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

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

Issue 2434123003: Merge more Kernel infrastructure from kernel_sdk SDK fork. (Closed)
Patch Set: 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..bf048fa1db0d625cc87265c9fa9c4a7ee71676e6
--- /dev/null
+++ b/tests/kernel/unsorted/throw_try_catch_test.dart
@@ -0,0 +1,186 @@
+import 'expect.dart';
Kevin Millikin (Google) 2016/10/21 09:10:58 Copyright header.
Vyacheslav Egorov (Google) 2016/10/21 13:39:44 Done.
+
+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