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 // Test constant folding on numbers. | 4 // Test constant folding on numbers. |
5 | 5 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
9 | 9 |
10 const String INT_PLUS_ZERO = """ | 10 const String INT_PLUS_ZERO = """ |
11 int foo(x) => x; | 11 int foo(x) => x; |
12 void main() { | 12 void main() { |
13 var x = foo(0); | 13 var x = foo(0); |
14 return (x & 1) + 0; | 14 return (x & 1) + 0; |
15 } | 15 } |
16 """; | 16 """; |
17 | 17 |
18 const String ZERO_PLUS_INT = """ | 18 const String ZERO_PLUS_INT = """ |
19 int foo(x) => x; | 19 int foo(x) => x; |
20 void main() { | 20 void main() { |
21 var x = foo(0); | 21 var x = foo(0); |
22 return 0 + (x & 1); | 22 return 0 + (x & 1); |
23 } | 23 } |
24 """; | 24 """; |
25 | 25 |
| 26 // TODO(johnniwinther): Find out why this doesn't work without the `as num` |
| 27 // cast. |
26 const String NUM_PLUS_ZERO = """ | 28 const String NUM_PLUS_ZERO = """ |
27 int foo(x) => x; | 29 int foo(x) => x; |
28 void main() { | 30 void main() { |
29 var x = foo(0); | 31 var x = foo(0) as num; |
30 return x + 0; | 32 return x + 0; |
31 } | 33 } |
32 """; | 34 """; |
33 | 35 |
34 const String ZERO_PLUS_NUM = """ | 36 const String ZERO_PLUS_NUM = """ |
35 int foo(x) => x; | 37 int foo(x) => x; |
36 void main() { | 38 void main() { |
37 var x = foo(0); | 39 var x = foo(0); |
38 return 0 + x; | 40 return 0 + x; |
39 } | 41 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 76 |
75 main() { | 77 main() { |
76 var plusZero = new RegExp(r"\+ 0"); | 78 var plusZero = new RegExp(r"\+ 0"); |
77 var zeroPlus = new RegExp(r"0 \+"); | 79 var zeroPlus = new RegExp(r"0 \+"); |
78 var timesOne = new RegExp(r"\* 1"); | 80 var timesOne = new RegExp(r"\* 1"); |
79 var oneTimes = new RegExp(r"1 \*"); | 81 var oneTimes = new RegExp(r"1 \*"); |
80 | 82 |
81 asyncTest(() => Future.wait([ | 83 asyncTest(() => Future.wait([ |
82 compileAndDoNotMatch(INT_PLUS_ZERO, 'main', plusZero), | 84 compileAndDoNotMatch(INT_PLUS_ZERO, 'main', plusZero), |
83 compileAndDoNotMatch(ZERO_PLUS_INT, 'main', zeroPlus), | 85 compileAndDoNotMatch(ZERO_PLUS_INT, 'main', zeroPlus), |
84 // TODO(johnniwinther): Find out why this doesn't work without [useMock]. | 86 compileAndMatch(NUM_PLUS_ZERO, 'main', plusZero), |
85 compileAndMatch(NUM_PLUS_ZERO, 'main', plusZero, useMock: true), | |
86 compileAndMatch(ZERO_PLUS_NUM, 'main', zeroPlus), | 87 compileAndMatch(ZERO_PLUS_NUM, 'main', zeroPlus), |
87 compileAndDoNotMatch(INT_TIMES_ONE, 'main', timesOne), | 88 compileAndDoNotMatch(INT_TIMES_ONE, 'main', timesOne), |
88 compileAndDoNotMatch(ONE_TIMES_INT, 'main', oneTimes), | 89 compileAndDoNotMatch(ONE_TIMES_INT, 'main', oneTimes), |
89 compileAndDoNotMatch(NUM_TIMES_ONE, 'main', timesOne), | 90 compileAndDoNotMatch(NUM_TIMES_ONE, 'main', timesOne), |
90 compileAndDoNotMatch(ONE_TIMES_NUM, 'main', oneTimes), | 91 compileAndDoNotMatch(ONE_TIMES_NUM, 'main', oneTimes), |
91 ])); | 92 ])); |
92 } | 93 } |
OLD | NEW |