| Index: tests/kernel/unsorted/try_finally_test.dart
|
| diff --git a/tests/kernel/unsorted/try_finally_test.dart b/tests/kernel/unsorted/try_finally_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3eddd4ff7239c2329291dd461ab9c85264faa653
|
| --- /dev/null
|
| +++ b/tests/kernel/unsorted/try_finally_test.dart
|
| @@ -0,0 +1,158 @@
|
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'expect.dart';
|
| +
|
| +testSimpleBreak() {
|
| + var x = 1;
|
| + while (true) {
|
| + try {
|
| + x++;
|
| + break;
|
| + } finally {
|
| + x++;
|
| + break;
|
| + }
|
| + }
|
| + return x;
|
| +}
|
| +
|
| +testReturnFinally() {
|
| + try {
|
| + return 1;
|
| + } finally {
|
| + return 42;
|
| + }
|
| +}
|
| +
|
| +testNestedReturnFinally() {
|
| + try {
|
| + try {
|
| + return 1;
|
| + } finally {
|
| + return 2;
|
| + }
|
| + } finally {
|
| + return 42;
|
| + }
|
| +}
|
| +
|
| +testReturnInsideLoop() {
|
| + while (true) {
|
| + try {
|
| + print("hello");
|
| + } finally {
|
| + return 42;
|
| + }
|
| + }
|
| +}
|
| +
|
| +testStopContinueInsideLoop() {
|
| + while (true) {
|
| + try {
|
| + continue;
|
| + } finally {
|
| + return 42;
|
| + }
|
| + }
|
| +}
|
| +
|
| +testStopBreakInsideLoop() {
|
| + var foo = 1;
|
| + while (true) {
|
| + try {
|
| + if (foo == 1) {
|
| + // 1st iteration we break.
|
| + break;
|
| + } else if (foo == 2) {
|
| + // 2nd iteration we return.
|
| + return 42;
|
| + }
|
| + } finally {
|
| + // 1st iteration we overrwrite break with continue.
|
| + if (foo == 1) {
|
| + foo++;
|
| + continue;
|
| + } else {
|
| + // Let return work
|
| + }
|
| + }
|
| + }
|
| + return foo;
|
| +}
|
| +
|
| +testStopBreakInsideLoop2() {
|
| + var foo = 1;
|
| + while (true) {
|
| + try {
|
| + if (foo == 1) {
|
| + // 1st iteration we break.
|
| + break;
|
| + } else if (foo == 2) {
|
| + // 2nd iteration we return.
|
| + return -1;
|
| + }
|
| + } finally {
|
| + // 1st iteration we overrwrite break with continue.
|
| + if (foo == 1) {
|
| + foo++;
|
| + continue;
|
| + } else {
|
| + // 2nd iteration we overrwrite return with break.
|
| + foo = 42;
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + return foo;
|
| +}
|
| +
|
| +testStopContinueInsideSwitch() {
|
| + var foo = 1;
|
| + switch (foo) {
|
| + jump5:
|
| + case 5:
|
| + return -1;
|
| +
|
| + case 1:
|
| + try {
|
| + continue jump5;
|
| + } finally {
|
| + return 42;
|
| + }
|
| + }
|
| +}
|
| +
|
| +testStopContinueInsideSwitch2() {
|
| + var foo = 1;
|
| + switch (foo) {
|
| + jump5:
|
| + case 5:
|
| + return -1;
|
| +
|
| + jump42:
|
| + case 5:
|
| + return 42;
|
| +
|
| + case 1:
|
| + try {
|
| + continue jump5;
|
| + } finally {
|
| + continue jump42;
|
| + }
|
| + }
|
| +}
|
| +
|
| +main() {
|
| + Expect.isTrue(testSimpleBreak() == 3);
|
| + Expect.isTrue(testReturnFinally() == 42);
|
| + Expect.isTrue(testNestedReturnFinally() == 42);
|
| + Expect.isTrue(testReturnInsideLoop() == 42);
|
| + Expect.isTrue(testStopContinueInsideLoop() == 42);
|
| + Expect.isTrue(testStopBreakInsideLoop() == 42);
|
| + Expect.isTrue(testStopBreakInsideLoop2() == 42);
|
| + Expect.isTrue(testStopContinueInsideLoop() == 42);
|
| + Expect.isTrue(testStopContinueInsideSwitch() == 42);
|
| + Expect.isTrue(testStopContinueInsideSwitch2() == 42);
|
| +}
|
|
|