OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library trydart.incremental_compilation_update_test; | 5 library trydart.incremental_compilation_update_test; |
6 | 6 |
7 import 'dart:html' hide | 7 import 'dart:html' hide |
8 Element; | 8 Element; |
9 | 9 |
10 import 'dart:async' show | 10 import 'dart:async' show |
(...skipping 26 matching lines...) Expand all Loading... |
37 Element, | 37 Element, |
38 LibraryElement; | 38 LibraryElement; |
39 | 39 |
40 import 'package:compiler/src/dart2jslib.dart' show | 40 import 'package:compiler/src/dart2jslib.dart' show |
41 Compiler; | 41 Compiler; |
42 | 42 |
43 import 'program_result.dart'; | 43 import 'program_result.dart'; |
44 | 44 |
45 const int TIMEOUT = 100; | 45 const int TIMEOUT = 100; |
46 | 46 |
47 const List<List<ProgramResult>> tests = const <List<ProgramResult>>[ | 47 const List<EncodedResult> tests = const <EncodedResult>[ |
48 // Basic hello-world test. | 48 // Basic hello-world test. |
49 const <ProgramResult>[ | 49 const EncodedResult( |
50 const ProgramResult( | 50 const [ |
51 "main() { print('Hello, World!'); }", | 51 "main() { print('Hello, ", |
52 const <String> ['Hello, World!']), | 52 const ["", "Brave New "], |
53 const ProgramResult( | 53 "World!'); }", |
54 "main() { print('Hello, Brave New World!'); }", | 54 ], |
55 const <String> ['Hello, Brave New World!']), | 55 const <ProgramExpectation>[ |
56 ], | 56 const ProgramExpectation( |
| 57 const <String>['Hello, World!']), |
| 58 const ProgramExpectation( |
| 59 const <String>['Hello, Brave New World!']), |
| 60 ]), |
57 | 61 |
58 // Test that the test framework handles more than one update. | 62 // Test that the test framework handles more than one update. |
59 const <ProgramResult>[ | 63 const EncodedResult( |
60 const ProgramResult( | 64 const [ |
61 "main() { print('Hello darkness, my old friend'); }", | 65 "main() { print('", |
62 const <String> ['Hello darkness, my old friend']), | 66 const [ |
63 const ProgramResult( | 67 "Hello darkness, my old friend", |
64 "main() { print('I\\'ve come to talk with you again'); }", | 68 "I\\'ve come to talk with you again", |
65 const <String> ['I\'ve come to talk with you again']), | 69 "Because a vision softly creeping", |
66 const ProgramResult( | 70 ], |
67 "main() { print('Because a vision softly creeping'); }", | 71 "'); }", |
68 const <String> ['Because a vision softly creeping']), | 72 ], |
69 ], | 73 const <ProgramExpectation>[ |
| 74 const ProgramExpectation( |
| 75 const <String>['Hello darkness, my old friend']), |
| 76 const ProgramExpectation( |
| 77 const <String>['I\'ve come to talk with you again']), |
| 78 const ProgramExpectation( |
| 79 const <String>['Because a vision softly creeping']), |
| 80 ]), |
70 | 81 |
71 // Test that that isolate support works. | 82 // Test that that isolate support works. |
72 const <ProgramResult>[ | 83 const EncodedResult( |
73 const ProgramResult( | 84 const [ |
74 "main(arguments) { print('Hello, Isolated World!'); }", | 85 "main(arguments) { print(", |
75 const <String> ['Hello, Isolated World!']), | 86 const [ |
76 const ProgramResult( | 87 "'Hello, Isolated World!'", |
77 "main(arguments) { print(arguments); }", | 88 "arguments" |
78 const <String> ['[]']), | 89 ], |
79 ], | 90 "); }", |
| 91 ], |
| 92 const <ProgramExpectation>[ |
| 93 const ProgramExpectation( |
| 94 const <String>['Hello, Isolated World!']), |
| 95 const ProgramExpectation( |
| 96 const <String>['[]']), |
| 97 ]), |
80 | 98 |
81 // Test that a stored closure changes behavior when updated. | 99 const EncodedResult( |
82 const <ProgramResult>[ | 100 const [ |
83 const ProgramResult( | |
84 r""" | 101 r""" |
| 102 // Test that a stored closure changes behavior when updated. |
| 103 |
85 var closure; | 104 var closure; |
86 | 105 |
87 foo(a, [b = 'b']) { | 106 foo(a, [b = 'b']) { |
| 107 """, |
| 108 const [ |
| 109 r""" |
88 print('$a $b'); | 110 print('$a $b'); |
| 111 """, |
| 112 r""" |
| 113 print('$b $a'); |
| 114 """, |
| 115 ], |
| 116 r""" |
89 } | 117 } |
90 | 118 |
91 main() { | 119 main() { |
92 if (closure == null) { | |
93 print('[closure] is null.'); | |
94 closure = foo; | |
95 } | |
96 closure('a'); | |
97 closure('a', 'c'); | |
98 } | |
99 """, | |
100 const <String> ['[closure] is null.', 'a b', 'a c']), | |
101 const ProgramResult( | |
102 r""" | |
103 var closure; | |
104 | |
105 foo(a, [b = 'b']) { | |
106 print('$b $a'); | |
107 } | |
108 | |
109 main() { | |
110 if (closure == null) { | 120 if (closure == null) { |
111 print('[closure] is null.'); | 121 print('[closure] is null.'); |
112 closure = foo; | 122 closure = foo; |
113 } | 123 } |
114 closure('a'); | 124 closure('a'); |
115 closure('a', 'c'); | 125 closure('a', 'c'); |
116 } | 126 } |
117 """, | 127 """], |
118 const <String> ['b a', 'c a']), | 128 const <ProgramExpectation>[ |
119 ], | 129 const ProgramExpectation( |
| 130 const <String>['[closure] is null.', 'a b', 'a c']), |
| 131 const ProgramExpectation( |
| 132 const <String>['b a', 'c a']), |
| 133 ]), |
120 | 134 |
121 // Test modifying a static method works. | 135 const EncodedResult( |
122 const <ProgramResult>[ | 136 const [ |
123 const ProgramResult( | |
124 """ | 137 """ |
| 138 // Test modifying a static method works. |
| 139 |
125 class C { | 140 class C { |
126 static m() { | 141 static m() { |
127 print('v1'); | 142 """, |
| 143 const [ |
| 144 r""" |
| 145 print('v1'); |
| 146 """, |
| 147 r""" |
| 148 print('v2'); |
| 149 """, |
| 150 ], |
| 151 """ |
128 } | 152 } |
129 } | 153 } |
130 main() { | 154 main() { |
131 C.m(); | 155 C.m(); |
132 } | 156 } |
133 """, | 157 """, |
134 const <String> ['v1']), | 158 ], |
135 const ProgramResult( | 159 const <ProgramExpectation>[ |
| 160 const ProgramExpectation( |
| 161 const <String>['v1']), |
| 162 const ProgramExpectation( |
| 163 const <String>['v2']), |
| 164 ]), |
| 165 |
| 166 const EncodedResult( |
| 167 const [ |
136 """ | 168 """ |
137 class C { | 169 // Test modifying an instance method works. |
138 static m() { | |
139 print('v2'); | |
140 } | |
141 } | |
142 main() { | |
143 C.m(); | |
144 } | |
145 """, | |
146 const <String> ['v2']), | |
147 ], | |
148 | 170 |
149 // Test modifying an instance method works. | |
150 const <ProgramResult>[ | |
151 const ProgramResult( | |
152 """ | |
153 class C { | 171 class C { |
154 m() { | 172 m() { |
155 print('v1'); | 173 """, |
| 174 const [ |
| 175 r""" |
| 176 print('v1'); |
| 177 """, |
| 178 r""" |
| 179 print('v2'); |
| 180 """, |
| 181 ], |
| 182 """ |
156 } | 183 } |
157 } | 184 } |
158 var instance; | 185 var instance; |
159 main() { | |
160 if (instance == null) { | |
161 print('instance is null'); | |
162 instance = new C(); | |
163 } | |
164 instance.m(); | |
165 } | |
166 """, | |
167 const <String> ['instance is null', 'v1']), | |
168 const ProgramResult( | |
169 """ | |
170 class C { | |
171 m() { | |
172 print('v2'); | |
173 } | |
174 } | |
175 var instance; | |
176 main() { | 186 main() { |
177 if (instance == null) { | 187 if (instance == null) { |
178 print('instance is null'); | 188 print('instance is null'); |
179 instance = new C(); | 189 instance = new C(); |
180 } | 190 } |
181 instance.m(); | 191 instance.m(); |
182 } | 192 } |
183 """, | 193 """, |
184 const <String> ['v2']), | |
185 ], | |
186 | 194 |
187 // Test that a stored instance tearoff changes behavior when updated. | 195 ], |
188 const <ProgramResult>[ | 196 const <ProgramExpectation>[ |
189 const ProgramResult( | 197 const ProgramExpectation( |
| 198 const <String>['instance is null', 'v1']), |
| 199 const ProgramExpectation( |
| 200 const <String>['v2']), |
| 201 ]), |
| 202 |
| 203 const EncodedResult( |
| 204 const [ |
190 """ | 205 """ |
| 206 // Test that a stored instance tearoff changes behavior when updated. |
| 207 |
191 class C { | 208 class C { |
192 m() { | 209 m() { |
193 print('v1'); | 210 """, |
| 211 const [ |
| 212 r""" |
| 213 print('v1'); |
| 214 """, |
| 215 r""" |
| 216 print('v2'); |
| 217 """, |
| 218 ], |
| 219 """ |
194 } | 220 } |
195 } | 221 } |
196 var closure; | 222 var closure; |
197 main() { | |
198 if (closure == null) { | |
199 print('closure is null'); | |
200 closure = new C().m; | |
201 } | |
202 closure(); | |
203 } | |
204 """, | |
205 const <String> ['closure is null', 'v1']), | |
206 const ProgramResult( | |
207 """ | |
208 class C { | |
209 m() { | |
210 print('v2'); | |
211 } | |
212 } | |
213 var closure; | |
214 main() { | 223 main() { |
215 if (closure == null) { | 224 if (closure == null) { |
216 print('closure is null'); | 225 print('closure is null'); |
217 closure = new C().m; | 226 closure = new C().m; |
218 } | 227 } |
219 closure(); | 228 closure(); |
220 } | 229 } |
221 """, | 230 """, |
222 const <String> ['v2']), | |
223 ], | |
224 | 231 |
225 // Test that deleting an instance method works. | 232 ], |
226 const <ProgramResult>[ | 233 const <ProgramExpectation>[ |
227 const ProgramResult( | 234 const ProgramExpectation( |
| 235 const <String>['closure is null', 'v1']), |
| 236 const ProgramExpectation( |
| 237 const <String>['v2']), |
| 238 ]), |
| 239 |
| 240 const EncodedResult( |
| 241 const [ |
228 """ | 242 """ |
| 243 // Test that deleting an instance method works. |
| 244 |
229 class C { | 245 class C { |
| 246 """, |
| 247 const [ |
| 248 """ |
230 m() { | 249 m() { |
231 print('v1'); | 250 print('v1'); |
232 } | 251 } |
| 252 """, |
| 253 """ |
| 254 """, |
| 255 ], |
| 256 """ |
233 } | 257 } |
234 var instance; | 258 var instance; |
235 main() { | 259 main() { |
236 if (instance == null) { | |
237 print('instance is null'); | |
238 instance = new C(); | |
239 } | |
240 try { | |
241 instance.m(); | |
242 } catch (e) { | |
243 print('threw'); | |
244 } | |
245 } | |
246 """, | |
247 const <String> ['instance is null', 'v1']), | |
248 const ProgramResult( | |
249 """ | |
250 class C { | |
251 } | |
252 var instance; | |
253 main() { | |
254 if (instance == null) { | 260 if (instance == null) { |
255 print('instance is null'); | 261 print('instance is null'); |
256 instance = new C(); | 262 instance = new C(); |
257 } | 263 } |
258 try { | 264 try { |
259 instance.m(); | 265 instance.m(); |
260 } catch (e) { | 266 } catch (e) { |
261 print('threw'); | 267 print('threw'); |
262 } | 268 } |
263 } | 269 } |
264 """, | 270 """, |
265 const <String> ['threw']), | 271 ], |
266 ], | 272 const <ProgramExpectation>[ |
| 273 const ProgramExpectation( |
| 274 const <String>['instance is null', 'v1']), |
| 275 const ProgramExpectation( |
| 276 const <String>['threw']), |
| 277 ]), |
267 | 278 |
268 // Test that deleting an instance method works, even when accessed through | 279 const EncodedResult( |
269 // super. | 280 const [ |
270 const <ProgramResult>[ | |
271 const ProgramResult( | |
272 """ | 281 """ |
| 282 // Test that deleting an instance method works, even when accessed through |
| 283 // super. |
| 284 |
273 class A { | 285 class A { |
274 m() { | 286 m() { |
275 print('v2'); | 287 print('v2'); |
276 } | 288 } |
277 } | 289 } |
278 class B extends A { | 290 class B extends A { |
| 291 """, |
| 292 const [ |
| 293 """ |
279 m() { | 294 m() { |
280 print('v1'); | 295 print('v1'); |
281 } | 296 } |
| 297 """, |
| 298 """ |
| 299 """, |
| 300 ], |
| 301 """ |
282 } | 302 } |
283 class C extends B { | 303 class C extends B { |
284 m() { | 304 m() { |
285 super.m(); | |
286 } | |
287 } | |
288 var instance; | |
289 main() { | |
290 if (instance == null) { | |
291 print('instance is null'); | |
292 instance = new C(); | |
293 } | |
294 instance.m(); | |
295 } | |
296 """, | |
297 const <String> ['instance is null', 'v1']), | |
298 const ProgramResult( | |
299 """ | |
300 class A { | |
301 m() { | |
302 print('v2'); | |
303 } | |
304 } | |
305 class B extends A { | |
306 } | |
307 class C extends B { | |
308 m() { | |
309 super.m(); | 305 super.m(); |
310 } | 306 } |
311 } | 307 } |
312 var instance; | 308 var instance; |
313 main() { | 309 main() { |
314 if (instance == null) { | 310 if (instance == null) { |
315 print('instance is null'); | 311 print('instance is null'); |
316 instance = new C(); | 312 instance = new C(); |
317 } | 313 } |
318 instance.m(); | 314 instance.m(); |
319 } | 315 } |
320 """, | 316 """, |
321 const <String> ['v2']), | |
322 ], | |
323 | 317 |
324 // Test that deleting a top-level method works. | 318 ], |
325 const <ProgramResult>[ | 319 const <ProgramExpectation>[ |
326 const ProgramResult( | 320 const ProgramExpectation( |
| 321 const <String>['instance is null', 'v1']), |
| 322 const ProgramExpectation( |
| 323 const <String>['v2']), |
| 324 ]), |
| 325 |
| 326 const EncodedResult( |
| 327 const [ |
327 """ | 328 """ |
| 329 // Test that deleting a top-level method works. |
| 330 |
| 331 """, |
| 332 const [ |
| 333 """ |
328 toplevel() { | 334 toplevel() { |
329 print('v1'); | 335 print('v1'); |
330 } | 336 } |
331 class C { | |
332 m() { | |
333 try { | |
334 toplevel(); | |
335 } catch (e) { | |
336 print('threw'); | |
337 } | |
338 } | |
339 } | |
340 var instance; | |
341 main() { | |
342 if (instance == null) { | |
343 print('instance is null'); | |
344 instance = new C(); | |
345 } | |
346 instance.m(); | |
347 } | |
348 """, | 337 """, |
349 const <String> ['instance is null', 'v1']), | 338 """ |
350 const ProgramResult( | 339 """, |
| 340 ], |
351 """ | 341 """ |
352 class C { | 342 class C { |
353 m() { | 343 m() { |
354 try { | 344 try { |
355 toplevel(); | 345 toplevel(); |
356 } catch (e) { | 346 } catch (e) { |
357 print('threw'); | 347 print('threw'); |
358 } | 348 } |
359 } | 349 } |
360 } | 350 } |
361 var instance; | 351 var instance; |
362 main() { | 352 main() { |
363 if (instance == null) { | 353 if (instance == null) { |
364 print('instance is null'); | 354 print('instance is null'); |
365 instance = new C(); | 355 instance = new C(); |
366 } | 356 } |
367 instance.m(); | 357 instance.m(); |
368 } | 358 } |
369 """, | 359 """, |
370 const <String> ['threw']), | 360 ], |
371 ], | 361 const <ProgramExpectation>[ |
| 362 const ProgramExpectation( |
| 363 const <String>['instance is null', 'v1']), |
| 364 const ProgramExpectation( |
| 365 const <String>['threw']), |
| 366 ]), |
372 | 367 |
373 // Test that deleting a static method works. | 368 const EncodedResult( |
374 const <ProgramResult>[ | 369 const [ |
375 const ProgramResult( | |
376 """ | 370 """ |
| 371 // Test that deleting a static method works. |
| 372 |
377 class B { | 373 class B { |
| 374 """, |
| 375 const [ |
| 376 """ |
378 static staticMethod() { | 377 static staticMethod() { |
379 print('v1'); | 378 print('v1'); |
380 } | 379 } |
| 380 """, |
| 381 """ |
| 382 """, |
| 383 ], |
| 384 """ |
381 } | 385 } |
382 class C { | 386 class C { |
383 m() { | 387 m() { |
384 try { | |
385 B.staticMethod(); | |
386 } catch (e) { | |
387 print('threw'); | |
388 } | |
389 try { | |
390 // Ensure that noSuchMethod support is compiled. This test is not about | |
391 // adding new classes. | |
392 B.missingMethod(); | |
393 print('bad'); | |
394 } catch (e) { | |
395 } | |
396 } | |
397 } | |
398 var instance; | |
399 main() { | |
400 if (instance == null) { | |
401 print('instance is null'); | |
402 instance = new C(); | |
403 } | |
404 instance.m(); | |
405 } | |
406 """, | |
407 const <String> ['instance is null', 'v1']), | |
408 const ProgramResult( | |
409 """ | |
410 class B { | |
411 } | |
412 class C { | |
413 m() { | |
414 try { | 388 try { |
415 B.staticMethod(); | 389 B.staticMethod(); |
416 } catch (e) { | 390 } catch (e) { |
417 print('threw'); | 391 print('threw'); |
418 } | 392 } |
419 try { | 393 try { |
420 // Ensure that noSuchMethod support is compiled. This test is not about | 394 // Ensure that noSuchMethod support is compiled. This test is not about |
421 // adding new classes. | 395 // adding new classes. |
422 B.missingMethod(); | 396 B.missingMethod(); |
423 print('bad'); | 397 print('bad'); |
424 } catch (e) { | 398 } catch (e) { |
425 } | 399 } |
426 } | 400 } |
427 } | 401 } |
428 var instance; | 402 var instance; |
429 main() { | 403 main() { |
430 if (instance == null) { | 404 if (instance == null) { |
431 print('instance is null'); | 405 print('instance is null'); |
432 instance = new C(); | 406 instance = new C(); |
433 } | 407 } |
434 instance.m(); | 408 instance.m(); |
435 } | 409 } |
436 """, | 410 """, |
437 const <String> ['threw']), | 411 ], |
438 ], | 412 const <ProgramExpectation>[ |
| 413 const ProgramExpectation( |
| 414 const <String>['instance is null', 'v1']), |
| 415 const ProgramExpectation( |
| 416 const <String>['threw']), |
| 417 ]), |
439 | 418 |
440 // Test that a newly instantiated class is handled. | 419 const EncodedResult( |
441 const <ProgramResult>[ | 420 const [ |
442 const ProgramResult( | |
443 """ | 421 """ |
| 422 // Test that a newly instantiated class is handled. |
| 423 |
444 class A { | 424 class A { |
445 m() { | 425 m() { |
446 print('Called A.m'); | 426 print('Called A.m'); |
447 } | |
448 } | |
449 | |
450 class B { | |
451 m() { | |
452 print('Called B.m'); | |
453 } | |
454 } | |
455 | |
456 var instance; | |
457 main() { | |
458 if (instance == null) { | |
459 print('instance is null'); | |
460 instance = new A(); | |
461 } | |
462 instance.m(); | |
463 } | |
464 """, | |
465 const <String>['instance is null', 'Called A.m']), | |
466 const ProgramResult( | |
467 """ | |
468 class A { | |
469 m() { | |
470 print('Called A.m'); | |
471 } | 427 } |
472 } | 428 } |
473 | 429 |
474 class B { | 430 class B { |
475 m() { | 431 m() { |
476 print('Called B.m'); | 432 print('Called B.m'); |
477 } | 433 } |
478 } | 434 } |
479 | 435 |
480 var instance; | 436 var instance; |
481 main() { | 437 main() { |
482 if (instance == null) { | 438 if (instance == null) { |
483 print('instance is null'); | 439 print('instance is null'); |
484 instance = new A(); | 440 instance = new A(); |
| 441 """, |
| 442 const [ |
| 443 """ |
| 444 """, |
| 445 """ |
485 } else { | 446 } else { |
486 instance = new B(); | 447 instance = new B(); |
| 448 """, |
| 449 ], |
| 450 """ |
487 } | 451 } |
488 instance.m(); | 452 instance.m(); |
489 } | 453 } |
490 """, | 454 """, |
491 const <String>['Called B.m']), | |
492 ], | |
493 | 455 |
494 // Test that source maps don't throw exceptions. | 456 ], |
495 const <ProgramResult>[ | 457 const <ProgramExpectation>[ |
496 const ProgramResult( | 458 const ProgramExpectation( |
| 459 const <String>['instance is null', 'Called A.m']), |
| 460 const ProgramExpectation( |
| 461 const <String>['Called B.m']), |
| 462 ]), |
| 463 |
| 464 const EncodedResult( |
| 465 const [ |
497 """ | 466 """ |
| 467 // Test that source maps don't throw exceptions. |
| 468 |
498 main() { | 469 main() { |
499 print('a'); | 470 print('a'); |
| 471 """, |
| 472 const [ |
| 473 """ |
| 474 """, |
| 475 """ |
| 476 print('b'); |
| 477 print('c'); |
| 478 """, |
| 479 ], |
| 480 """ |
500 } | 481 } |
501 """, | 482 """, |
502 const <String>['a']), | 483 ], |
| 484 const <ProgramExpectation>[ |
| 485 const ProgramExpectation( |
| 486 const <String>['a']), |
| 487 const ProgramExpectation( |
| 488 const <String>['a', 'b', 'c']), |
| 489 ]), |
503 | 490 |
504 const ProgramResult( | 491 const EncodedResult( |
505 """ | 492 const [ |
506 main() { | 493 r""" |
507 print('a'); | 494 // Test that a newly instantiated class is handled. |
508 print('b'); | |
509 print('c'); | |
510 } | |
511 """, | |
512 const <String>['a', 'b', 'c']), | |
513 ], | |
514 | 495 |
515 // Test that a newly instantiated class is handled. | |
516 const <ProgramResult>[ | |
517 const ProgramResult( | |
518 r""" | |
519 class A { | 496 class A { |
520 get name => 'A.m'; | 497 get name => 'A.m'; |
521 | 498 |
522 m() { | |
523 print('Called $name'); | |
524 } | |
525 } | |
526 | |
527 class B extends A { | |
528 get name => 'B.m'; | |
529 } | |
530 | |
531 var instance; | |
532 main() { | |
533 if (instance == null) { | |
534 print('instance is null'); | |
535 instance = new A(); | |
536 } | |
537 instance.m(); | |
538 } | |
539 """, | |
540 const <String>['instance is null', 'Called A.m']), | |
541 const ProgramResult( | |
542 r""" | |
543 class A { | |
544 get name => 'A.m'; | |
545 | |
546 m() { | 499 m() { |
547 print('Called $name'); | 500 print('Called $name'); |
548 } | 501 } |
549 } | 502 } |
550 | 503 |
551 class B extends A { | 504 class B extends A { |
552 get name => 'B.m'; | 505 get name => 'B.m'; |
553 } | 506 } |
554 | 507 |
555 var instance; | 508 var instance; |
556 main() { | 509 main() { |
557 if (instance == null) { | 510 if (instance == null) { |
558 print('instance is null'); | 511 print('instance is null'); |
559 instance = new A(); | 512 instance = new A(); |
| 513 """, |
| 514 const [ |
| 515 r""" |
| 516 """, |
| 517 r""" |
560 } else { | 518 } else { |
561 instance = new B(); | 519 instance = new B(); |
| 520 """, |
| 521 ], |
| 522 r""" |
562 } | 523 } |
563 instance.m(); | 524 instance.m(); |
564 } | 525 } |
565 """, | 526 """, |
566 const <String>['Called B.m']), | 527 ], |
567 ], | 528 const <ProgramExpectation>[ |
| 529 const ProgramExpectation( |
| 530 const <String>['instance is null', 'Called A.m']), |
| 531 const ProgramExpectation( |
| 532 const <String>['Called B.m']), |
| 533 ]), |
568 | 534 |
569 // Test that fields of a newly instantiated class are handled. | 535 const EncodedResult( |
570 const <ProgramResult>[ | 536 const [ |
571 const ProgramResult( | |
572 r""" | 537 r""" |
| 538 // Test that fields of a newly instantiated class are handled. |
| 539 |
573 class A { | 540 class A { |
574 var x; | 541 var x; |
575 A(this.x); | 542 A(this.x); |
576 } | 543 } |
577 var instance; | 544 var instance; |
578 foo() { | 545 foo() { |
579 if (instance != null) { | 546 if (instance != null) { |
580 print(instance.x); | 547 print(instance.x); |
581 } else { | 548 } else { |
582 print('v1'); | 549 print('v1'); |
583 } | 550 } |
584 } | 551 } |
585 main() { | 552 main() { |
| 553 """, |
| 554 const [ |
| 555 r""" |
| 556 """, |
| 557 r""" |
| 558 instance = new A('v2'); |
| 559 """, |
| 560 ], |
| 561 r""" |
586 foo(); | 562 foo(); |
587 } | 563 } |
588 """, | 564 """, |
589 const <String>['v1']), | 565 ], |
590 const ProgramResult( | 566 const <ProgramExpectation>[ |
| 567 const ProgramExpectation( |
| 568 const <String>['v1']), |
| 569 const ProgramExpectation( |
| 570 const <String>['v2']), |
| 571 ]), |
| 572 |
| 573 const EncodedResult( |
| 574 const [ |
591 r""" | 575 r""" |
592 class A { | 576 // Test that top-level functions can be added. |
593 var x; | 577 |
594 A(this.x); | 578 """, |
595 } | 579 const [ |
596 var instance; | 580 "", |
| 581 r""" |
597 foo() { | 582 foo() { |
598 if (instance != null) { | 583 print('v2'); |
599 print(instance.x); | |
600 } else { | |
601 print('v1'); | |
602 } | |
603 } | |
604 main() { | |
605 instance = new A('v2'); | |
606 foo(); | |
607 } | 584 } |
608 """, | 585 """, |
609 const <String>['v2']), | 586 ], |
610 ], | |
611 | |
612 // Test that top-level functions can be added. | |
613 const <ProgramResult>[ | |
614 const ProgramResult( | |
615 r""" | 587 r""" |
616 main() { | 588 main() { |
617 try { | 589 try { |
618 foo(); | 590 foo(); |
619 } catch(e) { | |
620 print('threw'); | |
621 } | |
622 } | |
623 """, | |
624 const <String>['threw']), | |
625 const ProgramResult( | |
626 r""" | |
627 foo() { | |
628 print('v2'); | |
629 } | |
630 | |
631 main() { | |
632 try { | |
633 foo(); | |
634 } catch(e) { | 591 } catch(e) { |
635 print('threw'); | 592 print('threw'); |
636 } | 593 } |
637 } | 594 } |
638 """, | 595 """, |
639 const <String>['v2']), | 596 ], |
640 ], | 597 const <ProgramExpectation>[ |
| 598 const ProgramExpectation( |
| 599 const <String>['threw']), |
| 600 const ProgramExpectation( |
| 601 const <String>['v2']), |
| 602 ]), |
641 | 603 |
642 // Test that static methods can be added. | 604 const EncodedResult( |
643 const <ProgramResult>[ | 605 const [ |
644 const ProgramResult( | |
645 r""" | 606 r""" |
| 607 // Test that static methods can be added. |
| 608 |
646 class C { | 609 class C { |
| 610 """, |
| 611 const [ |
| 612 "", |
| 613 r""" |
| 614 static foo() { |
| 615 print('v2'); |
| 616 } |
| 617 """, |
| 618 ], |
| 619 r""" |
647 } | 620 } |
648 | 621 |
649 main() { | 622 main() { |
650 try { | |
651 C.foo(); | |
652 } catch(e) { | |
653 print('threw'); | |
654 } | |
655 } | |
656 """, | |
657 const <String>['threw']), | |
658 const ProgramResult( | |
659 r""" | |
660 class C { | |
661 static foo() { | |
662 print('v2'); | |
663 } | |
664 } | |
665 | |
666 main() { | |
667 try { | 623 try { |
668 C.foo(); | 624 C.foo(); |
669 } catch(e) { | 625 } catch(e) { |
670 print('threw'); | 626 print('threw'); |
671 } | 627 } |
672 } | 628 } |
673 """, | 629 """, |
674 const <String>['v2']), | |
675 ], | |
676 | 630 |
677 // Test that instance methods can be added. | 631 ], |
678 const <ProgramResult>[ | 632 const <ProgramExpectation>[ |
679 const ProgramResult( | 633 const ProgramExpectation( |
| 634 const <String>['threw']), |
| 635 const ProgramExpectation( |
| 636 const <String>['v2']), |
| 637 ]), |
| 638 |
| 639 const EncodedResult( |
| 640 const [ |
680 r""" | 641 r""" |
| 642 // Test that instance methods can be added. |
| 643 |
681 class C { | 644 class C { |
| 645 """, |
| 646 const [ |
| 647 "", |
| 648 r""" |
| 649 foo() { |
| 650 print('v2'); |
| 651 } |
| 652 """, |
| 653 ], |
| 654 r""" |
682 } | 655 } |
683 | 656 |
684 var instance; | 657 var instance; |
685 | |
686 main() { | |
687 if (instance == null) { | |
688 print('instance is null'); | |
689 instance = new C(); | |
690 } | |
691 | |
692 try { | |
693 instance.foo(); | |
694 } catch(e) { | |
695 print('threw'); | |
696 } | |
697 } | |
698 """, | |
699 const <String>['instance is null', 'threw']), | |
700 const ProgramResult( | |
701 r""" | |
702 class C { | |
703 foo() { | |
704 print('v2'); | |
705 } | |
706 } | |
707 | |
708 var instance; | |
709 | 658 |
710 main() { | 659 main() { |
711 if (instance == null) { | 660 if (instance == null) { |
712 print('instance is null'); | 661 print('instance is null'); |
713 instance = new C(); | 662 instance = new C(); |
714 } | 663 } |
715 | 664 |
716 try { | 665 try { |
717 instance.foo(); | 666 instance.foo(); |
718 } catch(e) { | 667 } catch(e) { |
719 print('threw'); | 668 print('threw'); |
720 } | 669 } |
721 } | 670 } |
722 """, | 671 """, |
723 const <String>['v2']), | 672 ], |
724 ], | 673 const <ProgramExpectation>[ |
| 674 const ProgramExpectation( |
| 675 const <String>['instance is null', 'threw']), |
| 676 const ProgramExpectation( |
| 677 const <String>['v2']), |
| 678 ]), |
725 | 679 |
726 // Test that top-level functions can have signature changed. | 680 const EncodedResult( |
727 const <ProgramResult>[ | 681 const [ |
728 const ProgramResult( | |
729 r""" | 682 r""" |
| 683 // Test that top-level functions can have signature changed. |
| 684 |
| 685 """, |
| 686 const [ |
| 687 r""" |
730 foo() { | 688 foo() { |
731 print('v1'); | 689 print('v1'); |
| 690 """, |
| 691 r""" |
| 692 void foo() { |
| 693 print('v2'); |
| 694 """, |
| 695 ], |
| 696 r""" |
732 } | 697 } |
733 | 698 |
734 main() { | 699 main() { |
735 foo(); | 700 foo(); |
736 } | 701 } |
737 """, | 702 """, |
738 const <String>['v1']), | 703 ], |
739 const ProgramResult( | 704 const <ProgramExpectation>[ |
| 705 const ProgramExpectation( |
| 706 const <String>['v1']), |
| 707 const ProgramExpectation( |
| 708 const <String>['v2']), |
| 709 ]), |
| 710 |
| 711 const EncodedResult( |
| 712 const [ |
740 r""" | 713 r""" |
741 void foo() { | 714 // Test that static methods can have signature changed. |
742 print('v2'); | |
743 } | |
744 | 715 |
745 main() { | 716 class C { |
746 foo(); | |
747 } | |
748 """, | 717 """, |
749 const <String>['v2']), | 718 const [ |
750 ], | 719 r""" |
751 | |
752 // Test that static methods can have signature changed. | |
753 const <ProgramResult>[ | |
754 const ProgramResult( | |
755 r""" | |
756 class C { | |
757 static foo() { | 720 static foo() { |
758 print('v1'); | 721 print('v1'); |
| 722 """, |
| 723 r""" |
| 724 static void foo() { |
| 725 print('v2'); |
| 726 """, |
| 727 ], |
| 728 r""" |
759 } | 729 } |
760 } | 730 } |
761 | 731 |
762 main() { | |
763 C.foo(); | |
764 } | |
765 """, | |
766 const <String>['v1']), | |
767 const ProgramResult( | |
768 r""" | |
769 class C { | |
770 static void foo() { | |
771 print('v2'); | |
772 } | |
773 } | |
774 | |
775 main() { | 732 main() { |
776 C.foo(); | 733 C.foo(); |
777 } | 734 } |
778 """, | 735 """, |
779 const <String>['v2']), | 736 ], |
780 ], | 737 const <ProgramExpectation>[ |
| 738 const ProgramExpectation( |
| 739 const <String>['v1']), |
| 740 const ProgramExpectation( |
| 741 const <String>['v2']), |
| 742 ]), |
781 | 743 |
782 // Test that instance methods can have signature changed. | 744 const EncodedResult( |
783 const <ProgramResult>[ | 745 const [ |
784 const ProgramResult( | |
785 r""" | 746 r""" |
| 747 // Test that instance methods can have signature changed. |
| 748 |
786 class C { | 749 class C { |
| 750 """, |
| 751 const [ |
| 752 r""" |
787 foo() { | 753 foo() { |
788 print('v1'); | 754 print('v1'); |
| 755 """, |
| 756 r""" |
| 757 void foo() { |
| 758 print('v2'); |
| 759 """, |
| 760 ], |
| 761 r""" |
789 } | 762 } |
790 } | 763 } |
791 | 764 |
792 var instance; | |
793 | |
794 main() { | |
795 if (instance == null) { | |
796 print('instance is null'); | |
797 instance = new C(); | |
798 } | |
799 | |
800 instance.foo(); | |
801 } | |
802 """, | |
803 const <String>['instance is null', 'v1']), | |
804 const ProgramResult( | |
805 r""" | |
806 class C { | |
807 void foo() { | |
808 print('v2'); | |
809 } | |
810 } | |
811 | |
812 var instance; | 765 var instance; |
813 | 766 |
814 main() { | 767 main() { |
815 if (instance == null) { | 768 if (instance == null) { |
816 print('instance is null'); | 769 print('instance is null'); |
817 instance = new C(); | 770 instance = new C(); |
818 } | 771 } |
819 | 772 |
820 instance.foo(); | 773 instance.foo(); |
821 } | 774 } |
822 """, | 775 """, |
823 const <String>['v2']), | 776 ], |
824 ], | 777 const <ProgramExpectation>[ |
| 778 const ProgramExpectation( |
| 779 const <String>['instance is null', 'v1']), |
| 780 const ProgramExpectation( |
| 781 const <String>['v2']), |
| 782 ]), |
825 | 783 |
826 // Test that adding a class is supported. | 784 const EncodedResult( |
827 const <ProgramResult>[ | 785 const [ |
828 const ProgramResult( | |
829 r""" | 786 r""" |
830 main() { | 787 // Test that adding a class is supported. |
831 print('v1'); | 788 |
832 } | |
833 """, | 789 """, |
834 const <String>['v1']), | 790 const [ |
835 const ProgramResult( | 791 "", |
836 r""" | 792 r""" |
837 class C { | 793 class C { |
838 void foo() { | 794 void foo() { |
839 print('v2'); | 795 print('v2'); |
840 } | 796 } |
841 } | 797 } |
842 | 798 """, |
| 799 ], |
| 800 r""" |
843 main() { | 801 main() { |
| 802 """, |
| 803 const [ |
| 804 r""" |
| 805 print('v1'); |
| 806 """, |
| 807 r""" |
844 new C().foo(); | 808 new C().foo(); |
| 809 """, |
| 810 ], |
| 811 r""" |
845 } | 812 } |
846 """, | 813 """, |
847 const <String>['v2']), | 814 ], |
848 ], | 815 const <ProgramExpectation>[ |
| 816 const ProgramExpectation( |
| 817 const <String>['v1']), |
| 818 const ProgramExpectation( |
| 819 const <String>['v2']), |
| 820 ]), |
849 | 821 |
850 // Test that removing a class is supported, using constructor. | 822 const EncodedResult( |
851 const <ProgramResult>[ | 823 const [ |
852 const ProgramResult( | |
853 r""" | 824 r""" |
| 825 // Test that removing a class is supported, using constructor. |
| 826 |
| 827 """, |
| 828 const [ |
| 829 r""" |
854 class C { | 830 class C { |
855 } | 831 } |
856 | |
857 main() { | |
858 try { | |
859 new C(); | |
860 print('v1'); | |
861 } catch (e) { | |
862 print('v2'); | |
863 } | |
864 } | |
865 """, | 832 """, |
866 const <String>['v1']), | 833 "" |
867 const ProgramResult( | 834 ], |
868 r""" | 835 r""" |
869 main() { | 836 main() { |
870 try { | 837 try { |
871 new C(); | 838 new C(); |
872 print('v1'); | 839 print('v1'); |
873 } catch (e) { | 840 } catch (e) { |
874 print('v2'); | 841 print('v2'); |
875 } | 842 } |
876 } | 843 } |
877 """, | 844 """, |
878 const <String>['v2']), | 845 ], |
879 ], | 846 const <ProgramExpectation>[ |
| 847 const ProgramExpectation( |
| 848 const <String>['v1']), |
| 849 const ProgramExpectation( |
| 850 const <String>['v2']), |
| 851 ]), |
880 | 852 |
881 // Test that removing a class is supported, using a static method. | 853 const EncodedResult( |
882 const <ProgramResult>[ | 854 const [ |
883 const ProgramResult( | |
884 r""" | 855 r""" |
| 856 // Test that removing a class is supported, using a static method. |
| 857 |
| 858 """, |
| 859 const [ |
| 860 r""" |
885 class C { | 861 class C { |
886 static m() { | 862 static m() { |
887 print('v1'); | 863 print('v1'); |
888 } | 864 } |
889 } | 865 } |
890 | |
891 main() { | |
892 try { | |
893 C.m(); | |
894 } catch (e) { | |
895 print('v2'); | |
896 } | |
897 } | |
898 """, | 866 """, |
899 const <String>['v1']), | 867 "", |
900 const ProgramResult( | 868 ], |
901 r""" | 869 r""" |
902 main() { | 870 main() { |
903 try { | 871 try { |
904 C.m(); | 872 C.m(); |
905 } catch (e) { | 873 } catch (e) { |
906 print('v2'); | 874 print('v2'); |
907 } | 875 } |
908 } | 876 } |
909 """, | 877 """, |
910 const <String>['v2']), | 878 ], |
911 ], | 879 const <ProgramExpectation>[ |
| 880 const ProgramExpectation( |
| 881 const <String>['v1']), |
| 882 const ProgramExpectation( |
| 883 const <String>['v2']), |
| 884 ]), |
912 | 885 |
913 // Test that changing the supertype of a class. | 886 const EncodedResult( |
914 const <ProgramResult>[ | 887 const [ |
915 const ProgramResult( | |
916 r""" | 888 r""" |
| 889 // Test that changing the supertype of a class. |
| 890 |
917 class A { | 891 class A { |
918 m() { | 892 m() { |
919 print('v2'); | 893 print('v2'); |
920 } | 894 } |
921 } | 895 } |
922 class B extends A { | 896 class B extends A { |
923 m() { | 897 m() { |
924 print('v1'); | 898 print('v1'); |
925 } | 899 } |
926 } | 900 } |
| 901 """, |
| 902 const [ |
| 903 r""" |
927 class C extends B { | 904 class C extends B { |
| 905 """, |
| 906 r""" |
| 907 class C extends A { |
| 908 """, |
| 909 ], |
| 910 r""" |
928 m() { | 911 m() { |
929 super.m(); | 912 super.m(); |
930 } | 913 } |
931 } | |
932 | |
933 var instance; | |
934 | |
935 main() { | |
936 if (instance == null) { | |
937 print('instance is null'); | |
938 instance = new C(); | |
939 } | |
940 instance.m(); | |
941 } | |
942 """, | |
943 const <String>['instance is null', 'v1']), | |
944 const ProgramResult( | |
945 r""" | |
946 class A { | |
947 m() { | |
948 print('v2'); | |
949 } | |
950 } | |
951 class B extends A { | |
952 m() { | |
953 print('v1'); | |
954 } | |
955 } | |
956 class C extends A { | |
957 m() { | |
958 super.m(); | |
959 } | |
960 } | 914 } |
961 | 915 |
962 var instance; | 916 var instance; |
963 | 917 |
964 main() { | 918 main() { |
965 if (instance == null) { | 919 if (instance == null) { |
966 print('instance is null'); | 920 print('instance is null'); |
967 instance = new C(); | 921 instance = new C(); |
968 } | 922 } |
969 instance.m(); | 923 instance.m(); |
970 } | 924 } |
971 """, | 925 """, |
972 const <String>['v2']), | 926 ], |
973 ], | 927 const <ProgramExpectation>[ |
| 928 const ProgramExpectation( |
| 929 const <String>['instance is null', 'v1']), |
| 930 const ProgramExpectation( |
| 931 const <String>['v2']), |
| 932 ]), |
974 | 933 |
975 // Test adding a field to a class works. | 934 const EncodedResult( |
976 const <ProgramResult>[ | 935 const [ |
977 const ProgramResult( | |
978 r""" | 936 r""" |
| 937 // Test adding a field to a class works. |
| 938 |
979 class A { | 939 class A { |
| 940 """, |
| 941 const [ |
| 942 "", |
| 943 r""" |
| 944 var x; |
| 945 """, |
| 946 ], |
| 947 r""" |
980 } | 948 } |
981 | 949 |
982 var instance; | 950 var instance; |
983 | |
984 main() { | |
985 if (instance == null) { | |
986 print('instance is null'); | |
987 instance = new A(); | |
988 } | |
989 try { | |
990 instance.x = 'v2'; | |
991 } catch(e) { | |
992 print('setter threw'); | |
993 } | |
994 try { | |
995 print(instance.x); | |
996 } catch (e) { | |
997 print('getter threw'); | |
998 } | |
999 } | |
1000 """, | |
1001 const <String>['instance is null', 'setter threw', 'getter threw']), | |
1002 const ProgramResult( | |
1003 r""" | |
1004 class A { | |
1005 var x; | |
1006 } | |
1007 | |
1008 var instance; | |
1009 | 951 |
1010 main() { | 952 main() { |
1011 if (instance == null) { | 953 if (instance == null) { |
1012 print('instance is null'); | 954 print('instance is null'); |
1013 instance = new A(); | 955 instance = new A(); |
1014 } | 956 } |
1015 try { | 957 try { |
1016 instance.x = 'v2'; | 958 instance.x = 'v2'; |
1017 } catch(e) { | 959 } catch(e) { |
1018 print('setter threw'); | 960 print('setter threw'); |
1019 } | 961 } |
1020 try { | 962 try { |
1021 print(instance.x); | 963 print(instance.x); |
1022 } catch (e) { | 964 } catch (e) { |
1023 print('getter threw'); | 965 print('getter threw'); |
1024 } | 966 } |
1025 } | 967 } |
1026 """, | 968 """, |
1027 const <String>['v2']), | 969 ], |
1028 ], | 970 const <ProgramExpectation>[ |
| 971 const ProgramExpectation( |
| 972 const <String>['instance is null', 'setter threw', 'getter threw
']), |
| 973 const ProgramExpectation( |
| 974 const <String>['v2']), |
| 975 ]), |
1029 | 976 |
1030 // Test removing a field from a class works. | 977 const EncodedResult( |
1031 const <ProgramResult>[ | 978 const [ |
1032 const ProgramResult( | |
1033 r""" | 979 r""" |
| 980 // Test removing a field from a class works. |
| 981 |
1034 class A { | 982 class A { |
| 983 """, |
| 984 const [ |
| 985 r""" |
1035 var x; | 986 var x; |
| 987 """, |
| 988 "", |
| 989 ], |
| 990 r""" |
1036 } | 991 } |
1037 | 992 |
1038 var instance; | 993 var instance; |
1039 | |
1040 main() { | |
1041 if (instance == null) { | |
1042 print('instance is null'); | |
1043 instance = new A(); | |
1044 } | |
1045 try { | |
1046 instance.x = 'v1'; | |
1047 } catch(e) { | |
1048 print('setter threw'); | |
1049 } | |
1050 try { | |
1051 print(instance.x); | |
1052 } catch (e) { | |
1053 print('getter threw'); | |
1054 } | |
1055 } | |
1056 """, | |
1057 const <String>['instance is null', 'v1']), | |
1058 const ProgramResult( | |
1059 r""" | |
1060 class A { | |
1061 } | |
1062 | |
1063 var instance; | |
1064 | 994 |
1065 main() { | 995 main() { |
1066 if (instance == null) { | 996 if (instance == null) { |
1067 print('instance is null'); | 997 print('instance is null'); |
1068 instance = new A(); | 998 instance = new A(); |
1069 } | 999 } |
1070 try { | 1000 try { |
1071 instance.x = 'v1'; | 1001 instance.x = 'v1'; |
1072 } catch(e) { | 1002 } catch(e) { |
1073 print('setter threw'); | 1003 print('setter threw'); |
1074 } | 1004 } |
1075 try { | 1005 try { |
1076 print(instance.x); | 1006 print(instance.x); |
1077 } catch (e) { | 1007 } catch (e) { |
1078 print('getter threw'); | 1008 print('getter threw'); |
1079 } | 1009 } |
1080 } | 1010 } |
1081 """, | 1011 """, |
1082 const <String>['setter threw', 'getter threw']), | 1012 ], |
1083 ], | 1013 const <ProgramExpectation>[ |
| 1014 const ProgramExpectation( |
| 1015 const <String>['instance is null', 'v1']), |
| 1016 const ProgramExpectation( |
| 1017 const <String>['setter threw', 'getter threw']), |
| 1018 ]), |
1084 | 1019 |
1085 // Test that named arguments can be called. | 1020 const EncodedResult( |
1086 const <ProgramResult>[ | 1021 const [ |
1087 const ProgramResult( | |
1088 r""" | 1022 r""" |
| 1023 // Test that named arguments can be called. |
| 1024 |
1089 class C { | 1025 class C { |
1090 foo({a, named: 'v1', x}) { | 1026 foo({a, named: 'v1', x}) { |
1091 print(named); | 1027 print(named); |
1092 } | 1028 } |
1093 } | 1029 } |
1094 | 1030 |
1095 var instance; | 1031 var instance; |
1096 | 1032 |
1097 main() { | 1033 main() { |
1098 if (instance == null) { | 1034 if (instance == null) { |
1099 print('instance is null'); | 1035 print('instance is null'); |
1100 instance = new C(); | 1036 instance = new C(); |
1101 } | 1037 } |
| 1038 """, |
| 1039 const [ |
| 1040 r""" |
1102 instance.foo(); | 1041 instance.foo(); |
| 1042 """, |
| 1043 r""" |
| 1044 instance.foo(named: 'v2'); |
| 1045 """, |
| 1046 ], |
| 1047 r""" |
1103 } | 1048 } |
1104 """, | 1049 """, |
1105 const <String>['instance is null', 'v1']), | 1050 ], |
1106 const ProgramResult( | 1051 const <ProgramExpectation>[ |
| 1052 const ProgramExpectation( |
| 1053 const <String>['instance is null', 'v1']), |
| 1054 const ProgramExpectation( |
| 1055 const <String>['v2']), |
| 1056 ]), |
| 1057 |
| 1058 const EncodedResult( |
| 1059 const [ |
1107 r""" | 1060 r""" |
1108 class C { | 1061 // Test than named arguments can be called. |
1109 foo({a, named: 'v1', x}) { | |
1110 print(named); | |
1111 } | |
1112 } | |
1113 | 1062 |
1114 var instance; | |
1115 | |
1116 main() { | |
1117 if (instance == null) { | |
1118 print('instance is null'); | |
1119 instance = new C(); | |
1120 } | |
1121 instance.foo(named: 'v2'); | |
1122 } | |
1123 """, | |
1124 const <String>['v2']), | |
1125 ], | |
1126 | |
1127 // Test than named arguments can be called. | |
1128 const <ProgramResult>[ | |
1129 const ProgramResult( | |
1130 r""" | |
1131 class C { | 1063 class C { |
1132 foo({a, named: 'v2', x}) { | 1064 foo({a, named: 'v2', x}) { |
1133 print(named); | 1065 print(named); |
1134 } | |
1135 } | |
1136 | |
1137 var instance; | |
1138 | |
1139 main() { | |
1140 if (instance == null) { | |
1141 print('instance is null'); | |
1142 instance = new C(); | |
1143 } | |
1144 instance.foo(named: 'v1'); | |
1145 } | |
1146 """, | |
1147 const <String>['instance is null', 'v1']), | |
1148 const ProgramResult( | |
1149 r""" | |
1150 class C { | |
1151 foo({a, named: 'v2', x}) { | |
1152 print(named); | |
1153 } | 1066 } |
1154 } | 1067 } |
1155 | 1068 |
1156 var instance; | 1069 var instance; |
1157 | 1070 |
1158 main() { | 1071 main() { |
1159 if (instance == null) { | 1072 if (instance == null) { |
1160 print('instance is null'); | 1073 print('instance is null'); |
1161 instance = new C(); | 1074 instance = new C(); |
1162 } | 1075 } |
| 1076 """, |
| 1077 const [ |
| 1078 r""" |
| 1079 instance.foo(named: 'v1'); |
| 1080 """, |
| 1081 r""" |
1163 instance.foo(); | 1082 instance.foo(); |
| 1083 """, |
| 1084 ], |
| 1085 r""" |
1164 } | 1086 } |
1165 """, | 1087 """, |
1166 const <String>['v2']), | 1088 ], |
1167 ], | 1089 const <ProgramExpectation>[ |
| 1090 const ProgramExpectation( |
| 1091 const <String>['instance is null', 'v1']), |
| 1092 const ProgramExpectation( |
| 1093 const <String>['v2']), |
| 1094 ]), |
1168 | 1095 |
1169 // Test that an instance tear-off with named parameters can be called. | 1096 const EncodedResult( |
1170 const <ProgramResult>[ | 1097 const [ |
1171 const ProgramResult( | |
1172 r""" | 1098 r""" |
| 1099 // Test that an instance tear-off with named parameters can be called. |
| 1100 |
1173 class C { | 1101 class C { |
1174 foo({a, named: 'v1', x}) { | 1102 foo({a, named: 'v1', x}) { |
1175 print(named); | 1103 print(named); |
1176 } | |
1177 } | |
1178 | |
1179 var closure; | |
1180 | |
1181 main() { | |
1182 if (closure == null) { | |
1183 print('closure is null'); | |
1184 closure = new C().foo; | |
1185 } | |
1186 closure(); | |
1187 } | |
1188 """, | |
1189 const <String>['closure is null', 'v1']), | |
1190 const ProgramResult( | |
1191 r""" | |
1192 class C { | |
1193 foo({a, named: 'v1', x}) { | |
1194 print(named); | |
1195 } | 1104 } |
1196 } | 1105 } |
1197 | 1106 |
1198 var closure; | 1107 var closure; |
1199 | 1108 |
1200 main() { | 1109 main() { |
1201 if (closure == null) { | 1110 if (closure == null) { |
1202 print('closure is null'); | 1111 print('closure is null'); |
1203 closure = new C().foo; | 1112 closure = new C().foo; |
1204 } | 1113 } |
| 1114 """, |
| 1115 const [ |
| 1116 r""" |
| 1117 closure(); |
| 1118 """, |
| 1119 r""" |
1205 closure(named: 'v2'); | 1120 closure(named: 'v2'); |
| 1121 """, |
| 1122 ], |
| 1123 r""" |
1206 } | 1124 } |
1207 """, | 1125 """, |
1208 const <String>['v2']), | 1126 ], |
1209 ], | 1127 const <ProgramExpectation>[ |
| 1128 const ProgramExpectation( |
| 1129 const <String>['closure is null', 'v1']), |
| 1130 const ProgramExpectation( |
| 1131 const <String>['v2']), |
| 1132 ]), |
1210 | 1133 |
1211 // Test that a lazy static is supported. | 1134 const EncodedResult( |
1212 const <ProgramResult>[ | 1135 const [ |
1213 const ProgramResult( | |
1214 r""" | 1136 r""" |
| 1137 // Test that a lazy static is supported. |
| 1138 |
1215 var normal; | 1139 var normal; |
1216 | 1140 |
| 1141 """, |
| 1142 const [ |
| 1143 r""" |
1217 foo() { | 1144 foo() { |
1218 print(normal); | 1145 print(normal); |
1219 } | 1146 } |
1220 | |
1221 main() { | |
1222 if (normal == null) { | |
1223 normal = 'v1'; | |
1224 } else { | |
1225 normal = ''; | |
1226 } | |
1227 foo(); | |
1228 } | |
1229 """, | 1147 """, |
1230 const <String>['v1']), | 1148 r""" |
1231 const ProgramResult( | |
1232 r""" | |
1233 var normal; | |
1234 | |
1235 var lazy = bar(); | 1149 var lazy = bar(); |
1236 | 1150 |
1237 foo() { | 1151 foo() { |
1238 print(lazy); | 1152 print(lazy); |
1239 } | 1153 } |
1240 | 1154 |
1241 bar() { | 1155 bar() { |
1242 print('v2'); | 1156 print('v2'); |
1243 return 'lazy'; | 1157 return 'lazy'; |
1244 } | 1158 } |
1245 | 1159 |
| 1160 """, |
| 1161 ], |
| 1162 r""" |
1246 main() { | 1163 main() { |
1247 if (normal == null) { | 1164 if (normal == null) { |
1248 normal = 'v1'; | 1165 normal = 'v1'; |
1249 } else { | 1166 } else { |
1250 normal = ''; | 1167 normal = ''; |
1251 } | 1168 } |
1252 foo(); | 1169 foo(); |
1253 } | 1170 } |
1254 """, | 1171 """, |
1255 const <String>['v2', 'lazy']), | 1172 ], |
1256 ], | 1173 const <ProgramExpectation>[ |
| 1174 const ProgramExpectation( |
| 1175 const <String>['v1']), |
| 1176 const ProgramExpectation( |
| 1177 const <String>['v2', 'lazy']), |
| 1178 ]), |
1257 | 1179 |
1258 // Test that superclasses of directly instantiated classes are also | 1180 const EncodedResult( |
1259 // emitted. | 1181 const [ |
1260 const <ProgramResult>[ | |
1261 const ProgramResult( | |
1262 r""" | 1182 r""" |
| 1183 // Test that superclasses of directly instantiated classes are also emitted. |
1263 class A { | 1184 class A { |
1264 } | 1185 } |
1265 | 1186 |
1266 class B extends A { | 1187 class B extends A { |
1267 } | 1188 } |
1268 | 1189 |
1269 main() { | 1190 main() { |
| 1191 """, |
| 1192 const [ |
| 1193 r""" |
1270 print('v1'); | 1194 print('v1'); |
| 1195 """, |
| 1196 r""" |
| 1197 new B(); |
| 1198 print('v2'); |
| 1199 """, |
| 1200 ], |
| 1201 r""" |
1271 } | 1202 } |
1272 """, | 1203 """, |
1273 const <String>['v1']), | 1204 ], |
1274 const ProgramResult( | 1205 const <ProgramExpectation>[ |
| 1206 const ProgramExpectation( |
| 1207 const <String>['v1']), |
| 1208 const ProgramExpectation( |
| 1209 const <String>['v2']), |
| 1210 ]), |
| 1211 |
| 1212 const EncodedResult( |
| 1213 const [ |
1275 r""" | 1214 r""" |
1276 class A { | 1215 // Test that interceptor classes are handled correctly. |
1277 } | |
1278 | |
1279 class B extends A { | |
1280 } | |
1281 | 1216 |
1282 main() { | 1217 main() { |
1283 new B(); | 1218 """, |
1284 print('v2'); | 1219 const [ |
| 1220 r""" |
| 1221 print('v1'); |
| 1222 """, |
| 1223 r""" |
| 1224 ['v2'].forEach(print); |
| 1225 """, |
| 1226 ], |
| 1227 r""" |
1285 } | 1228 } |
1286 """, | 1229 """, |
1287 const <String>['v2']), | 1230 ], |
1288 ], | 1231 const <ProgramExpectation>[ |
| 1232 const ProgramExpectation( |
| 1233 const <String>['v1']), |
| 1234 const ProgramExpectation( |
| 1235 const <String>['v2']), |
| 1236 ]), |
1289 | 1237 |
1290 // Test that interceptor classes are handled correctly. | 1238 const EncodedResult( |
1291 const <ProgramResult>[ | 1239 const [ |
1292 const ProgramResult( | |
1293 r""" | 1240 r""" |
1294 main() { | 1241 // Test that newly instantiated superclasses are handled correctly when there |
1295 print('v1'); | 1242 // is more than one change. |
1296 } | |
1297 """, | |
1298 const <String>['v1']), | |
1299 const ProgramResult( | |
1300 r""" | |
1301 main() { | |
1302 ['v2'].forEach(print); | |
1303 } | |
1304 """, | |
1305 const <String>['v2']), | |
1306 ], | |
1307 | 1243 |
1308 // Test that newly instantiated classes are handled correctly when there is | |
1309 // more than one change. | |
1310 const <ProgramResult>[ | |
1311 const ProgramResult( | |
1312 r""" | |
1313 class A { | 1244 class A { |
1314 foo() { | 1245 foo() { |
1315 print('Called foo'); | 1246 print('Called foo'); |
1316 } | 1247 } |
1317 | 1248 |
1318 bar() { | 1249 bar() { |
1319 print('Called bar'); | 1250 print('Called bar'); |
1320 } | 1251 } |
1321 } | 1252 } |
1322 | 1253 |
1323 class B extends A { | 1254 class B extends A { |
1324 } | 1255 } |
1325 | 1256 |
1326 main() { | 1257 main() { |
| 1258 """, |
| 1259 const [ |
| 1260 r""" |
1327 new B().foo(); | 1261 new B().foo(); |
| 1262 """, |
| 1263 r""" |
| 1264 new B().foo(); |
| 1265 """, |
| 1266 r""" |
| 1267 new A().bar(); |
| 1268 """, |
| 1269 ], |
| 1270 r""" |
1328 } | 1271 } |
1329 """, | 1272 """, |
1330 const <String>['Called foo']), | 1273 ], |
1331 const ProgramResult( | 1274 const <ProgramExpectation>[ |
| 1275 const ProgramExpectation( |
| 1276 const <String>['Called foo']), |
| 1277 const ProgramExpectation( |
| 1278 const <String>['Called foo']), |
| 1279 const ProgramExpectation( |
| 1280 const <String>['Called bar']), |
| 1281 ]), |
| 1282 |
| 1283 const EncodedResult( |
| 1284 const [ |
1332 r""" | 1285 r""" |
| 1286 // Test that newly instantiated subclasses are handled correctly when there is |
| 1287 // more than one change. |
| 1288 |
1333 class A { | 1289 class A { |
1334 foo() { | 1290 foo() { |
1335 print('Called foo'); | 1291 print('Called foo'); |
1336 } | |
1337 | |
1338 bar() { | |
1339 print('Called bar'); | |
1340 } | |
1341 } | |
1342 | |
1343 class B extends A { | |
1344 } | |
1345 | |
1346 main() { | |
1347 new B().foo(); | |
1348 } | |
1349 """, | |
1350 const <String>['Called foo']), | |
1351 const ProgramResult( | |
1352 r""" | |
1353 class A { | |
1354 foo() { | |
1355 print('Called foo'); | |
1356 } | 1292 } |
1357 | 1293 |
1358 bar() { | 1294 bar() { |
1359 print('Called bar'); | 1295 print('Called bar'); |
1360 } | 1296 } |
1361 } | 1297 } |
1362 | 1298 |
1363 class B extends A { | 1299 class B extends A { |
1364 } | 1300 } |
1365 | 1301 |
1366 main() { | 1302 main() { |
1367 new A().bar(); | 1303 """, |
| 1304 const [ |
| 1305 r""" |
| 1306 new A().foo(); |
| 1307 """, |
| 1308 r""" |
| 1309 new A().foo(); |
| 1310 """, |
| 1311 r""" |
| 1312 new B().bar(); |
| 1313 """, |
| 1314 ], |
| 1315 r""" |
1368 } | 1316 } |
1369 """, | 1317 """, |
1370 const <String>['Called bar']), | 1318 ], |
1371 ], | 1319 const <ProgramExpectation>[ |
| 1320 const ProgramExpectation( |
| 1321 const <String>['Called foo']), |
| 1322 const ProgramExpectation( |
| 1323 const <String>['Called foo']), |
| 1324 const ProgramExpectation( |
| 1325 const <String>['Called bar']), |
| 1326 ]), |
1372 | 1327 |
1373 // Test that constants are handled correctly. | 1328 const EncodedResult( |
1374 const <ProgramResult>[ | 1329 const [ |
1375 const ProgramResult( | |
1376 r""" | 1330 r""" |
| 1331 // Test that constants are handled correctly. |
| 1332 |
1377 class C { | 1333 class C { |
1378 final String value; | 1334 final String value; |
1379 const C(this.value); | 1335 const C(this.value); |
1380 } | 1336 } |
1381 | 1337 |
1382 main() { | 1338 main() { |
| 1339 """, |
| 1340 const [ |
| 1341 r""" |
1383 print(const C('v1').value); | 1342 print(const C('v1').value); |
| 1343 """, |
| 1344 r""" |
| 1345 print(const C('v2').value); |
| 1346 """, |
| 1347 ], |
| 1348 r""" |
1384 } | 1349 } |
1385 """, | 1350 """, |
1386 const <String>['v1']), | 1351 ], |
1387 const ProgramResult( | 1352 const <ProgramExpectation>[ |
| 1353 const ProgramExpectation( |
| 1354 const <String>['v1']), |
| 1355 const ProgramExpectation( |
| 1356 const <String>['v2']), |
| 1357 ]), |
| 1358 |
| 1359 const EncodedResult( |
| 1360 const [ |
1388 r""" | 1361 r""" |
| 1362 // Test that an instance field can be added to a compound declaration. |
| 1363 |
1389 class C { | 1364 class C { |
1390 final String value; | |
1391 const C(this.value); | |
1392 } | |
1393 | |
1394 main() { | |
1395 print(const C('v2').value); | |
1396 } | |
1397 """, | 1365 """, |
1398 const <String>['v2']), | 1366 const [ |
1399 ], | 1367 r""" |
1400 | |
1401 // Test that an instance field can be added to a compound declaration. | |
1402 const <ProgramResult>[ | |
1403 const ProgramResult( | |
1404 r""" | |
1405 class C { | |
1406 int x; | 1368 int x; |
| 1369 """, |
| 1370 r""" |
| 1371 int x, y; |
| 1372 """, |
| 1373 ], |
| 1374 r""" |
1407 } | 1375 } |
1408 | 1376 |
1409 var instance; | 1377 var instance; |
1410 | |
1411 main() { | |
1412 if (instance == null) { | |
1413 print('[instance] is null'); | |
1414 instance = new C(); | |
1415 instance.x = 'v1'; | |
1416 } else { | |
1417 instance.y = 'v2'; | |
1418 } | |
1419 try { | |
1420 print(instance.x); | |
1421 } catch (e) { | |
1422 print('[instance.x] threw'); | |
1423 } | |
1424 try { | |
1425 print(instance.y); | |
1426 } catch (e) { | |
1427 print('[instance.y] threw'); | |
1428 } | |
1429 } | |
1430 """, | |
1431 const <String>['[instance] is null', 'v1', '[instance.y] threw']), | |
1432 | |
1433 const ProgramResult( | |
1434 r""" | |
1435 class C { | |
1436 int x, y; | |
1437 } | |
1438 | |
1439 var instance; | |
1440 | 1378 |
1441 main() { | 1379 main() { |
1442 if (instance == null) { | 1380 if (instance == null) { |
1443 print('[instance] is null'); | 1381 print('[instance] is null'); |
1444 instance = new C(); | 1382 instance = new C(); |
1445 instance.x = 'v1'; | 1383 instance.x = 'v1'; |
1446 } else { | 1384 } else { |
1447 instance.y = 'v2'; | 1385 instance.y = 'v2'; |
1448 } | 1386 } |
1449 try { | 1387 try { |
1450 print(instance.x); | 1388 print(instance.x); |
1451 } catch (e) { | 1389 } catch (e) { |
1452 print('[instance.x] threw'); | 1390 print('[instance.x] threw'); |
1453 } | 1391 } |
1454 try { | 1392 try { |
1455 print(instance.y); | 1393 print(instance.y); |
1456 } catch (e) { | 1394 } catch (e) { |
1457 print('[instance.y] threw'); | 1395 print('[instance.y] threw'); |
1458 } | 1396 } |
1459 } | 1397 } |
1460 """, | 1398 """, |
1461 const <String>['v1', 'v2'], | 1399 ], |
1462 // TODO(ahe): Shouldn't throw. | 1400 const <ProgramExpectation>[ |
1463 compileUpdatesShouldThrow: true), | 1401 const ProgramExpectation( |
| 1402 const <String>[ |
| 1403 '[instance] is null', 'v1', '[instance.y] threw']), |
| 1404 const ProgramExpectation( |
| 1405 const <String>['v1', 'v2'], |
| 1406 // TODO(ahe): Shouldn't throw. |
| 1407 compileUpdatesShouldThrow: true), |
| 1408 ]), |
1464 | 1409 |
1465 ], | 1410 const EncodedResult( |
| 1411 const [ |
| 1412 r""" |
| 1413 // Test that an instance field can be removed from a compound declaration. |
1466 | 1414 |
1467 // Test that an instance field can be removed from a compound declaration. | |
1468 const <ProgramResult>[ | |
1469 const ProgramResult( | |
1470 r""" | |
1471 class C { | 1415 class C { |
| 1416 """, |
| 1417 const [ |
| 1418 r""" |
1472 int x, y; | 1419 int x, y; |
| 1420 """, |
| 1421 r""" |
| 1422 int x; |
| 1423 """, |
| 1424 ], |
| 1425 r""" |
1473 } | 1426 } |
1474 | 1427 |
1475 var instance; | 1428 var instance; |
1476 | |
1477 main() { | |
1478 if (instance == null) { | |
1479 print('[instance] is null'); | |
1480 instance = new C(); | |
1481 instance.x = 'v1'; | |
1482 instance.y = 'v2'; | |
1483 } | |
1484 try { | |
1485 print(instance.x); | |
1486 } catch (e) { | |
1487 print('[instance.x] threw'); | |
1488 } | |
1489 try { | |
1490 print(instance.y); | |
1491 } catch (e) { | |
1492 print('[instance.y] threw'); | |
1493 } | |
1494 } | |
1495 """, | |
1496 const <String>['[instance] is null', 'v1', 'v2']), | |
1497 | |
1498 const ProgramResult( | |
1499 r""" | |
1500 class C { | |
1501 int x; | |
1502 } | |
1503 | |
1504 var instance; | |
1505 | 1429 |
1506 main() { | 1430 main() { |
1507 if (instance == null) { | 1431 if (instance == null) { |
1508 print('[instance] is null'); | 1432 print('[instance] is null'); |
1509 instance = new C(); | 1433 instance = new C(); |
1510 instance.x = 'v1'; | 1434 instance.x = 'v1'; |
1511 instance.y = 'v2'; | 1435 instance.y = 'v2'; |
1512 } | 1436 } |
1513 try { | 1437 try { |
1514 print(instance.x); | 1438 print(instance.x); |
1515 } catch (e) { | 1439 } catch (e) { |
1516 print('[instance.x] threw'); | 1440 print('[instance.x] threw'); |
1517 } | 1441 } |
1518 try { | 1442 try { |
1519 print(instance.y); | 1443 print(instance.y); |
1520 } catch (e) { | 1444 } catch (e) { |
1521 print('[instance.y] threw'); | 1445 print('[instance.y] threw'); |
1522 } | 1446 } |
1523 } | 1447 } |
1524 """, | 1448 """, |
1525 const <String>['v1', '[instance.y] threw'], | 1449 ], |
1526 // TODO(ahe): Shouldn't throw. | 1450 const <ProgramExpectation>[ |
1527 compileUpdatesShouldThrow: true), | 1451 const ProgramExpectation( |
1528 ], | 1452 const <String>['[instance] is null', 'v1', 'v2']), |
| 1453 const ProgramExpectation( |
| 1454 const <String>['v1', '[instance.y] threw'], |
| 1455 // TODO(ahe): Shouldn't throw. |
| 1456 compileUpdatesShouldThrow: true), |
| 1457 ]), |
1529 | 1458 |
1530 // Test that a static field can be made an instance field. | 1459 const EncodedResult( |
1531 // TODO(ahe): Test doesn't pass. | 1460 const [ |
1532 const <ProgramResult>[ | |
1533 const ProgramResult( | |
1534 r""" | 1461 r""" |
| 1462 // Test that a static field can be made an instance field. |
| 1463 |
1535 class C { | 1464 class C { |
| 1465 """, |
| 1466 |
| 1467 const [ |
| 1468 r""" |
1536 static int x; | 1469 static int x; |
| 1470 """, |
| 1471 r""" |
| 1472 int x; |
| 1473 """, |
| 1474 ], |
| 1475 r""" |
1537 } | 1476 } |
1538 | 1477 |
1539 var instance; | 1478 var instance; |
1540 | |
1541 main() { | |
1542 if (instance == null) { | |
1543 print('[instance] is null'); | |
1544 instance = new C(); | |
1545 C.x = 'v1'; | |
1546 } else { | |
1547 instance.x = 'v2'; | |
1548 } | |
1549 try { | |
1550 print(C.x); | |
1551 } catch (e) { | |
1552 print('[C.x] threw'); | |
1553 } | |
1554 try { | |
1555 print(instance.x); | |
1556 } catch (e) { | |
1557 print('[instance.x] threw'); | |
1558 } | |
1559 } | |
1560 """, | |
1561 const <String>['[instance] is null', 'v1', '[instance.x] threw']), | |
1562 | |
1563 const ProgramResult( | |
1564 r""" | |
1565 class C { | |
1566 int x; | |
1567 } | |
1568 | |
1569 var instance; | |
1570 | 1479 |
1571 main() { | 1480 main() { |
1572 if (instance == null) { | 1481 if (instance == null) { |
1573 print('[instance] is null'); | 1482 print('[instance] is null'); |
1574 instance = new C(); | 1483 instance = new C(); |
1575 C.x = 'v1'; | 1484 C.x = 'v1'; |
1576 } else { | 1485 } else { |
1577 instance.x = 'v2'; | 1486 instance.x = 'v2'; |
1578 } | 1487 } |
1579 try { | 1488 try { |
1580 print(C.x); | 1489 print(C.x); |
1581 } catch (e) { | 1490 } catch (e) { |
1582 print('[C.x] threw'); | 1491 print('[C.x] threw'); |
1583 } | 1492 } |
1584 try { | 1493 try { |
1585 print(instance.x); | 1494 print(instance.x); |
1586 } catch (e) { | 1495 } catch (e) { |
1587 print('[instance.x] threw'); | 1496 print('[instance.x] threw'); |
1588 } | 1497 } |
1589 } | 1498 } |
1590 """, | 1499 """, |
1591 const <String>['[C.x] threw', 'v2'], | 1500 ], |
1592 // TODO(ahe): Shouldn't throw. | 1501 const <ProgramExpectation>[ |
1593 compileUpdatesShouldThrow: true), | 1502 const ProgramExpectation( |
1594 ], | 1503 const <String>['[instance] is null', 'v1', '[instance.x] threw']
), |
| 1504 const ProgramExpectation( |
| 1505 const <String>['[C.x] threw', 'v2'], |
| 1506 // TODO(ahe): Shouldn't throw. |
| 1507 compileUpdatesShouldThrow: true), |
| 1508 ]), |
1595 | 1509 |
1596 // Test that instance field can be made static. | 1510 const EncodedResult( |
1597 const <ProgramResult>[ | 1511 const [ |
1598 const ProgramResult( | |
1599 r""" | 1512 r""" |
| 1513 // Test that instance field can be made static. |
| 1514 |
1600 class C { | 1515 class C { |
| 1516 """, |
| 1517 const [ |
| 1518 r""" |
1601 int x; | 1519 int x; |
| 1520 """, |
| 1521 r""" |
| 1522 static int x; |
| 1523 """, |
| 1524 ], |
| 1525 r""" |
1602 } | 1526 } |
1603 | 1527 |
1604 var instance; | 1528 var instance; |
1605 | |
1606 main() { | |
1607 if (instance == null) { | |
1608 print('[instance] is null'); | |
1609 instance = new C(); | |
1610 instance.x = 'v1'; | |
1611 } else { | |
1612 C.x = 'v2'; | |
1613 } | |
1614 try { | |
1615 print(C.x); | |
1616 } catch (e) { | |
1617 print('[C.x] threw'); | |
1618 } | |
1619 try { | |
1620 print(instance.x); | |
1621 } catch (e) { | |
1622 print('[instance.x] threw'); | |
1623 } | |
1624 } | |
1625 """, | |
1626 const <String>['[instance] is null', '[C.x] threw', 'v1']), | |
1627 | |
1628 const ProgramResult( | |
1629 r""" | |
1630 class C { | |
1631 static int x; | |
1632 } | |
1633 | |
1634 var instance; | |
1635 | 1529 |
1636 main() { | 1530 main() { |
1637 if (instance == null) { | 1531 if (instance == null) { |
1638 print('[instance] is null'); | 1532 print('[instance] is null'); |
1639 instance = new C(); | 1533 instance = new C(); |
1640 instance.x = 'v1'; | 1534 instance.x = 'v1'; |
1641 } else { | 1535 } else { |
1642 C.x = 'v2'; | 1536 C.x = 'v2'; |
1643 } | 1537 } |
1644 try { | 1538 try { |
1645 print(C.x); | 1539 print(C.x); |
1646 } catch (e) { | 1540 } catch (e) { |
1647 print('[C.x] threw'); | 1541 print('[C.x] threw'); |
1648 } | 1542 } |
1649 try { | 1543 try { |
1650 print(instance.x); | 1544 print(instance.x); |
1651 } catch (e) { | 1545 } catch (e) { |
1652 print('[instance.x] threw'); | 1546 print('[instance.x] threw'); |
1653 } | 1547 } |
1654 } | 1548 } |
1655 """, | 1549 """, |
1656 const <String>['v2', '[instance.x] threw'], | 1550 ], |
1657 // TODO(ahe): Shouldn't throw. | 1551 const <ProgramExpectation>[ |
1658 compileUpdatesShouldThrow: true), | 1552 const ProgramExpectation( |
1659 ], | 1553 const <String>['[instance] is null', '[C.x] threw', 'v1']), |
| 1554 const ProgramExpectation( |
| 1555 const <String>['v2', '[instance.x] threw'], |
| 1556 // TODO(ahe): Shouldn't throw. |
| 1557 compileUpdatesShouldThrow: true), |
| 1558 ]), |
1660 | 1559 |
1661 // Test compound constants. | 1560 const EncodedResult( |
1662 const <ProgramResult>[ | 1561 const [ |
1663 const ProgramResult( | |
1664 r""" | 1562 r""" |
| 1563 // Test compound constants. |
| 1564 |
1665 class A { | 1565 class A { |
1666 final value; | 1566 final value; |
1667 const A(this.value); | 1567 const A(this.value); |
1668 | 1568 |
1669 toString() => 'A($value)'; | 1569 toString() => 'A($value)'; |
1670 } | 1570 } |
1671 | 1571 |
1672 class B { | 1572 class B { |
1673 final value; | 1573 final value; |
1674 const B(this.value); | 1574 const B(this.value); |
1675 | 1575 |
1676 toString() => 'B($value)'; | 1576 toString() => 'B($value)'; |
1677 } | 1577 } |
1678 | 1578 |
1679 main() { | 1579 main() { |
| 1580 """, |
| 1581 const [ |
| 1582 r""" |
1680 print(const A('v1')); | 1583 print(const A('v1')); |
1681 print(const B('v1')); | 1584 print(const B('v1')); |
| 1585 """, |
| 1586 r""" |
| 1587 print(const B(const A('v2'))); |
| 1588 print(const A(const B('v2'))); |
| 1589 """, |
| 1590 ], |
| 1591 r""" |
1682 } | 1592 } |
1683 """, | 1593 """, |
1684 const <String>['A(v1)', 'B(v1)']), | 1594 ], |
| 1595 const <ProgramExpectation>[ |
| 1596 const ProgramExpectation( |
| 1597 const <String>['A(v1)', 'B(v1)']), |
| 1598 const ProgramExpectation( |
| 1599 const <String>['B(A(v2))', 'A(B(v2))']), |
| 1600 ]), |
1685 | 1601 |
1686 const ProgramResult( | 1602 const EncodedResult( |
| 1603 const [ |
1687 r""" | 1604 r""" |
| 1605 // Test constants of new classes. |
| 1606 |
1688 class A { | 1607 class A { |
1689 final value; | 1608 final value; |
1690 const A(this.value); | 1609 const A(this.value); |
1691 | 1610 |
1692 toString() => 'A($value)'; | 1611 toString() => 'A($value)'; |
1693 } | 1612 } |
1694 | 1613 """, |
| 1614 const [ |
| 1615 "", |
| 1616 r""" |
1695 class B { | 1617 class B { |
1696 final value; | 1618 final value; |
1697 const B(this.value); | 1619 const B(this.value); |
1698 | |
1699 toString() => 'B($value)'; | |
1700 } | |
1701 | |
1702 main() { | |
1703 print(const B(const A('v2'))); | |
1704 print(const A(const B('v2'))); | |
1705 } | |
1706 """, | |
1707 const <String>['B(A(v2))', 'A(B(v2))']), | |
1708 ], | |
1709 | |
1710 // Test constants of new classes. | |
1711 const <ProgramResult>[ | |
1712 const ProgramResult( | |
1713 r""" | |
1714 class A { | |
1715 final value; | |
1716 const A(this.value); | |
1717 | |
1718 toString() => 'A($value)'; | |
1719 } | |
1720 | |
1721 main() { | |
1722 print(const A('v1')); | |
1723 } | |
1724 """, | |
1725 const <String>['A(v1)']), | |
1726 | |
1727 const ProgramResult( | |
1728 r""" | |
1729 class A { | |
1730 final value; | |
1731 const A(this.value); | |
1732 | |
1733 toString() => 'A($value)'; | |
1734 } | |
1735 | |
1736 class B { | |
1737 final value; | |
1738 const B(this.value); | |
1739 | 1620 |
1740 toString() => 'B($value)'; | 1621 toString() => 'B($value)'; |
1741 } | 1622 } |
1742 | 1623 |
| 1624 """, |
| 1625 ], |
| 1626 r""" |
1743 main() { | 1627 main() { |
| 1628 """, |
| 1629 |
| 1630 const [ |
| 1631 r""" |
| 1632 print(const A('v1')); |
| 1633 """, |
| 1634 r""" |
1744 print(const A('v2')); | 1635 print(const A('v2')); |
1745 print(const B('v2')); | 1636 print(const B('v2')); |
1746 print(const B(const A('v2'))); | 1637 print(const B(const A('v2'))); |
1747 print(const A(const B('v2'))); | 1638 print(const A(const B('v2'))); |
| 1639 """, |
| 1640 ], |
| 1641 r""" |
1748 } | 1642 } |
1749 """, | 1643 """, |
1750 const <String>['A(v2)', 'B(v2)', 'B(A(v2))', 'A(B(v2))']), | 1644 |
1751 ], | 1645 ], |
| 1646 const <ProgramExpectation>[ |
| 1647 const ProgramExpectation( |
| 1648 const <String>['A(v1)']), |
| 1649 const ProgramExpectation( |
| 1650 const <String>['A(v2)', 'B(v2)', 'B(A(v2))', 'A(B(v2))']), |
| 1651 ]), |
1752 ]; | 1652 ]; |
1753 | 1653 |
1754 void main() { | 1654 void main() { |
1755 listener.start(); | 1655 listener.start(); |
1756 | 1656 |
1757 document.head.append(lineNumberStyle()); | 1657 document.head.append(lineNumberStyle()); |
1758 | 1658 |
1759 summary = new SpanElement(); | 1659 summary = new SpanElement(); |
1760 document.body.append(new HeadingElement.h1() | 1660 document.body.append(new HeadingElement.h1() |
1761 ..appendText("Incremental compiler tests") | 1661 ..appendText("Incremental compiler tests") |
(...skipping 20 matching lines...) Expand all Loading... |
1782 SpanElement summary; | 1682 SpanElement summary; |
1783 | 1683 |
1784 int testCount = 1; | 1684 int testCount = 1; |
1785 | 1685 |
1786 bool verboseStatus = false; | 1686 bool verboseStatus = false; |
1787 | 1687 |
1788 void updateSummary(_) { | 1688 void updateSummary(_) { |
1789 summary.text = " (${testCount - 1}/${tests.length})"; | 1689 summary.text = " (${testCount - 1}/${tests.length})"; |
1790 } | 1690 } |
1791 | 1691 |
1792 Future compileAndRun(List<ProgramResult> programs) { | 1692 Future compileAndRun(EncodedResult encodedResult) { |
1793 updateSummary(null); | 1693 updateSummary(null); |
| 1694 List<ProgramResult> programs = encodedResult.decode(); |
1794 var status = new DivElement(); | 1695 var status = new DivElement(); |
1795 document.body.append(status); | 1696 document.body.append(status); |
1796 | 1697 |
1797 IFrameElement iframe = | 1698 IFrameElement iframe = |
1798 appendIFrame( | 1699 appendIFrame( |
1799 '/root_dart/tests/try/web/incremental_compilation_update.html', | 1700 '/root_dart/tests/try/web/incremental_compilation_update.html', |
1800 document.body) | 1701 document.body) |
1801 ..style.width = '100%' | 1702 ..style.width = '100%' |
1802 ..style.height = '600px'; | 1703 ..style.height = '600px'; |
1803 | 1704 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 position: absolute; | 1864 position: absolute; |
1964 left: 0px; | 1865 left: 0px; |
1965 width: 3em; | 1866 width: 3em; |
1966 text-align: right; | 1867 text-align: right; |
1967 background-color: lightgoldenrodyellow; | 1868 background-color: lightgoldenrodyellow; |
1968 } | 1869 } |
1969 '''); | 1870 '''); |
1970 style.type = 'text/css'; | 1871 style.type = 'text/css'; |
1971 return style; | 1872 return style; |
1972 } | 1873 } |
OLD | NEW |