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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/typesystem/type-query.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
OLDNEW
« 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