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 int j; | 14 int j; |
16 j = func(); | 15 j = func(); |
17 try { | 16 try { |
18 i = 1; | 17 i = 1; |
19 return i; // Value of i is 1 on return. | 18 return i; // Value of i is 1 on return. |
20 } finally { | 19 } finally { |
21 i = i + 400; // Should get executed when we return. | 20 i = i + 400; // Should get executed when we return. |
22 } | 21 } |
23 i = 2; // Should not get executed. | 22 i = 2; // Should not get executed. |
24 return i; | 23 return i; |
25 } finally { | 24 } finally { |
26 i = i + 800; // Should get executed when we return. | 25 i = i + 800; // Should get executed when we return. |
27 } | 26 } |
28 return i + 200; // Should not get executed. | 27 return i + 200; // Should not get executed. |
29 } | 28 } |
30 | 29 |
31 static int func() { | 30 static int func() { |
32 int i = 0; | 31 int i = 0; |
33 while (i < 10) { | 32 while (i < 10) { |
34 i++; | 33 i++; |
35 } | 34 } |
36 return i; | 35 return i; |
37 } | 36 } |
38 | 37 |
39 int i; | 38 int i; |
40 } | 39 } |
41 | 40 |
42 class ExecuteFinally2Test { | 41 class ExecuteFinally2Test { |
43 static testMain() { | 42 static testMain() { |
44 Helper obj = new Helper(); | 43 Helper obj = new Helper(); |
45 Expect.equals(1, obj.f1()); | 44 Expect.equals(1, obj.f1()); |
46 Expect.equals(1201, obj.i); | 45 Expect.equals(1201, obj.i); |
47 } | 46 } |
48 } | 47 } |
49 | 48 |
50 main() { | 49 main() { |
51 ExecuteFinally2Test.testMain(); | 50 ExecuteFinally2Test.testMain(); |
52 } | 51 } |
OLD | NEW |