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 TestStringLiteralTypes() { | 11 (function TestStringLiteralTypes() { |
18 // These are not really valid here. | 12 // These are not really valid here. |
19 // They should only be valid in function/constructor signatures. | 13 // They should only be valid in function/constructor signatures. |
20 CheckValid("(cmd: 'add', x: number, y: number) => number"); | 14 CheckValidType("(cmd: 'add', x: number, y: number) => number"); |
21 CheckValid('(cmd: "sum", a: number[]) => number'); | 15 CheckValidType('(cmd: "sum", a: number[]) => number'); |
22 CheckValid("(x: number, cmd: 'one', ...rest) => any"); | 16 CheckValidType("(x: number, cmd: 'one', ...rest) => any"); |
23 CheckValid("(x: string, y: number, cmd: 'two', ...rest) => any"); | 17 CheckValidType("(x: string, y: number, cmd: 'two', ...rest) => any"); |
24 CheckValid("(x: number, cmd?: 'two', ...rest) => string"); | 18 CheckValidType("(x: number, cmd?: 'two', ...rest) => string"); |
25 // String literal types where they shouldn't be. | 19 // String literal types where they shouldn't be. |
26 CheckInvalid("'foo'"); | 20 CheckInvalidType("'foo'"); |
27 CheckInvalid("('foo')"); | 21 CheckInvalidType("('foo')"); |
28 CheckInvalid("'foo'[]"); | 22 CheckInvalidType("'foo'[]"); |
29 CheckInvalid("('foo')[]"); | 23 CheckInvalidType("('foo')[]"); |
30 CheckInvalid("('foo'[])"); | 24 CheckInvalidType("('foo'[])"); |
31 CheckInvalid("(('foo')[])"); | 25 CheckInvalidType("(('foo')[])"); |
32 CheckInvalid("'foo' | 'bar'"); | 26 CheckInvalidType("'foo' | 'bar'"); |
33 CheckInvalid("('foo') => any"); | 27 CheckInvalidType("('foo') => any"); |
34 })(); | 28 })(); |
OLD | NEW |