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

Side by Side Diff: tests/kernel/unsorted/try_finally_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 unified diff | Download patch
OLDNEW
(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 testSimpleBreak() {
4 var x = 1;
5 while (true) {
6 try {
7 x++;
8 break;
9 } finally {
10 x++;
11 break;
12 }
13 }
14 return x;
15 }
16
17 testReturnFinally() {
18 try {
19 return 1;
20 } finally {
21 return 42;
22 }
23 }
24
25 testNestedReturnFinally() {
26 try {
27 try {
28 return 1;
29 } finally {
30 return 2;
31 }
32 } finally {
33 return 42;
34 }
35 }
36
37 testReturnInsideLoop() {
38 while (true) {
39 try {
40 print("hello");
41 } finally {
42 return 42;
43 }
44 }
45 }
46
47 testStopContinueInsideLoop() {
48 while (true) {
49 try {
50 continue;
51 } finally {
52 return 42;
53 }
54 }
55 }
56
57 testStopBreakInsideLoop() {
58 var foo = 1;
59 while (true) {
60 try {
61 if (foo == 1) {
62 // 1st iteration we break.
63 break;
64 } else if (foo == 2) {
65 // 2nd iteration we return.
66 return 42;
67 }
68 } finally {
69 // 1st iteration we overrwrite break with continue.
70 if (foo == 1) {
71 foo++;
72 continue;
73 } else {
74 // Let return work
75 }
76 }
77 }
78 return foo;
79 }
80
81 testStopBreakInsideLoop2() {
82 var foo = 1;
83 while (true) {
84 try {
85 if (foo == 1) {
86 // 1st iteration we break.
87 break;
88 } else if (foo == 2) {
89 // 2nd iteration we return.
90 return -1;
91 }
92 } finally {
93 // 1st iteration we overrwrite break with continue.
94 if (foo == 1) {
95 foo++;
96 continue;
97 } else {
98 // 2nd iteration we overrwrite return with break.
99 foo = 42;
100 break;
101 }
102 }
103 }
104 return foo;
105 }
106
107 testStopContinueInsideSwitch() {
108 var foo = 1;
109 switch (foo) {
110 jump5:
111 case 5:
112 return -1;
113
114 case 1:
115 try {
116 continue jump5;
117 } finally {
118 return 42;
119 }
120 }
121 }
122
123 testStopContinueInsideSwitch2() {
124 var foo = 1;
125 switch (foo) {
126 jump5:
127 case 5:
128 return -1;
129
130 jump42:
131 case 5:
132 return 42;
133
134 case 1:
135 try {
136 continue jump5;
137 } finally {
138 continue jump42;
139 }
140 }
141 }
142
143 main() {
144 Expect.isTrue(testSimpleBreak() == 3);
145 Expect.isTrue(testReturnFinally() == 42);
146 Expect.isTrue(testNestedReturnFinally() == 42);
147 Expect.isTrue(testReturnInsideLoop() == 42);
148 Expect.isTrue(testStopContinueInsideLoop() == 42);
149 Expect.isTrue(testStopBreakInsideLoop() == 42);
150 Expect.isTrue(testStopBreakInsideLoop2() == 42);
151 Expect.isTrue(testStopContinueInsideLoop() == 42);
152 Expect.isTrue(testStopContinueInsideSwitch() == 42);
153 Expect.isTrue(testStopContinueInsideSwitch2() == 42);
154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698