Files
test-repo/tests/refinements/property.js
T
Christopher Chedeau cf45afba61 Add testing
- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases
- This creates snapshot tests using the pretty printer for all of them
- If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.
2016-12-23 19:51:53 +00:00

83 lines
1.4 KiB
JavaScript

/* @flow */
function a(x: {[key: string]: ?string}, y: string): string {
if (x[y]) {
return x[y];
}
return "";
}
function b(x: {y: {[key: string]: ?string}}, z: string): string {
if (x.y[z]) {
return x.y[z];
}
return "";
}
function c(x: {[key: string]: ?string}, y: {z: string}): string {
if (x[y.z]) {
return x[y.z];
}
return "";
}
function d(x: {y: {[key: string]: ?string}}, a: {b: string}): string {
if (x.y[a.b]) {
return x.y[a.b];
}
return "";
}
function a_array(x: Array<?string>, y: number): string {
if (x[y]) {
return x[y];
}
return "";
}
function b_array(x: {y: Array<?string>}, z: number): string {
if (x.y[z]) {
return x.y[z];
}
return "";
}
function c_array(x: Array<?string>, y: {z: number}): string {
if (x[y.z]) {
return x[y.z];
}
return "";
}
function d_array(x: {y: Array<?string>}, a: {b: number}): string {
if (x.y[a.b]) {
return x.y[a.b];
}
return "";
}
function e_array(x: Array<?string>): string {
if (x[0]) {
return x[0];
}
return "";
}
// --- name-sensitive havoc ---
function c2(x: {[key: string]: ?string}, y: {z: string}): string {
if (x[y.z]) {
y.z = "HEY";
return x[y.z]; // error
}
return "";
}
function c3(x: {[key: string]: ?string}, y: {z: string, a: string}): string {
if (x[y.z]) {
y.a = "HEY";
return x[y.z]; // ok
}
return "";
}