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

Side by Side Diff: test/mjsunit/harmony/typesystem/typegen.js

Issue 1817093002: Add parsing for object types (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1810943002-tuple
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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 load("test/mjsunit/harmony/typesystem/testgen.js"); 6 load("test/mjsunit/harmony/typesystem/testgen.js");
7 7
8 8
9 // In the rest, for each NonTerminal symbol in the parser grammar that we 9 // In the rest, for each NonTerminal symbol in the parser grammar that we
10 // care to test, there are two generator functions (ValidNonTerminal and 10 // care to test, there are two generator functions (ValidNonTerminal and
(...skipping 13 matching lines...) Expand all
24 new TestGen(1, ValidTypes, [ 24 new TestGen(1, ValidTypes, [
25 t => "(" + t + ")" 25 t => "(" + t + ")"
26 ]), 26 ]),
27 new TestGen(1, ValidPrimaryTypes, [ 27 new TestGen(1, ValidPrimaryTypes, [
28 t => t + "[]", 28 t => t + "[]",
29 t => t + "[][]", 29 t => t + "[][]",
30 t => "(" + t + "[])", 30 t => "(" + t + "[])",
31 t => "(" + t + "[])[]", 31 t => "(" + t + "[])[]",
32 ]), 32 ]),
33 new TestGen(1, ValidTupleTypes, [t => t]), 33 new TestGen(1, ValidTupleTypes, [t => t]),
34 new TestGen(1, ValidObjectTypes, [t => t]),
34 proper && "number", 35 proper && "number",
35 proper && "boolean", 36 proper && "boolean",
36 proper && "string", 37 proper && "string",
37 proper && "symbol", 38 proper && "symbol",
38 // Type references 39 // Type references
39 "A", 40 "A",
40 "Tree<number>", 41 "Tree<number>",
41 "Map<string, number>", 42 "Map<string, number>",
42 // Type queries 43 // Type queries
43 "typeof x", 44 "typeof x",
(...skipping 10 matching lines...) Expand all
54 new TestGen(1, InvalidTypes, [ 55 new TestGen(1, InvalidTypes, [
55 t => "(" + t + ")" 56 t => "(" + t + ")"
56 ]), 57 ]),
57 new TestGen(1, InvalidPrimaryTypes, [ 58 new TestGen(1, InvalidPrimaryTypes, [
58 t => t + "[]", 59 t => t + "[]",
59 t => t + "[][]", 60 t => t + "[][]",
60 t => "(" + t + "[])", 61 t => "(" + t + "[])",
61 t => "(" + t + "[])[]", 62 t => "(" + t + "[])[]",
62 ]), 63 ]),
63 new TestGen(1, InvalidTupleTypes, [t => t]), 64 new TestGen(1, InvalidTupleTypes, [t => t]),
65 new TestGen(1, InvalidObjectTypes, [t => t]),
64 // Line terminator in arrays. 66 // Line terminator in arrays.
65 new TestGen(1, ValidTypes, [ 67 new TestGen(1, ValidTypes, [
66 t => "(" + t + "\n[])" 68 t => "(" + t + "\n[])"
67 ]), 69 ]),
68 // Type references 70 // Type references
69 "Map<string, (number, void)>", 71 "Map<string, (number, void)>",
70 "number<string>", 72 "number<string>",
71 "Foo<>", 73 "Foo<>",
72 // Type queries 74 // Type queries
73 "typeof", 75 "typeof",
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 new TestGen(1, ValidTypes, [ 149 new TestGen(1, ValidTypes, [
148 t => c + "() => " + t, 150 t => c + "() => " + t,
149 t => c + "(a: " + t + ") => " + t, 151 t => c + "(a: " + t + ") => " + t,
150 t => c + "(a:" + t + ", b?:" + t + ") => " + t, 152 t => c + "(a:" + t + ", b?:" + t + ") => " + t,
151 t => c + "(a:" + t + ", b?:" + t + ", c) => " + t, 153 t => c + "(a:" + t + ", b?:" + t + ", c) => " + t,
152 t => c + "(a:" + t + ", b?:" + t + ", c?) => " + t, 154 t => c + "(a:" + t + ", b?:" + t + ", c?) => " + t,
153 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t, 155 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
154 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t, 156 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
155 t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t 157 t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t
156 ]), 158 ]),
157 // Parametric function types 159 // Parametric function types.
158 "<A> (x: A) => A", 160 "<A> (x: A) => A",
159 "<A extends string> (x: A) => A", 161 "<A extends string> (x: A) => A",
160 "<A, B> (x: A, y: B) => A", 162 "<A, B> (x: A, y: B) => A",
161 "<A, B extends number[], C> (x: A, y: B) => C", 163 "<A, B extends number[], C> (x: A, y: B) => C",
162 "<A, B, C, D> (x: A, y: B, z: C[], d: (e: D) => D) => A", 164 "<A, B, C, D> (x: A, y: B, z: C[], d: (e: D) => D) => A",
163 // String literal types 165 // String literal types.
164 "(cmd: 'add', x: number, y: number) => number", 166 "(cmd: 'add', x: number, y: number) => number",
165 '(cmd: "sum", a: number[]) => number', 167 '(cmd: "sum", a: number[]) => number',
166 "(x: number, cmd: 'one', ...rest) => any", 168 "(x: number, cmd: 'one', ...rest) => any",
167 "(x: string, y: number, cmd: 'two', ...rest) => any", 169 "(x: string, y: number, cmd: 'two', ...rest) => any",
168 "(x: number, cmd?: 'two', ...rest) => string" 170 "(x: number, cmd?: 'two', ...rest) => string",
171 // With binding patterns.
172 "([]: number[]) => boolean",
173 "([x, y]: number[]) => boolean",
174 "([x, ...rest]: number[]) => boolean",
175 "([,x, y]: number[]) => boolean",
176 "([x, y,]: number[]) => boolean",
177 "([x, y,,]: number[]) => boolean",
178 "([x, [a, b, c], z]: [number, any[], string]) => boolean",
179 "({x: a, y: b}: {x: number, y: string}) => boolean",
180 "({x: a, y: [b, c, ...rest]}: {x: number, y: string[]}) => boolean",
181 "({x: {a, b}, y: c}: {x: {a, b}, y: string}) => boolean"
169 ]); 182 ]);
170 } 183 }
171 184
172 function InvalidFunctionTypes(size, constr) { 185 function InvalidFunctionTypes(size, constr) {
173 let c = constr ? "new " : ""; 186 let c = constr ? "new " : "";
174 return Generate(size, [ 187 return Generate(size, [
175 // Illegal types in legal places. 188 // Illegal types in legal places.
176 new TestGen(1, InvalidTypes, [ 189 new TestGen(1, InvalidTypes, [
177 t => c + "() => " + t, 190 t => c + "() => " + t,
178 t => c + "(a: " + t + ") => " + t, 191 t => c + "(a: " + t + ") => " + t,
179 t => c + "(a:" + t + ", b?:" + t + ") => " + t, 192 t => c + "(a:" + t + ", b?:" + t + ") => " + t,
180 t => c + "(a:" + t + ", b?:" + t + ", c) => " + t, 193 t => c + "(a:" + t + ", b?:" + t + ", c) => " + t,
181 t => c + "(a:" + t + ", b?:" + t + ", c?) => " + t, 194 t => c + "(a:" + t + ", b?:" + t + ", c?) => " + t,
182 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t, 195 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
183 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t, 196 t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
184 t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t, 197 t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t,
185 ]), 198 ]),
186 // Parametric function types 199 // Parametric function types.
187 "<A> A[]", 200 "<A> A[]",
188 "<> (x: number) => number", 201 "<> (x: number) => number",
189 "<A extends ()> (x: A) => A" 202 "<A extends ()> (x: A) => A",
203 // With illegal binding patterns.
204 "({x: {a; b}, y: c}: {x: {a; b}, y: string}) => boolean"
190 ]); 205 ]);
191 } 206 }
192 207
193 208
194 // Tuple types. 209 // Tuple types.
195 210
196 function ValidTupleTypes(size) { 211 function ValidTupleTypes(size) {
197 return Generate(size, [ 212 return Generate(size, [
198 new TestGen(1, ValidTypes, [ 213 new TestGen(1, ValidTypes, [
199 t => "[" + t + "]", 214 t => "[" + t + "]",
(...skipping 17 matching lines...) Expand all
217 new TestGen(1, ValidTypes, [t => "[" + t + ",,]"]), 232 new TestGen(1, ValidTypes, [t => "[" + t + ",,]"]),
218 new TestGen(1, ValidTypes, [t => "[," + t + "]"]), 233 new TestGen(1, ValidTypes, [t => "[," + t + "]"]),
219 new TestGen(1, ValidTypes, [t => "[,," + t + "]"]), 234 new TestGen(1, ValidTypes, [t => "[,," + t + "]"]),
220 new TestGen(1, ValidTypes, [t => "[" + t + ",," + t + "]"]), 235 new TestGen(1, ValidTypes, [t => "[" + t + ",," + t + "]"]),
221 new TestGen(1, ValidTypes, [t => "[..." + t + "]"]), 236 new TestGen(1, ValidTypes, [t => "[..." + t + "]"]),
222 new TestGen(1, ValidTypes, [t => "[" + t + ", ..." + t + "]"]), 237 new TestGen(1, ValidTypes, [t => "[" + t + ", ..." + t + "]"]),
223 ]); 238 ]);
224 } 239 }
225 240
226 241
242 // Object types.
243
244 function ValidObjectTypes(size) {
245 return Generate(size, [
246 // Empty object type.
247 "{}",
248 // Property signatures.
249 "{a}",
250 "{a, b}",
251 "{a, b?}",
252 "{a?, b}",
253 new TestGen(1, ValidTypes, [
254 t => "{a: " + t + "}",
255 t => "{a: " + t + ", b: " + t + "}",
256 t => "{a?: " + t + "}",
257 t => "{a: " + t + ", b?: " + t + "}",
258 ]),
259 // Method signatures.
260 "{f()}",
261 "{f?()}",
262 "{f(a)}",
263 "{f?(a)}",
264 "{f(a, b)}",
265 "{f?(a, b)}",
266 new TestGen(1, ValidTypes, [
267 t => "{f() : " + t + "}",
268 t => "{f?() : " + t + "}",
269 t => "{f(a: " + t + ")}",
270 t => "{f?(a: " + t + ")}",
271 t => "{f(a: " + t + ") : " + t + "}",
272 t => "{f?(a: " + t + ") : " + t + "}",
273 t => "{f<A extends " + t + ">(a: " + t + ")}",
rossberg 2016/04/07 15:09:02 How about cases without extends, or with more than
nickie 2016/04/08 09:50:57 Done.
274 t => "{f?<A extends " + t + ">(a: " + t + ")}",
275 t => "{f<A extends " + t + ">(a: " + t + ") : " + t + "}",
276 t => "{f?<A extends " + t + ">(a: " + t + ") : " + t + "}"
277 ]),
278 // Call signatures.
279 "{()}",
280 "{(a)}",
281 "{(a, b)}",
282 new TestGen(1, ValidTypes, [
283 t => "{() : " + t + "}",
284 t => "{(a: " + t + ")}",
285 t => "{(a: " + t + ") : " + t + "}",
286 t => "{<A extends " + t + ">(a: " + t + ")}",
287 t => "{<A extends " + t + ">(a: " + t + ") : " + t + "}"
288 ]),
289 // Constructor signatures.
290 "{new ()}",
291 "{new (a)}",
292 "{new (a, b)}",
293 new TestGen(1, ValidTypes, [
294 t => "{new () : " + t + "}",
295 t => "{new (a: " + t + ")}",
296 t => "{new (a: " + t + ") : " + t + "}",
297 t => "{new <A extends " + t + ">(a: " + t + ")}",
298 t => "{new <A extends " + t + ">(a: " + t + ") : " + t + "}"
299 ]),
300 // Index signatures.
301 "{[a: number]}",
302 "{[a: string]}",
303 new TestGen(1, ValidTypes, [
304 t => "{[a: number] : " + t + "}",
305 t => "{[a: string] : " + t + "}"
306 ])
307 ]);
308 }
309
310 function InvalidObjectTypes(size) {
311 return Generate(size, [
312 // Illegal types in legal places.
313 new TestGen(1, InvalidTypes, [
314 t => "{a: " + t + "}",
315 t => "{a: " + t + ", b?: " + t + "}",
316 t => "{f() : " + t + "}",
317 t => "{f(a: " + t + ")}",
318 t => "{f<A extends " + t + ">()}",
319 t => "{(a: " + t + ")}",
320 t => "{new () : " + t + "}"
321 ]),
322 // Valid binding patterns that are not tuple types.
323 "{a: []}",
324 "{a: [...rest]}",
325 // Invalid index signatures.
326 "{[a: any]}",
327 "{[a: any] : number}"
328 ]);
329 }
330
331
227 // All types: simple, type references, type parametric, type queries 332 // All types: simple, type references, type parametric, type queries
228 // and tuples. 333 // and tuples.
229 334
230 function ValidTypes(size) { 335 function ValidTypes(size) {
231 return Generate(size, [ 336 return Generate(size, [
232 new TestGen(1, ValidUnionTypes, [t => t]), 337 new TestGen(1, ValidUnionTypes, [t => t]),
233 new TestGen(1, ValidFunctionTypes, [t => t], false), 338 new TestGen(1, ValidFunctionTypes, [t => t], false),
234 ]); 339 ]);
235 } 340 }
236 341
237 function InvalidTypes(size) { 342 function InvalidTypes(size) {
238 return Generate(size, [ 343 return Generate(size, [
239 new TestGen(1, InvalidUnionTypes, [t => t]), 344 new TestGen(1, InvalidUnionTypes, [t => t]),
240 new TestGen(1, InvalidFunctionTypes, [t => t], false), 345 new TestGen(1, InvalidFunctionTypes, [t => t], false),
241 ]); 346 ]);
242 } 347 }
OLDNEW
« test/cctest/test-parsing.cc ('K') | « test/mjsunit/harmony/typesystem/object-types.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698