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

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

Issue 2434123003: Merge more Kernel infrastructure from kernel_sdk SDK fork. (Closed)
Patch Set: address more comments 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
Index: tests/kernel/unsorted/throw_try_catch_test.dart
diff --git a/tests/kernel/unsorted/throw_try_catch_test.dart b/tests/kernel/unsorted/throw_try_catch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..69ebbeafbf01c4bdcab9af16c86e049eac2fcbb2
--- /dev/null
+++ b/tests/kernel/unsorted/throw_try_catch_test.dart
@@ -0,0 +1,190 @@
+// 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';
+
+testSimpleThrowCatch() {
+ var x = 1;
+ try {
+ throw x++;
+ } on int catch (e) {
+ Expect.isTrue(e == 1);
+ Expect.isTrue(x == 2);
+ x++;
+ }
+ Expect.isTrue(x == 3);
+}
+
+testNestedThrowCatch() {
+ var x = 1;
+ try {
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 1);
+ Expect.isTrue(x == 2);
+ x++;
+
+ try {
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 3);
+ Expect.isTrue(x == 4);
+ x++;
+ }
+ }
+ Expect.isTrue(x == 5);
+}
+
+testNestedThrowCatch2() {
+ var x = 1;
+ try {
+ try {
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 1);
+ Expect.isTrue(x == 2);
+ x++;
+ }
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 3);
+ Expect.isTrue(x == 4);
+ x++;
+ }
+ Expect.isTrue(x == 5);
+}
+
+testSiblingThrowCatch() {
+ var x = 1;
+ try {
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 1);
+ Expect.isTrue(x == 2);
+ x++;
+ }
+ try {
+ throw x++;
+ } catch (e) {
+ Expect.isTrue(e == 3);
+ Expect.isTrue(x == 4);
+ x++;
+ }
+
+ Expect.isTrue(x == 5);
+}
+
+testTypedCatch() {
+ var good = false;
+ try {
+ throw 1;
+ } on int catch (e) {
+ Expect.isTrue(e == 1);
+ good = true;
+ } on String catch (_) {
+ Expect.isTrue(false);
+ }
+ Expect.isTrue(good);
+}
+
+testTypedCatch2() {
+ var good = false;
+ try {
+ throw 'a';
+ } on int catch (_) {
+ Expect.isTrue(false);
+ } on String catch (e) {
+ Expect.isTrue(e == 'a');
+ good = true;
+ }
+ Expect.isTrue(good);
+}
+
+testThrowNull() {
+ var good = false;
+ try {
+ throw null;
+ } on NullThrownError catch (_) {
+ good = true;
+ }
+ Expect.isTrue(good);
+}
+
+testFinally() {
+ var x = 0;
+ try {
+ throw x++;
+ } catch (_) {
+ x++;
+ } finally {
+ x++;
+ }
+ Expect.isTrue(x == 3);
+}
+
+testFinally2() {
+ var x = 0;
+ try {
+ try {
+ throw x++;
+ } catch (_) {
+ x++;
+ } finally {
+ x++;
+ }
+ } finally {
+ x++;
+ }
+ Expect.isTrue(x == 4);
+}
+
+testFinally3() {
+ try {
+ var x = 0;
+ try {
+ throw x++;
+ } finally {
+ x++;
+ }
+ Expect.isTrue(x == 2);
+ } catch (_) {}
+}
+
+testSuccessfulBody() {
+ var x = 0;
+ try {
+ x++;
+ } finally {
+ x++;
+ }
+ Expect.isTrue(x == 2);
+}
+
+testSuccessfulBody2() {
+ var x = 0;
+ try {
+ try {
+ x++;
+ } finally {
+ x++;
+ throw 1;
+ }
+ } on int {}
+ Expect.isTrue(x == 2);
+}
+
+main() {
+ testSimpleThrowCatch();
+ testNestedThrowCatch();
+ testNestedThrowCatch2();
+ testSiblingThrowCatch();
+ testTypedCatch();
+ testTypedCatch2();
+ testThrowNull();
+ testFinally();
+ testFinally2();
+ testFinally3();
+ testSuccessfulBody();
+ testSuccessfulBody2();
+}

Powered by Google App Engine
This is Rietveld 408576698