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 = """ |
(...skipping 23 matching lines...) Expand all Loading... |
34 """; | 34 """; |
35 | 35 |
36 const String ZERO_PLUS_NUM = """ | 36 const String ZERO_PLUS_NUM = """ |
37 int foo(x) => x; | 37 int foo(x) => x; |
38 void main() { | 38 void main() { |
39 var x = foo(0); | 39 var x = foo(0); |
40 return 0 + x; | 40 return 0 + x; |
41 } | 41 } |
42 """; | 42 """; |
43 | 43 |
44 | |
45 const String INT_TIMES_ONE = """ | 44 const String INT_TIMES_ONE = """ |
46 int foo(x) => x; | 45 int foo(x) => x; |
47 void main() { | 46 void main() { |
48 var x = foo(0); | 47 var x = foo(0); |
49 return (x & 1) * 1; | 48 return (x & 1) * 1; |
50 } | 49 } |
51 """; | 50 """; |
52 | 51 |
53 const String ONE_TIMES_INT = """ | 52 const String ONE_TIMES_INT = """ |
54 int foo(x) => x; | 53 int foo(x) => x; |
(...skipping 19 matching lines...) Expand all Loading... |
74 } | 73 } |
75 """; | 74 """; |
76 | 75 |
77 main() { | 76 main() { |
78 var plusZero = new RegExp(r"\+ 0"); | 77 var plusZero = new RegExp(r"\+ 0"); |
79 var zeroPlus = new RegExp(r"0 \+"); | 78 var zeroPlus = new RegExp(r"0 \+"); |
80 var timesOne = new RegExp(r"\* 1"); | 79 var timesOne = new RegExp(r"\* 1"); |
81 var oneTimes = new RegExp(r"1 \*"); | 80 var oneTimes = new RegExp(r"1 \*"); |
82 | 81 |
83 asyncTest(() => Future.wait([ | 82 asyncTest(() => Future.wait([ |
84 compileAndDoNotMatch(INT_PLUS_ZERO, 'main', plusZero), | 83 compileAndDoNotMatch(INT_PLUS_ZERO, 'main', plusZero), |
85 compileAndDoNotMatch(ZERO_PLUS_INT, 'main', zeroPlus), | 84 compileAndDoNotMatch(ZERO_PLUS_INT, 'main', zeroPlus), |
86 compileAndMatch(NUM_PLUS_ZERO, 'main', plusZero), | 85 compileAndMatch(NUM_PLUS_ZERO, 'main', plusZero), |
87 compileAndMatch(ZERO_PLUS_NUM, 'main', zeroPlus), | 86 compileAndMatch(ZERO_PLUS_NUM, 'main', zeroPlus), |
88 compileAndDoNotMatch(INT_TIMES_ONE, 'main', timesOne), | 87 compileAndDoNotMatch(INT_TIMES_ONE, 'main', timesOne), |
89 compileAndDoNotMatch(ONE_TIMES_INT, 'main', oneTimes), | 88 compileAndDoNotMatch(ONE_TIMES_INT, 'main', oneTimes), |
90 compileAndDoNotMatch(NUM_TIMES_ONE, 'main', timesOne), | 89 compileAndDoNotMatch(NUM_TIMES_ONE, 'main', timesOne), |
91 compileAndDoNotMatch(ONE_TIMES_NUM, 'main', oneTimes), | 90 compileAndDoNotMatch(ONE_TIMES_NUM, 'main', oneTimes), |
92 ])); | 91 ])); |
93 } | 92 } |
OLD | NEW |