Files
test-repo/tests/spread/__snapshots__/jsfmt.spec.js.snap
T
Christopher Chedeau 74bc9e7a4d Add newline for empty blocks {} (#205)
I find it weird to put `{}` together. So I figured I would change it to have an empty line and ask for feedback :)

![image](https://cloud.githubusercontent.com/assets/197597/21739279/062adc80-d44c-11e6-8bb7-5e0768f3ddde.png)

Beware: most of the test cases are not representative of real code, you almost never define blocks with no content in practice.
2017-01-16 11:31:32 -05:00

242 lines
5.0 KiB
Plaintext

exports[`test test.js 1`] = `
"function parseTimestamp(timestamp: string): number {
return 0;
}
function parseCounter(line: string): number {
return 0;
}
function parseGroup(lines: Array<string>): {
counter: number;
begin: number;
end: number;
text: string;
} {
var counter = parseCounter(lines[0]);
var timeframe = parseTimeframe(lines[1]);
return {
counter,
...timeframe,
text: lines[2]
};
}
function parseTimeframe(line: string): { begin: number; end: number } {
var timestamps = line.split(\'-->\');
return {
begin: parseTimestamp(timestamps[0].trim()),
end: parseTimestamp(timestamps[1].trim())
};
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function parseTimestamp(timestamp: string): number {
return 0;
}
function parseCounter(line: string): number {
return 0;
}
function parseGroup(
lines: Array<string>
): { counter: number, begin: number, end: number, text: string } {
var counter = parseCounter(lines[0]);
var timeframe = parseTimeframe(lines[1]);
return { counter, ...timeframe, text: lines[2] };
}
function parseTimeframe(line: string): { begin: number, end: number } {
var timestamps = line.split(\"-->\");
return {
begin: parseTimestamp(timestamps[0].trim()),
end: parseTimestamp(timestamps[1].trim())
};
}
"
`;
exports[`test test2.js 1`] = `
"/**
* @flow
*/
function foo(o) {
bar({...o});
}
function bar(_: {foo:number}) { }
foo({foo: 42});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* @flow
*/
function foo(o) {
bar({ ...o });
}
function bar(_: { foo: number }) {
}
foo({ foo: 42 });
"
`;
exports[`test test3.js 1`] = `
"var p = { y: \"\" };
var q = { z: \"\" };
var o = {
x: 5,
...p,
...q,
};
var y: number = o.y;
var z: number = o.z;
// test conflicting keys (they get unioned)
var r = { y: 123 };
var s = {
...p,
...r,
};
var t: boolean = s.y; // error, string or number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var p = { y: \"\" };
var q = { z: \"\" };
var o = { x: 5, ...p, ...q };
var y: number = o.y;
var z: number = o.z;
// test conflicting keys (they get unioned)
var r = { y: 123 };
var s = { ...p, ...r };
var t: boolean = s.y; // error, string or number
"
`;
exports[`test test4.js 1`] = `
"/* @flow */
function test(...nums: Array<number>) {}
test(0, ...[1, 2, 3]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
function test(...nums: Array<number>) {
}
test(0, ...[ 1, 2, 3 ]);
"
`;
exports[`test test5.js 1`] = `
"/* @flow */
declare function map<Tv, TNext>(
obj: {[key: string]: Tv},
iterator:((obj: Tv) => TNext),
): Array<TNext>;
/**
* Tests overriding a property via a spread, where the value is a tvar. the
* type of the prop from the object that is being overridden (\`x.kind\` in the
* case below) should //not// feed back into the tvar (\`value\`), since the
* result is a new object.
*/
function test(
x: {kind: ?string},
kinds: {[key: string]: string}
): Array<{kind: ?string}> {
return map(kinds, (value) => {
(value: string); // OK
return {
...x,
kind: value,
};
});
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* @flow */
declare function map<Tv, TNext>(
obj: { [key: string]: Tv },
iterator: (obj: Tv) => TNext
): Array<TNext>;
/**
* Tests overriding a property via a spread, where the value is a tvar. the
* type of the prop from the object that is being overridden (\`x.kind\` in the
* case below) should //not// feed back into the tvar (\`value\`), since the
* result is a new object.
*/
function test(
x: { kind: ?string },
kinds: { [key: string]: string }
): Array<{ kind: ?string }> {
return map(kinds, value => {
(value: string);
// OK
return { ...x, kind: value };
});
}
"
`;
exports[`test test6.js 1`] = `
"var o = {
foo: \'bar\'
};
o = {...o};
(o: {foo: string});
var p = {
foo: \'bar\'
};
(p: {foo: string; abc: string}); // error, p doesn\'t have \`abc\` yet
p = {...p, abc: \'def\'};
(p: {foo: string; abc: string});
var q = {
foo: \'bar\'
};
for (var i = 0; i < 10; i++) {
q = {...q};
}
(q: {foo: string});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var o = { foo: \"bar\" };
o = { ...o };
(o: { foo: string });
var p = { foo: \"bar\" };
(p: { foo: string, abc: string });
// error, p doesn\'t have \`abc\` yet
p = { ...p, abc: \"def\" };
(p: { foo: string, abc: string });
var q = { foo: \"bar\" };
for (var i = 0; i < 10; i++) {
q = { ...q };
}
(q: { foo: string });
"
`;
exports[`test test7.js 1`] = `
"// @flow
let tests = [
function(x: Object) {
({...x}: Object);
({...x}: void); // error, Object
},
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @flow
let tests = [
function(x: Object) {
({ ...x }: Object);
({ ...x }: void); // error, Object
}
];
"
`;