2016-12-23 22:31:38 +03:00
|
|
|
exports[`test enum.js 1`] = `
|
|
|
|
"var APIKeys = {
|
2016-12-30 19:56:42 +03:00
|
|
|
AGE: \'age\',
|
|
|
|
NAME: \'name\',
|
2016-12-23 22:31:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = APIKeys;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-30 19:56:42 +03:00
|
|
|
var APIKeys = { AGE: \"age\", NAME: \"name\" };
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
module.exports = APIKeys;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test enum_client.js 1`] = `
|
2016-12-30 19:56:42 +03:00
|
|
|
"var APIKeys = require(\'./enum\');
|
|
|
|
// object that maps \"AGE\" to \"age\", \"NAME\" to \"name\"
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
function foo(x: $Keys<typeof APIKeys>) { }
|
2016-12-30 19:56:42 +03:00
|
|
|
foo(\"AGE\");
|
|
|
|
foo(\"LOCATION\"); // error
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
function bar(x: $Keys<{age: number}>) { }
|
2016-12-30 19:56:42 +03:00
|
|
|
bar(APIKeys.AGE); // not an error: APIKeys.AGE = \"age\"
|
|
|
|
bar(APIKeys.NAME); // error: since \"NAME\" is not in the smaller enum
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
var object = {};
|
|
|
|
object[APIKeys.AGE] = 123; // i.e., object.age = 123
|
2016-12-30 19:56:42 +03:00
|
|
|
object[APIKeys.NAME] = \"FOO\"; // i.e., object.name = \"FOO\"
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
var age:number = object[APIKeys.AGE];
|
|
|
|
var name:number = object[APIKeys.NAME]; // error: object.name is a string
|
|
|
|
|
|
|
|
var indices = { red: 0, green: 1, blue: 2 };
|
2016-12-30 19:56:42 +03:00
|
|
|
var tuple = [42, \"hello\", false];
|
2016-12-23 22:31:38 +03:00
|
|
|
var red:string = tuple[indices.red]; // error: tuple[0] is a number
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-30 19:56:42 +03:00
|
|
|
var APIKeys = require(\"./enum\");
|
2017-01-10 05:49:06 +03:00
|
|
|
// object that maps \"AGE\" to \"age\", \"NAME\" to \"name\"
|
2016-12-31 07:01:07 +03:00
|
|
|
function foo(x: $Keys<typeof APIKeys>) {}
|
2016-12-30 19:56:42 +03:00
|
|
|
foo(\"AGE\");
|
|
|
|
foo(\"LOCATION\");
|
2017-01-10 05:49:06 +03:00
|
|
|
// error
|
2016-12-31 07:01:07 +03:00
|
|
|
function bar(x: $Keys<{ age: number }>) {}
|
2016-12-27 21:29:31 +03:00
|
|
|
bar(APIKeys.AGE);
|
2017-01-10 05:49:06 +03:00
|
|
|
// not an error: APIKeys.AGE = \"age\"
|
2016-12-27 21:29:31 +03:00
|
|
|
bar(APIKeys.NAME);
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: since \"NAME\" is not in the smaller enum
|
2016-12-27 21:29:31 +03:00
|
|
|
var object = {};
|
2016-12-28 05:40:04 +03:00
|
|
|
object[APIKeys.AGE] = 123;
|
2017-01-10 05:49:06 +03:00
|
|
|
// i.e., object.age = 123
|
2016-12-30 19:56:42 +03:00
|
|
|
object[APIKeys.NAME] = \"FOO\";
|
2017-01-10 05:49:06 +03:00
|
|
|
// i.e., object.name = \"FOO\"
|
2016-12-27 21:29:31 +03:00
|
|
|
var age: number = object[APIKeys.AGE];
|
|
|
|
var name: number = object[APIKeys.NAME];
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: object.name is a string
|
2016-12-28 05:40:04 +03:00
|
|
|
var indices = { red: 0, green: 1, blue: 2 };
|
2016-12-30 19:56:42 +03:00
|
|
|
var tuple = [ 42, \"hello\", false ];
|
2017-01-11 18:16:38 +03:00
|
|
|
var red: string = tuple[indices.red]; // error: tuple[0] is a number
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test number.js 1`] = `
|
|
|
|
"function test1(x: number): number {
|
|
|
|
return -x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test2(x: string): number {
|
|
|
|
return -x;
|
|
|
|
}
|
|
|
|
|
2016-12-30 19:56:42 +03:00
|
|
|
// sanity checks to make sure merging envs doesn\'t keep creating new NumT\'s
|
|
|
|
// because of the UnaryMinusT\'s, causing nontermination
|
2016-12-23 22:31:38 +03:00
|
|
|
function test3(x: number, flip_times: number): number {
|
|
|
|
for (var i = 0; i < flip_times; i++) {
|
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
function test4(flip_times: number): number {
|
|
|
|
var x = 1;
|
|
|
|
for (var i = 0; i < flip_times; i++) {
|
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
function test1(x: number): number {
|
|
|
|
return -x;
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
function test2(x: string): number {
|
|
|
|
return -x;
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// sanity checks to make sure merging envs doesn\'t keep creating new NumT\'s
|
|
|
|
// because of the UnaryMinusT\'s, causing nontermination
|
2016-12-23 22:31:38 +03:00
|
|
|
function test3(x: number, flip_times: number): number {
|
2016-12-28 05:40:04 +03:00
|
|
|
for (var i = 0; i < flip_times; i++) {
|
2016-12-23 22:31:38 +03:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
function test4(flip_times: number): number {
|
2016-12-28 05:40:04 +03:00
|
|
|
var x = 1;
|
|
|
|
for (var i = 0; i < flip_times; i++) {
|
2016-12-23 22:31:38 +03:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
return x;
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|