I find it weird to put `{}` together. So I figured I would change it to have an empty line and ask for feedback :)

Beware: most of the test cases are not representative of real code, you almost never define blocks with no content in practice.
149 lines
2.6 KiB
Plaintext
149 lines
2.6 KiB
Plaintext
exports[`test boolean.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function veryOptimistic(isThisAwesome: true): boolean {
|
|
return isThisAwesome;
|
|
}
|
|
|
|
var x : boolean = veryOptimistic(true);
|
|
var y : boolean = veryOptimistic(false); // error
|
|
|
|
function veryPessimistic(isThisAwesome: true): boolean {
|
|
return !isThisAwesome; // test bool conversion
|
|
}
|
|
|
|
var x : boolean = veryPessimistic(true);
|
|
var y : boolean = veryPessimistic(false); // error
|
|
|
|
type MyOwnBooleanLOL = true | false
|
|
|
|
function bar(x: MyOwnBooleanLOL): false {
|
|
if (x) {
|
|
return x;
|
|
} else {
|
|
return !x;
|
|
}
|
|
}
|
|
|
|
bar(true);
|
|
bar(false);
|
|
bar(1); // error
|
|
|
|
function alwaysFalsy(x: boolean): false {
|
|
if (x) {
|
|
return !x;
|
|
} else {
|
|
return x;
|
|
}
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function veryOptimistic(isThisAwesome: true): boolean {
|
|
return isThisAwesome;
|
|
}
|
|
|
|
var x: boolean = veryOptimistic(true);
|
|
var y: boolean = veryOptimistic(false);
|
|
// error
|
|
function veryPessimistic(isThisAwesome: true): boolean {
|
|
return !isThisAwesome; // test bool conversion
|
|
}
|
|
|
|
var x: boolean = veryPessimistic(true);
|
|
var y: boolean = veryPessimistic(false);
|
|
// error
|
|
type MyOwnBooleanLOL = true | false;
|
|
|
|
function bar(x: MyOwnBooleanLOL): false {
|
|
if (x) {
|
|
return x;
|
|
} else {
|
|
return !x;
|
|
}
|
|
}
|
|
|
|
bar(true);
|
|
bar(false);
|
|
bar(1);
|
|
// error
|
|
function alwaysFalsy(x: boolean): false {
|
|
if (x) {
|
|
return !x;
|
|
} else {
|
|
return x;
|
|
}
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test number.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function highlander(howMany: 1): number {
|
|
return howMany; // there can be only one!
|
|
}
|
|
|
|
highlander(1);
|
|
highlander(2); // error
|
|
|
|
|
|
type Foo = 1 | 2
|
|
|
|
function bar(num: Foo): number {
|
|
return num + 1;
|
|
}
|
|
|
|
bar(1);
|
|
bar(2);
|
|
bar(3); // error
|
|
|
|
type ComparatorResult = -1 | 0 | 1
|
|
function sort(fn: (x: any, y: any) => ComparatorResult) {}
|
|
sort((x, y) => -1);
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function highlander(howMany: 1): number {
|
|
return howMany; // there can be only one!
|
|
}
|
|
|
|
highlander(1);
|
|
highlander(2);
|
|
// error
|
|
type Foo = 1 | 2;
|
|
|
|
function bar(num: Foo): number {
|
|
return num + 1;
|
|
}
|
|
|
|
bar(1);
|
|
bar(2);
|
|
bar(3);
|
|
// error
|
|
type ComparatorResult = -1 | 0 | 1;
|
|
function sort(fn: (x: any, y: any) => ComparatorResult) {
|
|
}
|
|
sort((x, y) => -1);
|
|
"
|
|
`;
|
|
|
|
exports[`test string.js 1`] = `
|
|
"/* @flow */
|
|
|
|
type NoSpaces = \"foobar\"
|
|
(\"foobar\": NoSpaces);
|
|
|
|
type HasSpaces = \"foo bar\"
|
|
(\"foo bar\": HasSpaces);
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
type NoSpaces = \"foobar\";
|
|
(\"foobar\": NoSpaces);
|
|
|
|
type HasSpaces = \"foo bar\";
|
|
(\"foo bar\": HasSpaces);
|
|
"
|
|
`;
|