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

Side by Side Diff: tests/kernel/unsorted/throw_try_catch_test.dart

Issue 2451623006: Reland "Merge more Kernel infrastructure from kernel_sdk SDK fork." (Closed)
Patch Set: Fix Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « tests/kernel/unsorted/this_test.dart ('k') | tests/kernel/unsorted/try_context_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'expect.dart';
6
7 testSimpleThrowCatch() {
8 var x = 1;
9 try {
10 throw x++;
11 } on int catch (e) {
12 Expect.isTrue(e == 1);
13 Expect.isTrue(x == 2);
14 x++;
15 }
16 Expect.isTrue(x == 3);
17 }
18
19 testNestedThrowCatch() {
20 var x = 1;
21 try {
22 throw x++;
23 } catch (e) {
24 Expect.isTrue(e == 1);
25 Expect.isTrue(x == 2);
26 x++;
27
28 try {
29 throw x++;
30 } catch (e) {
31 Expect.isTrue(e == 3);
32 Expect.isTrue(x == 4);
33 x++;
34 }
35 }
36 Expect.isTrue(x == 5);
37 }
38
39 testNestedThrowCatch2() {
40 var x = 1;
41 try {
42 try {
43 throw x++;
44 } catch (e) {
45 Expect.isTrue(e == 1);
46 Expect.isTrue(x == 2);
47 x++;
48 }
49 throw x++;
50 } catch (e) {
51 Expect.isTrue(e == 3);
52 Expect.isTrue(x == 4);
53 x++;
54 }
55 Expect.isTrue(x == 5);
56 }
57
58 testSiblingThrowCatch() {
59 var x = 1;
60 try {
61 throw x++;
62 } catch (e) {
63 Expect.isTrue(e == 1);
64 Expect.isTrue(x == 2);
65 x++;
66 }
67 try {
68 throw x++;
69 } catch (e) {
70 Expect.isTrue(e == 3);
71 Expect.isTrue(x == 4);
72 x++;
73 }
74
75 Expect.isTrue(x == 5);
76 }
77
78 testTypedCatch() {
79 var good = false;
80 try {
81 throw 1;
82 } on int catch (e) {
83 Expect.isTrue(e == 1);
84 good = true;
85 } on String catch (_) {
86 Expect.isTrue(false);
87 }
88 Expect.isTrue(good);
89 }
90
91 testTypedCatch2() {
92 var good = false;
93 try {
94 throw 'a';
95 } on int catch (_) {
96 Expect.isTrue(false);
97 } on String catch (e) {
98 Expect.isTrue(e == 'a');
99 good = true;
100 }
101 Expect.isTrue(good);
102 }
103
104 testThrowNull() {
105 var good = false;
106 try {
107 throw null;
108 } on NullThrownError catch (_) {
109 good = true;
110 }
111 Expect.isTrue(good);
112 }
113
114 testFinally() {
115 var x = 0;
116 try {
117 throw x++;
118 } catch (_) {
119 x++;
120 } finally {
121 x++;
122 }
123 Expect.isTrue(x == 3);
124 }
125
126 testFinally2() {
127 var x = 0;
128 try {
129 try {
130 throw x++;
131 } catch (_) {
132 x++;
133 } finally {
134 x++;
135 }
136 } finally {
137 x++;
138 }
139 Expect.isTrue(x == 4);
140 }
141
142 testFinally3() {
143 try {
144 var x = 0;
145 try {
146 throw x++;
147 } finally {
148 x++;
149 }
150 Expect.isTrue(x == 2);
151 } catch (_) {}
152 }
153
154 testSuccessfulBody() {
155 var x = 0;
156 try {
157 x++;
158 } finally {
159 x++;
160 }
161 Expect.isTrue(x == 2);
162 }
163
164 testSuccessfulBody2() {
165 var x = 0;
166 try {
167 try {
168 x++;
169 } finally {
170 x++;
171 throw 1;
172 }
173 } on int {}
174 Expect.isTrue(x == 2);
175 }
176
177 main() {
178 testSimpleThrowCatch();
179 testNestedThrowCatch();
180 testNestedThrowCatch2();
181 testSiblingThrowCatch();
182 testTypedCatch();
183 testTypedCatch2();
184 testThrowNull();
185 testFinally();
186 testFinally2();
187 testFinally3();
188 testSuccessfulBody();
189 testSuccessfulBody2();
190 }
OLDNEW
« no previous file with comments | « tests/kernel/unsorted/this_test.dart ('k') | tests/kernel/unsorted/try_context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698