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

Unified Diff: test/mjsunit/harmony/typesystem/variable-declarations.js

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/harmony/typesystem/type-query.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/typesystem/variable-declarations.js
diff --git a/test/mjsunit/harmony/typesystem/variable-declarations.js b/test/mjsunit/harmony/typesystem/variable-declarations.js
new file mode 100644
index 0000000000000000000000000000000000000000..50214804ed32ee2abde2f8bbcae17a78721ba609
--- /dev/null
+++ b/test/mjsunit/harmony/typesystem/variable-declarations.js
@@ -0,0 +1,73 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-types
+
+
+load("test/mjsunit/harmony/typesystem/typegen.js");
+debug = true;
+
+
+// In all the following functions, the size parameter (positive integer)
+// denotes how many test cases will be tried. The variable test_size
+// controls execution time of this test. It should not be too high.
+let test_size = 1000;
+
+
+function ValidVariableDeclarations(size, keyword="var") {
+ return Generate(size, [
+ new TestGen(1, ValidTypes, [
+ keyword != "const" && (t => keyword + " x : " + t + ";"),
+ t => keyword + " x : " + t + " = undefined;"
+ ]),
+ new TestGen(1, ValidTypes, [
+ t => keyword + " [x, y, ...rest] : (" + t + ")[] = [];"
+ ]),
+ new TestGen(1, ValidTupleTypes, [
+ t => keyword + " [x,, z] : " + t + " = [undefined,, undefined];"
+ ]),
+ new TestGen(1, ValidObjectTypes, [
+ t => keyword + " {a: x, b: y} : " + t + " = {a: 17, b: 42};"
+ ])
+ ]);
+}
+
+function InvalidVariableDeclarations(size, keyword="var") {
+ return Generate(size, [
+ new TestGen(1, InvalidTypes, [
+ keyword != "const" && (t => keyword + " x : " + t + ";"),
+ t => keyword + " x : " + t + " = undefined;"
+ ]),
+ new TestGen(1, InvalidTypes, [
+ keyword != "const" && (t => keyword + " [x, y, ...rest] : (" + t + ")[];"),
+ t => keyword + " [x, y, ...rest] : (" + t + ")[] = [];"
+ ]),
+ new TestGen(1, InvalidTupleTypes, [
+ keyword != "const" && (t => keyword + " [x,, z] : " + t + ";"),
+ t => keyword + " [x,, z] : " + t + " = [undefined,, undefined];"
+ ]),
+ new TestGen(1, InvalidObjectTypes, [
+ keyword != "const" && (t => keyword + " {a: x, b: y} : " + t + ";"),
+ t => keyword + " {a: x, b: y} : " + t + " = {a: 17, b: 42};"
+ ]),
+ "var [x, y]: number[];",
+ "var {a: x, b: y}: {a: number, b: string};",
+ "let [x, y]: number[];",
+ "let {a: x, b: y}: {a: number, b: string};",
+ "const x: number;",
+ "const [x, y]: [number, string];",
+ "const {a: x, b: y}: {a: number, b: string};"
+ ]);
+}
+
+(function TestVariableDeclarations(size) {
+ Test(size, [
+ new TestGen(1, ValidVariableDeclarations, [CheckValid], "var"),
+ new TestGen(1, ValidVariableDeclarations, [CheckValid], "let"),
+ new TestGen(1, ValidVariableDeclarations, [CheckValid], "const"),
+ new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "var"),
+ new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "let"),
+ new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "const")
+ ]);
+})(test_size);
« no previous file with comments | « test/mjsunit/harmony/typesystem/type-query.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698