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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class A { | 7 class A { |
8 operator+(arg) => 42; | 8 operator +(arg) => 42; |
9 } | 9 } |
10 | 10 |
11 get42() => 42; | 11 get42() => 42; |
12 getNonInt() => new A(); | 12 getNonInt() => new A(); |
13 use(x) => x; | 13 use(x) => x; |
14 | 14 |
15 void testInWhileLoop() { | 15 void testInWhileLoop() { |
16 var c = get42(); | 16 var c = get42(); |
17 while (true) { | 17 while (true) { |
18 var e = getNonInt(); | 18 var e = getNonInt(); |
(...skipping 16 matching lines...) Expand all Loading... |
35 } | 35 } |
36 // This is what matters: 'c' must have been saved in the | 36 // This is what matters: 'c' must have been saved in the |
37 // environment. | 37 // environment. |
38 Expect.equals(c, 42); | 38 Expect.equals(c, 42); |
39 if (c == 42) break; | 39 if (c == 42) break; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 void testInNestedWhileLoop2() { | 43 void testInNestedWhileLoop2() { |
44 var c = get42(); | 44 var c = get42(); |
45 L0: while (true) { | 45 L0: |
| 46 while (true) { |
46 while (true) { | 47 while (true) { |
47 var e = getNonInt(); | 48 var e = getNonInt(); |
48 Expect.equals(42, e + 2); | 49 Expect.equals(42, e + 2); |
49 if (e != null) break L0; | 50 if (e != null) break L0; |
50 while (true) use(e); | 51 while (true) use(e); |
51 } | 52 } |
52 } | 53 } |
53 // This is what matters: 'c' must have been saved in the | 54 // This is what matters: 'c' must have been saved in the |
54 // environment. | 55 // environment. |
55 Expect.equals(c, 42); | 56 Expect.equals(c, 42); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (e != null) break; | 93 if (e != null) break; |
93 while (true) use(e); | 94 while (true) use(e); |
94 } | 95 } |
95 // This is what matters: 'c' must have been saved in the | 96 // This is what matters: 'c' must have been saved in the |
96 // environment. | 97 // environment. |
97 Expect.equals(c, 42); | 98 Expect.equals(c, 42); |
98 } | 99 } |
99 | 100 |
100 void testLabeledIf() { | 101 void testLabeledIf() { |
101 var c = get42(); | 102 var c = get42(); |
102 L1: if (c == 42) { | 103 L1: |
| 104 if (c == 42) { |
103 var e = getNonInt(); | 105 var e = getNonInt(); |
104 Expect.equals(42, e + 2); | 106 Expect.equals(42, e + 2); |
105 if (e == null) break L1; | 107 if (e == null) break L1; |
106 // This is what matters: 'c' must have been saved in the | 108 // This is what matters: 'c' must have been saved in the |
107 // environment. | 109 // environment. |
108 Expect.equals(c, 42); | 110 Expect.equals(c, 42); |
109 while (e == null) use(e); | 111 while (e == null) use(e); |
110 } | 112 } |
111 Expect.equals(c, 42); | 113 Expect.equals(c, 42); |
112 } | 114 } |
113 | 115 |
114 void testLabeledIf2() { | 116 void testLabeledIf2() { |
115 var c = get42(); | 117 var c = get42(); |
116 L1: if (c == 42) { | 118 L1: |
| 119 if (c == 42) { |
117 var e = getNonInt(); | 120 var e = getNonInt(); |
118 Expect.equals(42, e + 2); | 121 Expect.equals(42, e + 2); |
119 if (e == null) break L1; | 122 if (e == null) break L1; |
120 Expect.equals(42, e + 1); | 123 Expect.equals(42, e + 1); |
121 while (e == null) use(e); | 124 while (e == null) use(e); |
122 } | 125 } |
123 Expect.equals(42, c); | 126 Expect.equals(42, c); |
124 } | 127 } |
125 | 128 |
126 main() { | 129 main() { |
127 testInWhileLoop(); | 130 testInWhileLoop(); |
128 testInDoWhileLoop(); | 131 testInDoWhileLoop(); |
129 testInForLoop(); | 132 testInForLoop(); |
130 testInNestedWhileLoop(); | 133 testInNestedWhileLoop(); |
131 testInNestedWhileLoop2(); | 134 testInNestedWhileLoop2(); |
132 testInNestedWhileLoop3(); | 135 testInNestedWhileLoop3(); |
133 testLabeledIf(); | 136 testLabeledIf(); |
134 testLabeledIf2(); | 137 testLabeledIf2(); |
135 } | 138 } |
OLD | NEW |