OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-types |
| 6 |
| 7 |
| 8 load("test/mjsunit/harmony/typesystem/typegen.js"); |
| 9 debug = true; |
| 10 |
| 11 |
| 12 // In all the following functions, the size parameter (positive integer) |
| 13 // denotes how many test cases will be tried. The variable test_size |
| 14 // controls execution time of this test. It should not be too high. |
| 15 let test_size = 1000; |
| 16 |
| 17 |
| 18 function ValidVariableDeclarations(size, keyword="var") { |
| 19 return Generate(size, [ |
| 20 new TestGen(1, ValidTypes, [ |
| 21 keyword != "const" && (t => keyword + " x : " + t + ";"), |
| 22 t => keyword + " x : " + t + " = undefined;" |
| 23 ]), |
| 24 new TestGen(1, ValidTypes, [ |
| 25 t => keyword + " [x, y, ...rest] : (" + t + ")[] = [];" |
| 26 ]), |
| 27 new TestGen(1, ValidTupleTypes, [ |
| 28 t => keyword + " [x,, z] : " + t + " = [undefined,, undefined];" |
| 29 ]), |
| 30 new TestGen(1, ValidObjectTypes, [ |
| 31 t => keyword + " {a: x, b: y} : " + t + " = {a: 17, b: 42};" |
| 32 ]) |
| 33 ]); |
| 34 } |
| 35 |
| 36 function InvalidVariableDeclarations(size, keyword="var") { |
| 37 return Generate(size, [ |
| 38 new TestGen(1, InvalidTypes, [ |
| 39 keyword != "const" && (t => keyword + " x : " + t + ";"), |
| 40 t => keyword + " x : " + t + " = undefined;" |
| 41 ]), |
| 42 new TestGen(1, InvalidTypes, [ |
| 43 keyword != "const" && (t => keyword + " [x, y, ...rest] : (" + t + ")[];")
, |
| 44 t => keyword + " [x, y, ...rest] : (" + t + ")[] = [];" |
| 45 ]), |
| 46 new TestGen(1, InvalidTupleTypes, [ |
| 47 keyword != "const" && (t => keyword + " [x,, z] : " + t + ";"), |
| 48 t => keyword + " [x,, z] : " + t + " = [undefined,, undefined];" |
| 49 ]), |
| 50 new TestGen(1, InvalidObjectTypes, [ |
| 51 keyword != "const" && (t => keyword + " {a: x, b: y} : " + t + ";"), |
| 52 t => keyword + " {a: x, b: y} : " + t + " = {a: 17, b: 42};" |
| 53 ]), |
| 54 "var [x, y]: number[];", |
| 55 "var {a: x, b: y}: {a: number, b: string};", |
| 56 "let [x, y]: number[];", |
| 57 "let {a: x, b: y}: {a: number, b: string};", |
| 58 "const x: number;", |
| 59 "const [x, y]: [number, string];", |
| 60 "const {a: x, b: y}: {a: number, b: string};" |
| 61 ]); |
| 62 } |
| 63 |
| 64 (function TestVariableDeclarations(size) { |
| 65 Test(size, [ |
| 66 new TestGen(1, ValidVariableDeclarations, [CheckValid], "var"), |
| 67 new TestGen(1, ValidVariableDeclarations, [CheckValid], "let"), |
| 68 new TestGen(1, ValidVariableDeclarations, [CheckValid], "const"), |
| 69 new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "var"), |
| 70 new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "let"), |
| 71 new TestGen(1, InvalidVariableDeclarations, [CheckInvalid], "const") |
| 72 ]); |
| 73 })(test_size); |
OLD | NEW |