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

Side by Side Diff: test/mjsunit/harmony/typesystem/function-declarations.js

Issue 1841093002: Add optional types to function/method declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1817353007-typ-mod
Patch Set: Created 4 years, 8 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
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
10
11 // In all the following functions, the size parameter (positive integer)
12 // denotes how many test cases will be tried. The variable test_size
13 // controls execution time of this test. It should not be too high.
14 let test_size = 1000;
15
16
17 function ValidFormalParameters(size) {
18 return Generate(size, [
19 "()",
20 "(x)",
21 "(x, y)",
22 "(x?)",
23 "(x?, y)",
24 "(x, y?)",
25 new TestGen(1, ValidTypes, [
26 t => "(x : " + t + ")",
27 t => "(x : " + t + " = undefined)",
28 t => "(x? : " + t + ")",
29 t => "(x : " + t + ", y : " + t + ")",
30 t => "(x : " + t + " = undefined, y : " + t + ")",
31 t => "(x? : " + t + ", y)",
32 t => "(x? : " + t + ", y : " + t + ")"
33 ]),
34 "(x, ...rest)",
35 "(x, y, ...rest)",
36 "(x?, ...rest)",
37 "(x?, y, ...rest)",
38 "(x, y?, ...rest)",
39 new TestGen(1, ValidTypes, [
40 t => "(x : " + t + ", ...rest : (" + t + ")[])",
41 t => "(x? : " + t + ", y : " + t + ", ...rest : (" + t + ")[])"
42 ]),
43 ]);
44 }
45
46 function InvalidFormalParameters(size) {
47 return Generate(size, [
48 new TestGen(1, InvalidTypes, [
49 t => "(x : " + t + ")",
50 t => "(x : " + t + "= undefined)",
51 t => "(x? : " + t + ")",
52 t => "(x : " + t + ", y : " + t + ")",
53 t => "(x = undefined, y : " + t + ")",
54 t => "(x? : " + t + ", y)",
55 t => "(x?, y : " + t + ")"
56 ]),
57 "(x? = 42)",
58 "(x? : number = 42)",
59 "(...rest?)",
60 "(...rest? : number)"
61 ]);
62 }
63
64 function ValidParameters(size) {
65 return Generate(size, [
66 new TestGen(1, ValidFormalParameters, [
67 p => p,
68 p => "<A>" + p,
69 p => "<A, B>" + p,
70 p => "<A extends {x:number}>" + p,
71 p => "<A extends {x:number}, B>" + p,
72 p => "<A, B extends {x:number}>" + p
73 ])
74 ]);
75 }
76
77 function InvalidParameters(size) {
78 return Generate(size, [
79 new TestGen(1, InvalidFormalParameters, [
80 p => p,
81 p => "<A>" + p,
82 p => "<A, B>" + p,
83 p => "<A extends {x:number}>" + p,
84 p => "<A extends {x:number}, B>" + p,
85 p => "<A, B extends {x:number}>" + p
86 ]),
87 "<>(x : number)",
88 "<A,>(s : string)",
89 "<A extends ()>()"
90 ]);
91 }
92
93 function ValidFunctionDeclarations(size) {
94 return Generate(size, [
95 new TestGen(1, ValidParameters, [
96 p => "function f " + p + " {}",
97 p => "function* f " + p + " {}",
98 p => "(function " + p + " {})()",
99 p => "(function* " + p + " {})()",
100 p => "function f " + p + " : number {}",
101 p => "function* f " + p + " : string[] {}",
102 p => "(function " + p + " : [any, number] {})()",
103 p => "(function* " + p + " : {a:number, b:string|boolean} {})()"
104 ]),
105 "function f ([x, y] : [any, any]) {}",
106 "function f ([x, y] : [any, any]) : number {}",
107 "(function ([x, y] : [any, any]) {})([1,2])",
108 "(function ([x, y] : [any, any]) : number {})([1,2])",
109 "function f ([first, ...rest] : string[]) {}",
110 "function f ([first, ...rest] : string[]) : number {}",
111 "(function ([first, ...rest] : string[]) {})(['hello', 'world'])",
112 "(function ([first, ...rest] : string[]) : number {})(['hello', 'world'])",
113 "function f ([one,,three] : number[], ...rest : string[]) {}",
114 "function f ([one,,three] : number[], ...rest : string[]) : number {}",
115 "(function ([one,,three] : number[], ...rest : string[]) {})([1,2,3])",
116 "(function ([one,,three] : number[], ...rest : string[]) : number {})([1,2,3 ])",
117 "function f ({a:x, b:y}? : {a:number, b:string}) {}",
118 "function f ({a:x, b:y}? : {a:number, b:string}) : number {}",
119 "(function ({a:x, b:y}? : {a:number, b:string}) {})({})",
120 "(function ({a:x, b:y}? : {a:number, b:string}) : number {})({})"
121 ]);
122 }
123
124 function InvalidFunctionDeclarations(size) {
125 return Generate(size, [
126 new TestGen(1, InvalidParameters, [
127 p => "function f " + p + " {}",
128 p => "function* f " + p + " {}",
129 p => "(function " + p + " {})()",
130 p => "(function* " + p + " {})()",
131 p => "function f " + p + " : number {}",
132 p => "function* f " + p + " : string[] {}",
133 p => "(function " + p + " : [any, number] {})()",
134 p => "(function* " + p + " : {a:number, b:string|boolean} {})()"
135 ]),
136 new TestGen(1, InvalidTypes, [
137 t => "function f() : " + t + " {}",
138 t => "function* f() : " + t + " {}",
139 t => "(function () : " + t + " {})()",
140 t => "(function* () : " + t + " {})()"
141 ])
142 ]);
143 }
144
145 (function TestFunctionDeclarations(size) {
146 Test(size, [
147 new TestGen(1, ValidFunctionDeclarations, [CheckValid]),
148 new TestGen(1, InvalidFunctionDeclarations, [CheckInvalid]),
149 ]);
150 })(test_size);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698