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: | |
karlklose
2014/03/12 14:43:45
I think we usually write the label as indented pre
herhut
2014/03/13 13:27:45
Done.
| |
73 case 3: | |
74 b = 19; | |
75 default: | |
76 b = 5; | |
77 } | |
78 } | |
79 print(a+b); | |
80 } | |
81 """; | |
82 | |
83 const String DEFLABEL = """ | |
84 void main() { | |
85 var b; | |
86 for (int a = 0; a < 3; a++) { | |
87 switch (a) { | |
88 case 1: | |
89 continue L; | |
90 case 2: | |
91 b = 0; | |
92 break; | |
93 L: | |
94 default: | |
95 b = 5; | |
96 } | |
97 } | |
98 print(a+b); | |
99 } | |
100 """; | |
101 | |
102 main() { | |
103 var def = new RegExp(r"default:"); | |
104 var defOrCase3 = new RegExp(r"(default:|case 3):"); | |
105 var case3 = new RegExp(r"case 3:"); | |
106 | |
107 compileAndDoNotMatch( SIMPLY_EMPTY, 'main', def); | |
karlklose
2014/03/12 14:43:45
Remove spaces before first arguments (here and bel
herhut
2014/03/13 13:27:45
Done.
| |
108 compileAndDoNotMatch( TOTAL, 'main', defOrCase3); | |
109 compileAndDoNotMatch( OPTIMIZED, 'main', def); | |
110 compileAndMatch( LABEL, 'main', case3); | |
111 compileAndMatch( DEFLABEL, 'main', def); | |
112 } | |
OLD | NEW |