OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Check that conditional expressions can contain assignment expressions. | 4 // Check that conditional expressions can contain assignment expressions. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 | |
9 var e1, e2; | 8 var e1, e2; |
10 | 9 |
11 f(a) => a < 0 ? e1 = -1 : e2 = 1; | 10 f(a) => a < 0 ? e1 = -1 : e2 = 1; |
12 | 11 |
13 main() { | 12 main() { |
14 e1 = 0; | 13 e1 = 0; |
15 e2 = 0; | 14 e2 = 0; |
16 var r = f(-100); | 15 var r = f(-100); |
17 Expect.equals(-1, r); | 16 Expect.equals(-1, r); |
18 Expect.equals(-1, e1); | 17 Expect.equals(-1, e1); |
19 Expect.equals(0, e2); | 18 Expect.equals(0, e2); |
20 | 19 |
21 e1 = 0; | 20 e1 = 0; |
22 e2 = 0; | 21 e2 = 0; |
23 r = f(100); | 22 r = f(100); |
24 Expect.equals(1, r); | 23 Expect.equals(1, r); |
25 Expect.equals(0, e1); | 24 Expect.equals(0, e1); |
26 Expect.equals(1, e2); | 25 Expect.equals(1, e2); |
27 } | 26 } |
OLD | NEW |