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); |