Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1817353003: Add tests for variable declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/typesystem/object-types.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7433 matching lines...) Expand 10 before | Expand all | Expand 10 after
7444 kAllowHarmonyExponentiationOperator}; 7444 kAllowHarmonyExponentiationOperator};
7445 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7445 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7446 arraysize(always_flags)); 7446 arraysize(always_flags));
7447 } 7447 }
7448 7448
7449 TEST(TypedVariableDeclarations) { 7449 TEST(TypedVariableDeclarations) {
7450 const char* untyped_context_data[][2] = {{"", ""}, {NULL, NULL}}; 7450 const char* untyped_context_data[][2] = {{"", ""}, {NULL, NULL}};
7451 const char* typed_context_data[][2] = {{"'use types'; ", ""}, {NULL, NULL}}; 7451 const char* typed_context_data[][2] = {{"'use types'; ", ""}, {NULL, NULL}};
7452 7452
7453 const char* untyped_data[] = { 7453 const char* untyped_data[] = {
7454 "var x = 42",
7455 NULL 7454 NULL
7456 }; 7455 };
7457 7456
7458 const char* typed_data[] = { 7457 const char* typed_data[] = {
7459 "var x: number = 42", 7458 "var x: number = 42",
7460 "var s: string = 'hello world'", 7459 "var s: string = 'hello world'",
7460 "var x : any",
7461 "let x : any",
7462 "var x : any = undefined",
7463 "let x : any = undefined",
7464 "const x : any = undefined",
7465 "var [x, y, ...rest] : any[] = []",
7466 "let [x, y, ...rest] : any[] = []",
7467 "const [x, y, ...rest] : any[] = []",
7468 "var [x,, z] : [any] = [undefined,, undefined]",
7469 "let [x,, z] : [any] = [undefined,, undefined]",
7470 "const [x,, z] : [any] = [undefined,, undefined]",
7471 "var {a: x, b: y} : {a: number, b: string} = {a: 17, b: 'hello'}",
7472 "let {a: x, b: y} : {a: number, b: string} = {a: 17, b: 'hello'}",
7473 "const {a: x, b: y} : {a: number, b: string} = {a: 17, b: 'hello'}",
7461 NULL 7474 NULL
7462 }; 7475 };
7463 7476
7477 const char* typed_error_data[] = {
7478 "var x : ()",
7479 "let x : ()",
7480 "var x : () = undefined",
7481 "let x : () = undefined",
7482 "const x : () = undefined",
7483 "var [x, y, ...rest] : ()[]",
7484 "let [x, y, ...rest] : ()[]",
7485 "const [x, y, ...rest] : ()[] = []",
7486 "var [x,, z] : [any, (), any]",
7487 "let [x,, z] : [any, (), any]",
7488 "const [x,, z] : [any, (), any] = [1, 2, 3]",
7489 "var {a: x, b: y} : {a: (), b: number}",
7490 "let {a: x, b: y} : {a: (), b: number}",
7491 "const {a: x, b: y} : {a: (), b: number} = {a: 17, b: 42}",
7492 "var [x, y]: number[];",
7493 "var {a: x, b: y}: {a: number, b: string};",
7494 "let [x, y]: number[];",
7495 "let {a: x, b: y}: {a: number, b: string};",
7496 "const x: number;",
7497 "const [x, y]: [number, string];",
7498 "const {a: x, b: y}: {a: number, b: string};",
7499 NULL
7500 };
7501
7464 static const ParserFlag always_flags[] = {kAllowTypes}; 7502 static const ParserFlag always_flags[] = {kAllowTypes};
7465 RunParserSyncTest(untyped_context_data, untyped_data, kSuccess, NULL, 0, 7503 RunParserSyncTest(untyped_context_data, untyped_data, kSuccess, NULL, 0,
7466 always_flags, arraysize(always_flags)); 7504 always_flags, arraysize(always_flags));
7467 RunParserSyncTest(typed_context_data, untyped_data, kSuccess, NULL, 0, 7505 RunParserSyncTest(typed_context_data, untyped_data, kSuccess, NULL, 0,
7468 always_flags, arraysize(always_flags)); 7506 always_flags, arraysize(always_flags));
7469 RunParserSyncTest(untyped_context_data, typed_data, kError, NULL, 0, 7507 RunParserSyncTest(untyped_context_data, typed_data, kError, NULL, 0,
7470 always_flags, arraysize(always_flags)); 7508 always_flags, arraysize(always_flags));
7471 RunParserSyncTest(typed_context_data, typed_data, kSuccess, NULL, 0, 7509 RunParserSyncTest(typed_context_data, typed_data, kSuccess, NULL, 0,
7472 always_flags, arraysize(always_flags)); 7510 always_flags, arraysize(always_flags));
7511 RunParserSyncTest(untyped_context_data, typed_error_data, kError, NULL, 0,
7512 always_flags, arraysize(always_flags));
7513 RunParserSyncTest(typed_context_data, typed_error_data, kError, NULL, 0,
7514 always_flags, arraysize(always_flags));
7473 } 7515 }
7474 7516
7475 TEST(TypedModeChecks) { 7517 TEST(TypedModeChecks) {
7476 const char* strict_context_data[][2] = { 7518 const char* strict_context_data[][2] = {
7477 {"'use types'; ", ""}, 7519 {"'use types'; ", ""},
7478 {"'use strict'; 'use types'; ", ""}, 7520 {"'use strict'; 'use types'; ", ""},
7479 {"'use types'; 'use strict'; ", ""}, 7521 {"'use types'; 'use strict'; ", ""},
7480 {"'use strict'; 'use types'; 'use strict'; ", ""}, 7522 {"'use strict'; 'use types'; 'use strict'; ", ""},
7481 {"'use types'; 'use strict'; 'use types'; ", ""}, 7523 {"'use types'; 'use strict'; 'use types'; ", ""},
7482 {NULL, NULL} 7524 {NULL, NULL}
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
7769 static const ParserFlag always_flags[] = {kAllowTypes}; 7811 static const ParserFlag always_flags[] = {kAllowTypes};
7770 RunParserSyncTest(untyped_context_data, correct_data, kError, NULL, 0, 7812 RunParserSyncTest(untyped_context_data, correct_data, kError, NULL, 0,
7771 always_flags, arraysize(always_flags)); 7813 always_flags, arraysize(always_flags));
7772 RunParserSyncTest(typed_context_data, correct_data, kSuccess, NULL, 0, 7814 RunParserSyncTest(typed_context_data, correct_data, kSuccess, NULL, 0,
7773 always_flags, arraysize(always_flags)); 7815 always_flags, arraysize(always_flags));
7774 RunParserSyncTest(untyped_context_data, error_data, kError, NULL, 0, 7816 RunParserSyncTest(untyped_context_data, error_data, kError, NULL, 0,
7775 always_flags, arraysize(always_flags)); 7817 always_flags, arraysize(always_flags));
7776 RunParserSyncTest(typed_context_data, error_data, kError, NULL, 0, 7818 RunParserSyncTest(typed_context_data, error_data, kError, NULL, 0,
7777 always_flags, arraysize(always_flags)); 7819 always_flags, arraysize(always_flags));
7778 } 7820 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/typesystem/object-types.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698