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 program for testing execution of finally blocks on | 4 // Dart test program for testing execution of finally blocks on |
5 // control flow breaks because of 'return', 'continue' etc. | 5 // control flow breaks because of 'return', 'continue' etc. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 | |
10 class Helper { | 9 class Helper { |
11 Helper() : i = 0 { } | 10 Helper() : i = 0 {} |
12 | 11 |
13 int f1() { | 12 int f1() { |
14 try { | 13 try { |
15 try { | 14 try { |
16 int j; | 15 int j; |
17 j = func(); | 16 j = func(); |
18 L1: | 17 L1: |
19 while (i <= 0) { | 18 while (i <= 0) { |
20 if (i == 0) { | 19 if (i == 0) { |
21 try { | 20 try { |
22 i = 1; | 21 i = 1; |
23 func(); | 22 func(); |
24 try { | 23 try { |
25 int j; | 24 int j; |
26 j = func(); | 25 j = func(); |
27 while (j < 50) { | 26 while (j < 50) { |
28 j += func(); | 27 j += func(); |
29 if (j > 30) { | 28 if (j > 30) { |
30 continue L1; // Break out of nested try blocks. | 29 continue L1; // Break out of nested try blocks. |
31 } | 30 } |
32 } | 31 } |
33 i = 200000; // Should not get executed. | 32 i = 200000; // Should not get executed. |
34 } finally { | 33 } finally { |
35 i = i + 200; // Should get executed when we break out. | 34 i = i + 200; // Should get executed when we break out. |
36 } | 35 } |
37 } finally { | 36 } finally { |
38 i = i + 400; // Should get executed when we break out. | 37 i = i + 400; // Should get executed when we break out. |
39 } | 38 } |
40 } | 39 } |
41 } | 40 } |
42 } finally { | 41 } finally { |
43 i = i + 800; // Should get executed as normal control flow. | 42 i = i + 800; // Should get executed as normal control flow. |
44 } | 43 } |
45 return i; // Value of i should be 1401. | 44 return i; // Value of i should be 1401. |
46 } finally { | 45 } finally { |
47 i = i + 1600; // Should get executed as part of return above. | 46 i = i + 1600; // Should get executed as part of return above. |
48 } | 47 } |
49 i = i + 2000000; // Should not get executed. | 48 i = i + 2000000; // Should not get executed. |
50 return 1; | 49 return 1; |
51 } | 50 } |
52 | 51 |
53 static int func() { | 52 static int func() { |
54 int i = 0; | 53 int i = 0; |
55 while (i < 10) { | 54 while (i < 10) { |
56 i++; | 55 i++; |
57 } | 56 } |
58 return i; | 57 return i; |
59 } | 58 } |
60 | 59 |
61 int i; | 60 int i; |
62 } | 61 } |
63 | 62 |
64 class ExecuteFinally3Test { | 63 class ExecuteFinally3Test { |
65 static testMain() { | 64 static testMain() { |
66 Helper obj = new Helper(); | 65 Helper obj = new Helper(); |
67 Expect.equals(1401, obj.f1()); | 66 Expect.equals(1401, obj.f1()); |
68 Expect.equals(3001, obj.i); | 67 Expect.equals(3001, obj.i); |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 main() { | 71 main() { |
73 ExecuteFinally3Test.testMain(); | 72 ExecuteFinally3Test.testMain(); |
74 } | 73 } |
OLD | NEW |