OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Test constant folding on numbers. |
| 5 |
| 6 import "package:expect/expect.dart"; |
| 7 import 'compiler_helper.dart'; |
| 8 |
| 9 const String SIMPLY_EMPTY = """ |
| 10 int foo(x) => x; |
| 11 void main() { |
| 12 var a = foo(4); |
| 13 var b = 1; |
| 14 switch (a) { |
| 15 case 1: |
| 16 b += 2; |
| 17 a = 0; |
| 18 } |
| 19 print(a); |
| 20 } |
| 21 """; |
| 22 |
| 23 const String TOTAL = """ |
| 24 void main() { |
| 25 for (int a = 0; a < 3; a++) { |
| 26 switch (a) { |
| 27 case 0: |
| 28 a = 99; |
| 29 break; |
| 30 case 1: |
| 31 a = 2; |
| 32 break; |
| 33 case 2: |
| 34 a = 1; |
| 35 break; |
| 36 default: |
| 37 a = 33; |
| 38 } |
| 39 } |
| 40 print(a); |
| 41 } |
| 42 """; |
| 43 |
| 44 const String OPTIMIZED = """ |
| 45 void main() { |
| 46 var b; |
| 47 for (int a = 0; a < 3; a++) { |
| 48 switch (a) { |
| 49 case 1: |
| 50 case 2: |
| 51 b = 0; |
| 52 ++a; |
| 53 break; |
| 54 default: |
| 55 b = 0; |
| 56 } |
| 57 } |
| 58 print(a+b); |
| 59 } |
| 60 """; |
| 61 |
| 62 const String LABEL = """ |
| 63 void main() { |
| 64 var b; |
| 65 for (int a = 0; a < 3; a++) { |
| 66 switch (a) { |
| 67 case 1: |
| 68 break; |
| 69 case 2: |
| 70 b = 0; |
| 71 continue K; |
| 72 K: case 3: |
| 73 b = 19; |
| 74 default: |
| 75 b = 5; |
| 76 } |
| 77 } |
| 78 print(a+b); |
| 79 } |
| 80 """; |
| 81 |
| 82 const String DEFLABEL = """ |
| 83 void main() { |
| 84 var b; |
| 85 for (int a = 0; a < 3; a++) { |
| 86 switch (a) { |
| 87 case 1: |
| 88 continue L; |
| 89 case 2: |
| 90 b = 0; |
| 91 break; |
| 92 L: default: |
| 93 b = 5; |
| 94 } |
| 95 } |
| 96 print(a+b); |
| 97 } |
| 98 """; |
| 99 |
| 100 main() { |
| 101 var def = new RegExp(r"default:"); |
| 102 var defOrCase3 = new RegExp(r"(default:|case 3):"); |
| 103 var case3 = new RegExp(r"case 3:"); |
| 104 |
| 105 compileAndDoNotMatch(SIMPLY_EMPTY, 'main', def); |
| 106 compileAndDoNotMatch(TOTAL, 'main', defOrCase3); |
| 107 compileAndDoNotMatch(OPTIMIZED, 'main', def); |
| 108 compileAndMatch(LABEL, 'main', case3); |
| 109 compileAndMatch(DEFLABEL, 'main', def); |
| 110 } |
OLD | NEW |