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 class A { | 5 class A { |
6 operator+(arg) => 42; | 6 operator+(arg) => 42; |
7 } | 7 } |
8 | 8 |
9 get42() => 42; | 9 get42() => 42; |
10 getNonInt() => new A(); | 10 getNonInt() => new A(); |
11 use(x) => x; | 11 use(x) => x; |
12 | 12 |
13 void testInWhileLoop() { | 13 void testInWhileLoop() { |
14 var c = get42(); | 14 var c = get42(); |
15 while (true) { | 15 while (true) { |
16 var e = getNonInt(); | 16 var e = getNonInt(); |
17 Expect.equals(42, e + 2); | 17 Expect.equals(42, e + 2); |
18 if (e !== null) break; | 18 if (e != null) break; |
19 while (true) use(e); | 19 while (true) use(e); |
20 } | 20 } |
21 // This is what matters: 'c' must have been saved in the | 21 // This is what matters: 'c' must have been saved in the |
22 // environment. | 22 // environment. |
23 Expect.equals(c, 42); | 23 Expect.equals(c, 42); |
24 } | 24 } |
25 | 25 |
26 void testInNestedWhileLoop() { | 26 void testInNestedWhileLoop() { |
27 var c = get42(); | 27 var c = get42(); |
28 while (true) { | 28 while (true) { |
29 while (true) { | 29 while (true) { |
30 var e = getNonInt(); | 30 var e = getNonInt(); |
31 Expect.equals(42, e + 2); | 31 Expect.equals(42, e + 2); |
32 if (e !== null) break; | 32 if (e != null) break; |
33 } | 33 } |
34 // This is what matters: 'c' must have been saved in the | 34 // This is what matters: 'c' must have been saved in the |
35 // environment. | 35 // environment. |
36 Expect.equals(c, 42); | 36 Expect.equals(c, 42); |
37 if (c == 42) break; | 37 if (c == 42) break; |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 void testInNestedWhileLoop2() { | 41 void testInNestedWhileLoop2() { |
42 var c = get42(); | 42 var c = get42(); |
43 L0: while (true) { | 43 L0: while (true) { |
44 while (true) { | 44 while (true) { |
45 var e = getNonInt(); | 45 var e = getNonInt(); |
46 Expect.equals(42, e + 2); | 46 Expect.equals(42, e + 2); |
47 if (e !== null) break L0; | 47 if (e != null) break L0; |
48 while (true) use(e); | 48 while (true) use(e); |
49 } | 49 } |
50 } | 50 } |
51 // This is what matters: 'c' must have been saved in the | 51 // This is what matters: 'c' must have been saved in the |
52 // environment. | 52 // environment. |
53 Expect.equals(c, 42); | 53 Expect.equals(c, 42); |
54 } | 54 } |
55 | 55 |
56 void testInNestedWhileLoop3() { | 56 void testInNestedWhileLoop3() { |
57 var c = get42(); | 57 var c = get42(); |
58 int index = 0; | 58 int index = 0; |
59 while (index < 2) { | 59 while (index < 2) { |
60 while (index < 2) { | 60 while (index < 2) { |
61 var e = getNonInt(); | 61 var e = getNonInt(); |
62 Expect.equals(42, e + 2); | 62 Expect.equals(42, e + 2); |
63 if (e !== null && index++ == 0) break; | 63 if (e != null && index++ == 0) break; |
64 // This is what matters: 'c' must have been saved in the | 64 // This is what matters: 'c' must have been saved in the |
65 // environment. | 65 // environment. |
66 Expect.equals(c, 42); | 66 Expect.equals(c, 42); |
67 while (e === null) use(e); | 67 while (e == null) use(e); |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void testInDoWhileLoop() { | 72 void testInDoWhileLoop() { |
73 var c = get42(); | 73 var c = get42(); |
74 do { | 74 do { |
75 var e = getNonInt(); | 75 var e = getNonInt(); |
76 Expect.equals(42, e + 2); | 76 Expect.equals(42, e + 2); |
77 if (e !== null) break; | 77 if (e != null) break; |
78 while (true) use(e); | 78 while (true) use(e); |
79 } while (true); | 79 } while (true); |
80 // This is what matters: 'c' must have been saved in the | 80 // This is what matters: 'c' must have been saved in the |
81 // environment. | 81 // environment. |
82 Expect.equals(c, 42); | 82 Expect.equals(c, 42); |
83 } | 83 } |
84 | 84 |
85 void testInForLoop() { | 85 void testInForLoop() { |
86 var c = get42(); | 86 var c = get42(); |
87 for (int i = 0; i < 10; i++) { | 87 for (int i = 0; i < 10; i++) { |
88 var e = getNonInt(); | 88 var e = getNonInt(); |
89 Expect.equals(42, e + 2); | 89 Expect.equals(42, e + 2); |
90 if (e !== null) break; | 90 if (e != null) break; |
91 while (true) use(e); | 91 while (true) use(e); |
92 } | 92 } |
93 // This is what matters: 'c' must have been saved in the | 93 // This is what matters: 'c' must have been saved in the |
94 // environment. | 94 // environment. |
95 Expect.equals(c, 42); | 95 Expect.equals(c, 42); |
96 } | 96 } |
97 | 97 |
98 void testLabeledIf() { | 98 void testLabeledIf() { |
99 var c = get42(); | 99 var c = get42(); |
100 L1: if (c == 42) { | 100 L1: if (c == 42) { |
101 var e = getNonInt(); | 101 var e = getNonInt(); |
102 Expect.equals(42, e + 2); | 102 Expect.equals(42, e + 2); |
103 if (e === null) break L1; | 103 if (e == null) break L1; |
104 // This is what matters: 'c' must have been saved in the | 104 // This is what matters: 'c' must have been saved in the |
105 // environment. | 105 // environment. |
106 Expect.equals(c, 42); | 106 Expect.equals(c, 42); |
107 while (e === null) use(e); | 107 while (e == null) use(e); |
108 } | 108 } |
109 Expect.equals(c, 42); | 109 Expect.equals(c, 42); |
110 } | 110 } |
111 | 111 |
112 void testLabeledIf2() { | 112 void testLabeledIf2() { |
113 var c = get42(); | 113 var c = get42(); |
114 L1: if (c == 42) { | 114 L1: if (c == 42) { |
115 var e = getNonInt(); | 115 var e = getNonInt(); |
116 Expect.equals(42, e + 2); | 116 Expect.equals(42, e + 2); |
117 if (e === null) break L1; | 117 if (e == null) break L1; |
118 Expect.equals(42, e + 1); | 118 Expect.equals(42, e + 1); |
119 while (e === null) use(e); | 119 while (e == null) use(e); |
120 } | 120 } |
121 Expect.equals(42, c); | 121 Expect.equals(42, c); |
122 } | 122 } |
123 | 123 |
124 main() { | 124 main() { |
125 testInWhileLoop(); | 125 testInWhileLoop(); |
126 testInDoWhileLoop(); | 126 testInDoWhileLoop(); |
127 testInForLoop(); | 127 testInForLoop(); |
128 testInNestedWhileLoop(); | 128 testInNestedWhileLoop(); |
129 testInNestedWhileLoop2(); | 129 testInNestedWhileLoop2(); |
130 testInNestedWhileLoop3(); | 130 testInNestedWhileLoop3(); |
131 testLabeledIf(); | 131 testLabeledIf(); |
132 testLabeledIf2(); | 132 testLabeledIf2(); |
133 } | 133 } |
OLD | NEW |