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 // SharedOptions=--enable-enum | 5 // SharedOptions=--enable-enum |
6 | 6 |
7 // Basic syntax test for enumeration types | 7 // Basic syntax test for enumeration types |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 | 10 |
11 | 11 |
12 enum Color { red, orange, yellow, green } | 12 enum Color { red, orange, yellow, green } |
13 | 13 |
14 // Additional comma at end of list is ok. | 14 // Additional comma at end of list is ok. |
15 enum Veggies { carrot, bean, broccolo, } | 15 enum Veggies { carrot, bean, broccolo, } |
16 | 16 |
17 // Need at least one enumeration identifier. | 17 // Need at least one enumeration identifier. |
18 enum Nada {} /// 01: compile-time error | 18 enum Nada {} //# 01: compile-time error |
19 | 19 |
20 // Duplicate entries are a compile-time error | 20 // Duplicate entries are a compile-time error |
21 enum ComeAgain { ahau, knust, zipfel, knust, gupf } /// 02: compile-time error | 21 enum ComeAgain { ahau, knust, zipfel, knust, gupf } //# 02: compile-time error |
22 | 22 |
23 // Enum entries must not collide with implicitly defined members. | 23 // Enum entries must not collide with implicitly defined members. |
24 enum ComeAgain { ahau, knust, zipfel, index } /// 03: compile-time error | 24 enum ComeAgain { ahau, knust, zipfel, index } //# 03: compile-time error |
25 | 25 |
26 enum ComeAgain { ahau, knust, zipfel, values } /// 04: compile-time error | 26 enum ComeAgain { ahau, knust, zipfel, values } //# 04: compile-time error |
27 | 27 |
28 enum ComeAgain { ahau, knust, zipfel, toString } /// 05: compile-time error | 28 enum ComeAgain { ahau, knust, zipfel, toString } //# 05: compile-time error |
29 | 29 |
30 // Enum entry must not collide with enum type name. | 30 // Enum entry must not collide with enum type name. |
31 enum ComeAgain { ahau, knust, zipfel, ComeAgain } /// 06: compile-time error | 31 enum ComeAgain { ahau, knust, zipfel, ComeAgain } //# 06: compile-time error |
32 | 32 |
33 // Missing comma. | 33 // Missing comma. |
34 enum Numbers { one, two, three four, five } /// 07: compile-time error | 34 enum Numbers { one, two, three four, five } //# 07: compile-time error |
35 | 35 |
36 // Missing enum type name. | 36 // Missing enum type name. |
37 enum { eins, zwei, drei } /// 08: compile-time error | 37 enum { eins, zwei, drei } //# 08: compile-time error |
38 | 38 |
39 // Duplicate name in library scope. | 39 // Duplicate name in library scope. |
40 topLevelFunction() => null; | 40 topLevelFunction() => null; |
41 enum topLevelFunction { bla, blah } /// 09: compile-time error | 41 enum topLevelFunction { bla, blah } //# 09: compile-time error |
42 | 42 |
43 class C {} | 43 class C {} |
44 enum C { bla, blah } /// 10: compile-time error | 44 enum C { bla, blah } //# 10: compile-time error |
45 | 45 |
46 var zzTop; | 46 var zzTop; |
47 enum zzTop { Billy, Dusty, Frank } /// 11: compile-time error | 47 enum zzTop { Billy, Dusty, Frank } //# 11: compile-time error |
48 | 48 |
49 // Enum type cannot be super type or interface type. | 49 // Enum type cannot be super type or interface type. |
50 class Rainbow extends Color {} /// 20: compile-time error | 50 class Rainbow extends Color {} //# 20: compile-time error |
51 class Rainbow implements Color {} /// 21: compile-time error | 51 class Rainbow implements Color {} //# 21: compile-time error |
52 class Rainbow extends List with Color {} /// 22: compile-time error | 52 class Rainbow extends List with Color {} //# 22: compile-time error |
53 | 53 |
54 main() { | 54 main() { |
55 Nada x; /// 01: continued | 55 Nada x; //# 01: continued |
56 var x = ComeAgain.zipfel; /// 02: continued | 56 var x = ComeAgain.zipfel; //# 02: continued |
57 var x = ComeAgain.zipfel; /// 03: continued | 57 var x = ComeAgain.zipfel; //# 03: continued |
58 var x = ComeAgain.zipfel; /// 04: continued | 58 var x = ComeAgain.zipfel; //# 04: continued |
59 var x = ComeAgain.zipfel; /// 05: continued | 59 var x = ComeAgain.zipfel; //# 05: continued |
60 var x = ComeAgain.zipfel; /// 06: continued | 60 var x = ComeAgain.zipfel; //# 06: continued |
61 var x = Numbers.four; /// 07: continued | 61 var x = Numbers.four; //# 07: continued |
62 var x = topLevelFunction.bla; /// 09: continued | 62 var x = topLevelFunction.bla; //# 09: continued |
63 var x = C.bla; /// 10: continued | 63 var x = C.bla; //# 10: continued |
64 var x = zzTop.Frank; /// 11: continued | 64 var x = zzTop.Frank; //# 11: continued |
65 | 65 |
66 var x = new Rainbow(); /// 20: continued | 66 var x = new Rainbow(); //# 20: continued |
67 var x = new Rainbow(); /// 21: continued | 67 var x = new Rainbow(); //# 21: continued |
68 var x = new Rainbow(); /// 22: continued | 68 var x = new Rainbow(); //# 22: continued |
69 | 69 |
70 // It is a compile-time error to explicitly instantiate an enum instance. | 70 // It is a compile-time error to explicitly instantiate an enum instance. |
71 var x = new Color(); /// 30: compile-time error | 71 var x = new Color(); //# 30: compile-time error |
72 } | 72 } |
73 | 73 |
OLD | NEW |