OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Check that conditional expression can be a compile-time constant. | 5 // Check that conditional expression can be a compile-time constant. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 const C1 = true; | 9 const C1 = true; |
10 const C2 = false; | 10 const C2 = false; |
11 | 11 |
12 const nephew = C1 ? C2 ? "Tick" : "Trick" : "Track"; | 12 const nephew = C1 ? C2 ? "Tick" : "Trick" : "Track"; |
13 | 13 |
14 main() { | 14 main() { |
15 const a = true ? 5 : 10; | 15 const a = true ? 5 : 10; |
16 const b = C2 ? "Track" : C1 ? "Trick" : "Tick"; | 16 const b = C2 ? "Track" : C1 ? "Trick" : "Tick"; |
17 | 17 |
18 Expect.equals(5, a); | 18 Expect.equals(5, a); |
19 Expect.equals("Trick", nephew); | 19 Expect.equals("Trick", nephew); |
20 Expect.equals(nephew, b); | 20 Expect.equals(nephew, b); |
21 Expect.identical(nephew, b); | 21 Expect.identical(nephew, b); |
22 var s = const Symbol(nephew); | 22 var s = const Symbol(nephew); |
23 var msg = "Donald is $nephew's uncle."; | 23 var msg = "Donald is $nephew's uncle."; |
24 Expect.equals("Donald is Trick's uncle.", msg); | 24 Expect.equals("Donald is Trick's uncle.", msg); |
25 } | 25 } |
OLD | NEW |