OLD | NEW |
---|---|
(Empty) | |
1 import 'expect.dart'; | |
Kevin Millikin (Google)
2016/10/21 09:10:58
Copyright header.
Vyacheslav Egorov (Google)
2016/10/21 13:39:44
Done.
| |
2 | |
3 testSimpleThrowCatch() { | |
4 var x = 1; | |
5 try { | |
6 throw x++; | |
7 } on int catch (e) { | |
8 Expect.isTrue(e == 1); | |
9 Expect.isTrue(x == 2); | |
10 x++; | |
11 } | |
12 Expect.isTrue(x == 3); | |
13 } | |
14 | |
15 testNestedThrowCatch() { | |
16 var x = 1; | |
17 try { | |
18 throw x++; | |
19 } catch (e) { | |
20 Expect.isTrue(e == 1); | |
21 Expect.isTrue(x == 2); | |
22 x++; | |
23 | |
24 try { | |
25 throw x++; | |
26 } catch (e) { | |
27 Expect.isTrue(e == 3); | |
28 Expect.isTrue(x == 4); | |
29 x++; | |
30 } | |
31 } | |
32 Expect.isTrue(x == 5); | |
33 } | |
34 | |
35 testNestedThrowCatch2() { | |
36 var x = 1; | |
37 try { | |
38 try { | |
39 throw x++; | |
40 } catch (e) { | |
41 Expect.isTrue(e == 1); | |
42 Expect.isTrue(x == 2); | |
43 x++; | |
44 } | |
45 throw x++; | |
46 } catch (e) { | |
47 Expect.isTrue(e == 3); | |
48 Expect.isTrue(x == 4); | |
49 x++; | |
50 } | |
51 Expect.isTrue(x == 5); | |
52 } | |
53 | |
54 testSiblingThrowCatch() { | |
55 var x = 1; | |
56 try { | |
57 throw x++; | |
58 } catch (e) { | |
59 Expect.isTrue(e == 1); | |
60 Expect.isTrue(x == 2); | |
61 x++; | |
62 } | |
63 try { | |
64 throw x++; | |
65 } catch (e) { | |
66 Expect.isTrue(e == 3); | |
67 Expect.isTrue(x == 4); | |
68 x++; | |
69 } | |
70 | |
71 Expect.isTrue(x == 5); | |
72 } | |
73 | |
74 testTypedCatch() { | |
75 var good = false; | |
76 try { | |
77 throw 1; | |
78 } on int catch (e) { | |
79 Expect.isTrue(e == 1); | |
80 good = true; | |
81 } on String catch (_) { | |
82 Expect.isTrue(false); | |
83 } | |
84 Expect.isTrue(good); | |
85 } | |
86 | |
87 testTypedCatch2() { | |
88 var good = false; | |
89 try { | |
90 throw 'a'; | |
91 } on int catch (_) { | |
92 Expect.isTrue(false); | |
93 } on String catch (e) { | |
94 Expect.isTrue(e == 'a'); | |
95 good = true; | |
96 } | |
97 Expect.isTrue(good); | |
98 } | |
99 | |
100 testThrowNull() { | |
101 var good = false; | |
102 try { | |
103 throw null; | |
104 } on NullThrownError catch (_) { | |
105 good = true; | |
106 } | |
107 Expect.isTrue(good); | |
108 } | |
109 | |
110 testFinally() { | |
111 var x = 0; | |
112 try { | |
113 throw x++; | |
114 } catch (_) { | |
115 x++; | |
116 } finally { | |
117 x++; | |
118 } | |
119 Expect.isTrue(x == 3); | |
120 } | |
121 | |
122 testFinally2() { | |
123 var x = 0; | |
124 try { | |
125 try { | |
126 throw x++; | |
127 } catch (_) { | |
128 x++; | |
129 } finally { | |
130 x++; | |
131 } | |
132 } finally { | |
133 x++; | |
134 } | |
135 Expect.isTrue(x == 4); | |
136 } | |
137 | |
138 testFinally3() { | |
139 try { | |
140 var x = 0; | |
141 try { | |
142 throw x++; | |
143 } finally { | |
144 x++; | |
145 } | |
146 Expect.isTrue(x == 2); | |
147 } catch (_) {} | |
148 } | |
149 | |
150 testSuccessfulBody() { | |
151 var x = 0; | |
152 try { | |
153 x++; | |
154 } finally { | |
155 x++; | |
156 } | |
157 Expect.isTrue(x == 2); | |
158 } | |
159 | |
160 testSuccessfulBody2() { | |
161 var x = 0; | |
162 try { | |
163 try { | |
164 x++; | |
165 } finally { | |
166 x++; | |
167 throw 1; | |
168 } | |
169 } on int {} | |
170 Expect.isTrue(x == 2); | |
171 } | |
172 | |
173 main() { | |
174 testSimpleThrowCatch(); | |
175 testNestedThrowCatch(); | |
176 testNestedThrowCatch2(); | |
177 testSiblingThrowCatch(); | |
178 testTypedCatch(); | |
179 testTypedCatch2(); | |
180 testThrowNull(); | |
181 testFinally(); | |
182 testFinally2(); | |
183 testFinally3(); | |
184 testSuccessfulBody(); | |
185 testSuccessfulBody2(); | |
186 } | |
OLD | NEW |