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 // Dart test for closures. | 4 // Dart test for closures. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class ClosureBreak1 { | 8 class ClosureBreak1 { |
9 ClosureBreak1(this.field); | 9 ClosureBreak1(this.field); |
10 int field; | 10 int field; |
11 } | 11 } |
12 | 12 |
13 class ClosureBreak1Test { | 13 class ClosureBreak1Test { |
14 static testMain() { | 14 static testMain() { |
15 var o1 = new ClosureBreak1(3); | 15 var o1 = new ClosureBreak1(3); |
16 String newstr = "abcdefgh"; | 16 String newstr = "abcdefgh"; |
17 foo() { | 17 foo() { |
18 o1.field++; | 18 o1.field++; |
19 Expect.equals(8, newstr.length); | 19 Expect.equals(8, newstr.length); |
20 } | 20 } |
| 21 |
21 bool loop = true; | 22 bool loop = true; |
22 L: | 23 L: |
23 while (loop) { | 24 while (loop) { |
24 String newstr1 = "abcd"; | 25 String newstr1 = "abcd"; |
25 var o2 = new ClosureBreak1(3); | 26 var o2 = new ClosureBreak1(3); |
26 foo1() { | 27 foo1() { |
27 o2.field++; | 28 o2.field++; |
28 Expect.equals(4, newstr1.length); | 29 Expect.equals(4, newstr1.length); |
29 } | 30 } |
| 31 |
30 Expect.equals(4, newstr1.length); | 32 Expect.equals(4, newstr1.length); |
31 while (loop) { | 33 while (loop) { |
32 int newint = 0; | 34 int newint = 0; |
33 var o3 = new ClosureBreak1(3); | 35 var o3 = new ClosureBreak1(3); |
34 foo2() { | 36 foo2() { |
35 o3.field++; | 37 o3.field++; |
36 Expect.equals(0, newint); | 38 Expect.equals(0, newint); |
37 } | 39 } |
| 40 |
38 foo2(); | 41 foo2(); |
39 break L; | 42 break L; |
40 } | 43 } |
41 } | 44 } |
42 foo(); | 45 foo(); |
43 Expect.equals(4, o1.field); | 46 Expect.equals(4, o1.field); |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 main() { | 50 main() { |
48 ClosureBreak1Test.testMain(); | 51 ClosureBreak1Test.testMain(); |
49 } | 52 } |
OLD | NEW |