Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: tests/kernel/unsorted/try_finally_test.dart

Issue 2451623006: Reland "Merge more Kernel infrastructure from kernel_sdk SDK fork." (Closed)
Patch Set: Fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/kernel/unsorted/try_context_test.dart ('k') | tests/kernel/unsorted/type_args_regression_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « tests/kernel/unsorted/try_context_test.dart ('k') | tests/kernel/unsorted/type_args_regression_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698