OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test for conditionals as compile-time constants. | 5 // Test for conditionals as compile-time constants. |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 | 8 |
9 class Marker { | 9 class Marker { |
10 final field; | 10 final field; |
11 const Marker(this.field); | 11 const Marker(this.field); |
12 } | 12 } |
13 | 13 |
14 var var0 = const Marker(0); | 14 var var0 = const Marker(0); |
15 var var1 = const Marker(1); | 15 var var1 = const Marker(1); |
16 const const0 = const Marker(0); | 16 const const0 = const Marker(0); |
17 const const1 = const Marker(1); | 17 const const1 = const Marker(1); |
18 | 18 |
19 const trueConst = true; | 19 const trueConst = true; |
20 const falseConst = false; | 20 const falseConst = false; |
21 var nonConst = true; | 21 var nonConst = true; |
22 const zeroConst = 0; | 22 const zeroConst = 0; |
23 | 23 |
24 const cond1 = trueConst ? const0 : const1; | 24 const cond1 = trueConst ? const0 : const1; |
25 const cond1a = trueConst ? nonConst : const1; /// 01: compile-time error | 25 const cond1a = trueConst ? nonConst : const1; //# 01: compile-time error |
26 const cond1b = trueConst ? const0 : nonConst; /// 02: compile-time error | 26 const cond1b = trueConst ? const0 : nonConst; //# 02: compile-time error |
27 | 27 |
28 const cond2 = falseConst ? const0 : const1; | 28 const cond2 = falseConst ? const0 : const1; |
29 const cond2a = falseConst ? nonConst : const1; /// 03: compile-time error | 29 const cond2a = falseConst ? nonConst : const1; //# 03: compile-time error |
30 const cond2b = falseConst ? const0 : nonConst; /// 04: compile-time error | 30 const cond2b = falseConst ? const0 : nonConst; //# 04: compile-time error |
31 | 31 |
32 const cond3 = nonConst ? const0 : const1; /// 05: compile-time error | 32 const cond3 = nonConst ? const0 : const1; //# 05: compile-time error |
33 const cond3a = nonConst ? nonConst : const1; /// 06: compile-time error | 33 const cond3a = nonConst ? nonConst : const1; //# 06: compile-time error |
34 const cond3b = nonConst ? const0 : nonConst; /// 07: compile-time error | 34 const cond3b = nonConst ? const0 : nonConst; //# 07: compile-time error |
35 | 35 |
36 const cond4 = zeroConst ? const0 : const1; /// 08: compile-time error | 36 const cond4 = zeroConst ? const0 : const1; //# 08: compile-time error |
37 const cond4a = zeroConst ? nonConst : const1; /// 09: compile-time error | 37 const cond4a = zeroConst ? nonConst : const1; //# 09: compile-time error |
38 const cond4b = zeroConst ? const0 : nonConst; /// 10: compile-time error | 38 const cond4b = zeroConst ? const0 : nonConst; //# 10: compile-time error |
39 | 39 |
40 void main() { | 40 void main() { |
41 Expect.identical(var0, cond1); | 41 Expect.identical(var0, cond1); |
42 Expect.identical(nonConst, cond1a); /// 01: continued | 42 Expect.identical(nonConst, cond1a); //# 01: continued |
43 Expect.identical(var0, cond1b); /// 02: continued | 43 Expect.identical(var0, cond1b); //# 02: continued |
44 | 44 |
45 Expect.identical(var1, cond2); | 45 Expect.identical(var1, cond2); |
46 Expect.identical(var1, cond2a); /// 03: continued | 46 Expect.identical(var1, cond2a); //# 03: continued |
47 Expect.identical(nonConst, cond2b); /// 04: continued | 47 Expect.identical(nonConst, cond2b); //# 04: continued |
48 | 48 |
49 Expect.identical(var0, cond3); // /// 05: continued | 49 Expect.identical(var0, cond3); // //# 05: continued |
50 Expect.identical(nonConst, cond3a); /// 06: continued | 50 Expect.identical(nonConst, cond3a); //# 06: continued |
51 Expect.identical(var0, cond3b); /// 07: continued | 51 Expect.identical(var0, cond3b); //# 07: continued |
52 | 52 |
53 Expect.identical(var1, cond4); // /// 08: continued | 53 Expect.identical(var1, cond4); // //# 08: continued |
54 Expect.identical(var1, cond4a); /// 09: continued | 54 Expect.identical(var1, cond4a); //# 09: continued |
55 Expect.identical(nonConst, cond4b); /// 10: continued | 55 Expect.identical(nonConst, cond4b); //# 10: continued |
56 } | 56 } |
OLD | NEW |