| 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 i = 1; | 16 i = 1; |
| 18 } finally { | 17 } finally { |
| 19 i = i + 10; | 18 i = i + 10; |
| 20 } | 19 } |
| 21 return i + 200; // Should return here with i = 211. | 20 return i + 200; // Should return here with i = 211. |
| 22 try { | 21 try { |
| 23 int j; | 22 int j; |
| 24 j = func(); | 23 j = func(); |
| 25 } finally { | 24 } finally { |
| 26 i = i + 10; // Should not get executed as part of return above. | 25 i = i + 10; // Should not get executed as part of return above. |
| 27 } | 26 } |
| 28 } | 27 } |
| 29 | 28 |
| 30 static int func() { | 29 static int func() { |
| 31 int i = 0; | 30 int i = 0; |
| 32 while (i < 10) { | 31 while (i < 10) { |
| 33 i++; | 32 i++; |
| 34 } | 33 } |
| 35 return i; | 34 return i; |
| 36 } | 35 } |
| 37 | 36 |
| 38 int i; | 37 int i; |
| 39 } | 38 } |
| 40 | 39 |
| 41 class ExecuteFinally4Test { | 40 class ExecuteFinally4Test { |
| 42 static testMain() { | 41 static testMain() { |
| 43 Helper obj = new Helper(); | 42 Helper obj = new Helper(); |
| 44 Expect.equals(211, obj.f1()); | 43 Expect.equals(211, obj.f1()); |
| 45 Expect.equals(11, obj.i); | 44 Expect.equals(11, obj.i); |
| 46 } | 45 } |
| 47 } | 46 } |
| 48 | 47 |
| 49 main() { | 48 main() { |
| 50 ExecuteFinally4Test.testMain(); | 49 ExecuteFinally4Test.testMain(); |
| 51 } | 50 } |
| OLD | NEW |