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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import 'mock_compiler.dart'; | 8 import 'mock_compiler.dart'; |
9 import 'package:compiler/src/js/js.dart' as jsAst; | 9 import 'package:compiler/src/js/js.dart' as jsAst; |
10 import 'package:compiler/src/js/js.dart' show js; | 10 import 'package:compiler/src/js/js.dart' show js; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 testStatement('do #; while ( # )', [block12, eTrue], | 151 testStatement('do #; while ( # )', [block12, eTrue], |
152 'do {\n 1;\n 2;\n} while (true); '), | 152 'do {\n 1;\n 2;\n} while (true); '), |
153 testStatement('do #; while ( # );', [block12, eVar], | 153 testStatement('do #; while ( # );', [block12, eVar], |
154 'do {\n 1;\n 2;\n} while (x);'), | 154 'do {\n 1;\n 2;\n} while (x);'), |
155 testStatement('do { # } while ( # )', [block12, 'a'], | 155 testStatement('do { # } while ( # )', [block12, 'a'], |
156 'do {\n 1;\n 2;\n} while (a);'), | 156 'do {\n 1;\n 2;\n} while (a);'), |
157 testStatement( | 157 testStatement( |
158 'do #; while ( # )', [stm, 'a'], 'do\n foo();\nwhile (a);'), | 158 'do #; while ( # )', [stm, 'a'], 'do\n foo();\nwhile (a);'), |
159 | 159 |
160 testStatement('switch (#) {}', [eOne], 'switch (1) {\n}'), | 160 testStatement('switch (#) {}', [eOne], 'switch (1) {\n}'), |
161 testStatement( | 161 testStatement(''' |
162 ''' | |
163 switch (#) { | 162 switch (#) { |
164 case #: { # } | 163 case #: { # } |
165 }''', | 164 }''', [eTrue, eOne, block12], |
166 [eTrue, eOne, block12], | |
167 'switch (true) {\n case 1:\n 1;\n 2;\n}'), | 165 'switch (true) {\n case 1:\n 1;\n 2;\n}'), |
168 testStatement( | 166 testStatement(''' |
169 ''' | |
170 switch (#) { | 167 switch (#) { |
171 case #: { # } | 168 case #: { # } |
172 break; | 169 break; |
173 case #: { # } | 170 case #: { # } |
174 default: { # } | 171 default: { # } |
175 }''', | 172 }''', [eTrue, eOne, block12, eTwo, block12, stm], ''' |
176 [eTrue, eOne, block12, eTwo, block12, stm], | |
177 ''' | |
178 switch (true) { | 173 switch (true) { |
179 case 1: | 174 case 1: |
180 1; | 175 1; |
181 2; | 176 2; |
182 break; | 177 break; |
183 case 2: | 178 case 2: |
184 1; | 179 1; |
185 2; | 180 2; |
186 default: | 181 default: |
187 foo(); | 182 foo(); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 testStatement('do {foo();} while(a);', [], 'do\n foo();\nwhile (a);'), | 467 testStatement('do {foo();} while(a);', [], 'do\n foo();\nwhile (a);'), |
473 testStatement('label: {foo();}', [], 'label:\n foo();'), | 468 testStatement('label: {foo();}', [], 'label:\n foo();'), |
474 testStatement( | 469 testStatement( |
475 'for (var key in a) {foo();}', [], 'for (var key in a)\n foo();'), | 470 'for (var key in a) {foo();}', [], 'for (var key in a)\n foo();'), |
476 // `label: break label;` gives problems on IE. Test that it is avoided. | 471 // `label: break label;` gives problems on IE. Test that it is avoided. |
477 testStatement('label: {break label;}', [], ';'), | 472 testStatement('label: {break label;}', [], ';'), |
478 // This works on IE: | 473 // This works on IE: |
479 testStatement('label: {label2: {break label;}}', [], | 474 testStatement('label: {label2: {break label;}}', [], |
480 'label:\n label2:\n break label;\n'), | 475 'label:\n label2:\n break label;\n'), |
481 // Test dangling else: | 476 // Test dangling else: |
482 testStatement( | 477 testStatement('if (a) {if (b) {foo1();}} else {foo2();}', [], """ |
483 'if (a) {if (b) {foo1();}} else {foo2();}', | |
484 [], | |
485 """ | |
486 if (a) { | 478 if (a) { |
487 if (b) | 479 if (b) |
488 foo1(); | 480 foo1(); |
489 } else | 481 } else |
490 foo2();"""), | 482 foo2();"""), |
491 testStatement( | 483 testStatement('if (a) {if (b) {foo1();} else {foo2();}}', [], """ |
492 'if (a) {if (b) {foo1();} else {foo2();}}', | |
493 [], | |
494 """ | |
495 if (a) | 484 if (a) |
496 if (b) | 485 if (b) |
497 foo1(); | 486 foo1(); |
498 else | 487 else |
499 foo2(); | 488 foo2(); |
500 """), | 489 """), |
501 testStatement( | 490 testStatement( |
502 'if (a) {if (b) {foo1();} else {foo2();}} else {foo3();}', | 491 'if (a) {if (b) {foo1();} else {foo2();}} else {foo3();}', [], """ |
503 [], | |
504 """ | |
505 if (a) | 492 if (a) |
506 if (b) | 493 if (b) |
507 foo1(); | 494 foo1(); |
508 else | 495 else |
509 foo2(); | 496 foo2(); |
510 else | 497 else |
511 foo3();"""), | 498 foo3();"""), |
512 testStatement( | 499 testStatement( |
513 'if (a) {while (true) if (b) {foo1();}} else {foo2();}', | 500 'if (a) {while (true) if (b) {foo1();}} else {foo2();}', [], """ |
514 [], | |
515 """ | |
516 if (a) { | 501 if (a) { |
517 while (true) | 502 while (true) |
518 if (b) | 503 if (b) |
519 foo1(); | 504 foo1(); |
520 } else | 505 } else |
521 foo2();"""), | 506 foo2();"""), |
522 ])); | 507 ])); |
523 } | 508 } |
OLD | NEW |