OLD | NEW |
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 // Flags: --harmony-types | 5 // Flags: --harmony-types |
6 | 6 |
7 function CheckValid(type) { | |
8 // print("V:", type); | |
9 assertDoesNotThrow("'use types'; var x: " + type + ";"); | |
10 } | |
11 | 7 |
12 function CheckInvalid(type) { | 8 load("test/mjsunit/harmony/typesystem/testgen.js"); |
13 // print("I:", type); | 9 |
14 assertThrows("'use types'; var x: " + type + ";", SyntaxError); | |
15 } | |
16 | 10 |
17 function valid(type) { | 11 function valid(type) { |
18 CheckValid(type); | 12 CheckValidType(type); |
19 CheckValid(type + "[]"); | 13 CheckValidType(type + "[]"); |
20 CheckValid(type + " & any"); | 14 CheckValidType(type + " & any"); |
21 CheckValid(type + " | any"); | 15 CheckValidType(type + " | any"); |
22 CheckValid("(" + type + ")[]"); | 16 CheckValidType("(" + type + ")[]"); |
23 CheckValid("(a: " + type + ") => any"); | 17 CheckValidType("(a: " + type + ") => any"); |
24 } | 18 } |
25 | 19 |
26 function invalid(type) { | 20 function invalid(type) { |
27 CheckInvalid(type); | 21 CheckInvalidType(type); |
28 CheckInvalid(type + "[]"); | 22 CheckInvalidType(type + "[]"); |
29 CheckInvalid(type + " & any"); | 23 CheckInvalidType(type + " & any"); |
30 CheckInvalid(type + " | any"); | 24 CheckInvalidType(type + " | any"); |
31 CheckInvalid("(" + type + ")[]"); | 25 CheckInvalidType("(" + type + ")[]"); |
32 CheckInvalid("(a: " + type + ") => any"); | 26 CheckInvalidType("(a: " + type + ") => any"); |
33 } | 27 } |
34 | 28 |
35 (function TestTypeQueries() { | 29 (function TestTypeQueries() { |
36 valid("typeof x"); | 30 valid("typeof x"); |
37 valid("typeof x.a"); | 31 valid("typeof x.a"); |
38 valid("typeof x.something.something_else"); | 32 valid("typeof x.something.something_else"); |
39 valid("typeof x.a.b.c.d.e.f.g.h.i.j.k.l"); | 33 valid("typeof x.a.b.c.d.e.f.g.h.i.j.k.l"); |
40 | 34 |
41 invalid("typeof"); | 35 invalid("typeof"); |
42 invalid("typeof x."); | 36 invalid("typeof x."); |
43 invalid("typeof x.a.b.c.d.e.f.g.h.i.j.k.l."); | 37 invalid("typeof x.a.b.c.d.e.f.g.h.i.j.k.l."); |
44 invalid("typeof x => any"); | 38 invalid("typeof x => any"); |
45 })(); | 39 })(); |
OLD | NEW |