OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 void checkBadSymbol(String s) { | 7 void checkBadSymbol(String s) { |
8 Expect.throws(() => new Symbol(s), (e) => e is ArgumentError); | 8 Expect.throws(() => new Symbol(s), (e) => e is ArgumentError); |
9 } | 9 } |
10 | 10 |
11 main() { | 11 main() { |
12 var x; | 12 var x; |
13 | 13 |
14 // 'void' is allowed as a symbol name. | 14 // 'void' is allowed as a symbol name. |
15 x = const Symbol('void'); /// 01: ok | 15 x = const Symbol('void'); //# 01: ok |
16 x = #void; /// 02: ok | 16 x = #void; //# 02: ok |
17 x = new Symbol('void'); /// 03: ok | 17 x = new Symbol('void'); //# 03: ok |
18 | 18 |
19 // However, it is not allowed as a part of a symbol name. | 19 // However, it is not allowed as a part of a symbol name. |
20 x = const Symbol('void.foo'); /// 04: compile-time error | 20 x = const Symbol('void.foo'); //# 04: compile-time error |
21 x = #void.foo; /// 05: static type warning | 21 x = #void.foo; //# 05: static type warning |
22 checkBadSymbol('void.foo'); /// 06: ok | 22 checkBadSymbol('void.foo'); //# 06: ok |
23 x = const Symbol('foo.void'); /// 07: compile-time error | 23 x = const Symbol('foo.void'); //# 07: compile-time error |
24 x = #foo.void; /// 08: compile-time error | 24 x = #foo.void; //# 08: compile-time error |
25 checkBadSymbol('foo.void'); /// 09: ok | 25 checkBadSymbol('foo.void'); //# 09: ok |
26 | 26 |
27 // All other reserved words are disallowed. | 27 // All other reserved words are disallowed. |
28 x = const Symbol('assert'); /// 10: compile-time error | 28 x = const Symbol('assert'); //# 10: compile-time error |
29 x = const Symbol('break'); /// 10: continued | 29 x = const Symbol('break'); //# 10: continued |
30 x = const Symbol('case'); /// 10: continued | 30 x = const Symbol('case'); //# 10: continued |
31 x = const Symbol('catch'); /// 10: continued | 31 x = const Symbol('catch'); //# 10: continued |
32 x = const Symbol('class'); /// 10: continued | 32 x = const Symbol('class'); //# 10: continued |
33 x = const Symbol('const'); /// 10: continued | 33 x = const Symbol('const'); //# 10: continued |
34 x = const Symbol('continue'); /// 10: continued | 34 x = const Symbol('continue'); //# 10: continued |
35 x = const Symbol('default'); /// 10: continued | 35 x = const Symbol('default'); //# 10: continued |
36 x = const Symbol('do'); /// 10: continued | 36 x = const Symbol('do'); //# 10: continued |
37 x = const Symbol('else'); /// 10: continued | 37 x = const Symbol('else'); //# 10: continued |
38 x = const Symbol('enum'); /// 10: continued | 38 x = const Symbol('enum'); //# 10: continued |
39 x = const Symbol('extends'); /// 10: continued | 39 x = const Symbol('extends'); //# 10: continued |
40 x = const Symbol('false'); /// 10: continued | 40 x = const Symbol('false'); //# 10: continued |
41 x = const Symbol('final'); /// 10: continued | 41 x = const Symbol('final'); //# 10: continued |
42 x = const Symbol('finally'); /// 10: continued | 42 x = const Symbol('finally'); //# 10: continued |
43 x = const Symbol('for'); /// 10: continued | 43 x = const Symbol('for'); //# 10: continued |
44 x = const Symbol('if'); /// 10: continued | 44 x = const Symbol('if'); //# 10: continued |
45 x = const Symbol('in'); /// 10: continued | 45 x = const Symbol('in'); //# 10: continued |
46 x = const Symbol('is'); /// 10: continued | 46 x = const Symbol('is'); //# 10: continued |
47 x = const Symbol('new'); /// 10: continued | 47 x = const Symbol('new'); //# 10: continued |
48 x = const Symbol('null'); /// 10: continued | 48 x = const Symbol('null'); //# 10: continued |
49 x = const Symbol('rethrow'); /// 10: continued | 49 x = const Symbol('rethrow'); //# 10: continued |
50 x = const Symbol('return'); /// 10: continued | 50 x = const Symbol('return'); //# 10: continued |
51 x = const Symbol('super'); /// 10: continued | 51 x = const Symbol('super'); //# 10: continued |
52 x = const Symbol('switch'); /// 10: continued | 52 x = const Symbol('switch'); //# 10: continued |
53 x = const Symbol('this'); /// 10: continued | 53 x = const Symbol('this'); //# 10: continued |
54 x = const Symbol('throw'); /// 10: continued | 54 x = const Symbol('throw'); //# 10: continued |
55 x = const Symbol('true'); /// 10: continued | 55 x = const Symbol('true'); //# 10: continued |
56 x = const Symbol('try'); /// 10: continued | 56 x = const Symbol('try'); //# 10: continued |
57 x = const Symbol('var'); /// 10: continued | 57 x = const Symbol('var'); //# 10: continued |
58 x = const Symbol('while'); /// 10: continued | 58 x = const Symbol('while'); //# 10: continued |
59 x = const Symbol('with'); /// 10: continued | 59 x = const Symbol('with'); //# 10: continued |
60 x = #assert; /// 11: compile-time error | 60 x = #assert; //# 11: compile-time error |
61 x = #break; /// 11: continued | 61 x = #break; //# 11: continued |
62 x = #case; /// 11: continued | 62 x = #case; //# 11: continued |
63 x = #catch; /// 11: continued | 63 x = #catch; //# 11: continued |
64 x = #class; /// 11: continued | 64 x = #class; //# 11: continued |
65 x = #const; /// 11: continued | 65 x = #const; //# 11: continued |
66 x = #continue; /// 11: continued | 66 x = #continue; //# 11: continued |
67 x = #default; /// 11: continued | 67 x = #default; //# 11: continued |
68 x = #do; /// 11: continued | 68 x = #do; //# 11: continued |
69 x = #else; /// 11: continued | 69 x = #else; //# 11: continued |
70 x = #enum; /// 11: continued | 70 x = #enum; //# 11: continued |
71 x = #extends; /// 11: continued | 71 x = #extends; //# 11: continued |
72 x = #false; /// 11: continued | 72 x = #false; //# 11: continued |
73 x = #final; /// 11: continued | 73 x = #final; //# 11: continued |
74 x = #finally; /// 11: continued | 74 x = #finally; //# 11: continued |
75 x = #for; /// 11: continued | 75 x = #for; //# 11: continued |
76 x = #if; /// 11: continued | 76 x = #if; //# 11: continued |
77 x = #in; /// 11: continued | 77 x = #in; //# 11: continued |
78 x = #is; /// 11: continued | 78 x = #is; //# 11: continued |
79 x = #new; /// 11: continued | 79 x = #new; //# 11: continued |
80 x = #null; /// 11: continued | 80 x = #null; //# 11: continued |
81 x = #rethrow; /// 11: continued | 81 x = #rethrow; //# 11: continued |
82 x = #return; /// 11: continued | 82 x = #return; //# 11: continued |
83 x = #super; /// 11: continued | 83 x = #super; //# 11: continued |
84 x = #switch; /// 11: continued | 84 x = #switch; //# 11: continued |
85 x = #this; /// 11: continued | 85 x = #this; //# 11: continued |
86 x = #throw; /// 11: continued | 86 x = #throw; //# 11: continued |
87 x = #true; /// 11: continued | 87 x = #true; //# 11: continued |
88 x = #try; /// 11: continued | 88 x = #try; //# 11: continued |
89 x = #var; /// 11: continued | 89 x = #var; //# 11: continued |
90 x = #while; /// 11: continued | 90 x = #while; //# 11: continued |
91 x = #with; /// 11: continued | 91 x = #with; //# 11: continued |
92 checkBadSymbol('assert'); /// 12: ok | 92 checkBadSymbol('assert'); //# 12: ok |
93 checkBadSymbol('break'); /// 12: continued | 93 checkBadSymbol('break'); //# 12: continued |
94 checkBadSymbol('case'); /// 12: continued | 94 checkBadSymbol('case'); //# 12: continued |
95 checkBadSymbol('catch'); /// 12: continued | 95 checkBadSymbol('catch'); //# 12: continued |
96 checkBadSymbol('class'); /// 12: continued | 96 checkBadSymbol('class'); //# 12: continued |
97 checkBadSymbol('const'); /// 12: continued | 97 checkBadSymbol('const'); //# 12: continued |
98 checkBadSymbol('continue'); /// 12: continued | 98 checkBadSymbol('continue'); //# 12: continued |
99 checkBadSymbol('default'); /// 12: continued | 99 checkBadSymbol('default'); //# 12: continued |
100 checkBadSymbol('do'); /// 12: continued | 100 checkBadSymbol('do'); //# 12: continued |
101 checkBadSymbol('else'); /// 12: continued | 101 checkBadSymbol('else'); //# 12: continued |
102 checkBadSymbol('enum'); /// 12: continued | 102 checkBadSymbol('enum'); //# 12: continued |
103 checkBadSymbol('extends'); /// 12: continued | 103 checkBadSymbol('extends'); //# 12: continued |
104 checkBadSymbol('false'); /// 12: continued | 104 checkBadSymbol('false'); //# 12: continued |
105 checkBadSymbol('final'); /// 12: continued | 105 checkBadSymbol('final'); //# 12: continued |
106 checkBadSymbol('finally'); /// 12: continued | 106 checkBadSymbol('finally'); //# 12: continued |
107 checkBadSymbol('for'); /// 12: continued | 107 checkBadSymbol('for'); //# 12: continued |
108 checkBadSymbol('if'); /// 12: continued | 108 checkBadSymbol('if'); //# 12: continued |
109 checkBadSymbol('in'); /// 12: continued | 109 checkBadSymbol('in'); //# 12: continued |
110 checkBadSymbol('is'); /// 12: continued | 110 checkBadSymbol('is'); //# 12: continued |
111 checkBadSymbol('new'); /// 12: continued | 111 checkBadSymbol('new'); //# 12: continued |
112 checkBadSymbol('null'); /// 12: continued | 112 checkBadSymbol('null'); //# 12: continued |
113 checkBadSymbol('rethrow'); /// 12: continued | 113 checkBadSymbol('rethrow'); //# 12: continued |
114 checkBadSymbol('return'); /// 12: continued | 114 checkBadSymbol('return'); //# 12: continued |
115 checkBadSymbol('super'); /// 12: continued | 115 checkBadSymbol('super'); //# 12: continued |
116 checkBadSymbol('switch'); /// 12: continued | 116 checkBadSymbol('switch'); //# 12: continued |
117 checkBadSymbol('this'); /// 12: continued | 117 checkBadSymbol('this'); //# 12: continued |
118 checkBadSymbol('throw'); /// 12: continued | 118 checkBadSymbol('throw'); //# 12: continued |
119 checkBadSymbol('true'); /// 12: continued | 119 checkBadSymbol('true'); //# 12: continued |
120 checkBadSymbol('try'); /// 12: continued | 120 checkBadSymbol('try'); //# 12: continued |
121 checkBadSymbol('var'); /// 12: continued | 121 checkBadSymbol('var'); //# 12: continued |
122 checkBadSymbol('while'); /// 12: continued | 122 checkBadSymbol('while'); //# 12: continued |
123 checkBadSymbol('with'); /// 12: continued | 123 checkBadSymbol('with'); //# 12: continued |
124 } | 124 } |
OLD | NEW |