OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Check that exception messages for truncating operations contains the | 5 // Check that exception messages for truncating operations contains the |
6 // operands. | 6 // operands. |
7 | 7 |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 @NoInline() @AssumeDynamic() | 10 @NoInline() |
| 11 @AssumeDynamic() |
11 confuse(x) => x; | 12 confuse(x) => x; |
12 | 13 |
13 void find1(expected, thunk) { | 14 void find1(expected, thunk) { |
14 if (thunk == null) return; | 15 if (thunk == null) return; |
15 var returned, exceptionText; | 16 var returned, exceptionText; |
16 try { | 17 try { |
17 returned = thunk(); | 18 returned = thunk(); |
18 } catch (e) { | 19 } catch (e) { |
19 exceptionText = '$e'; | 20 exceptionText = '$e'; |
20 } | 21 } |
21 if (exceptionText == null) { | 22 if (exceptionText == null) { |
22 Expect.fail( | 23 Expect |
23 'Expected exception containing "$expected", returned: $returned'); | 24 .fail('Expected exception containing "$expected", returned: $returned'); |
24 } | 25 } |
25 Expect.isTrue( | 26 Expect.isTrue(exceptionText.contains(expected), |
26 exceptionText.contains(expected), | |
27 'Expected "$expected" in "$exceptionText"'); | 27 'Expected "$expected" in "$exceptionText"'); |
28 } | 28 } |
29 | 29 |
30 void find(expected, [thunk1, thunk2, thunk3, thunk4]) { | 30 void find(expected, [thunk1, thunk2, thunk3, thunk4]) { |
31 find1(expected, thunk1); | 31 find1(expected, thunk1); |
32 find1(expected, thunk2); | 32 find1(expected, thunk2); |
33 find1(expected, thunk3); | 33 find1(expected, thunk3); |
34 find1(expected, thunk4); | 34 find1(expected, thunk4); |
35 } | 35 } |
36 | 36 |
37 main() { | 37 main() { |
38 | |
39 var NaN = double.NAN; | 38 var NaN = double.NAN; |
40 var Infinity = double.INFINITY; | 39 var Infinity = double.INFINITY; |
41 | 40 |
42 find(' Infinity: 123 ~/ 0', | 41 find(' Infinity: 123 ~/ 0', () => confuse(123) ~/ confuse(0), |
43 () => confuse(123) ~/ confuse(0), | 42 () => confuse(123) ~/ 0, () => 123 ~/ confuse(0), () => 123 ~/ 0); |
44 () => confuse(123) ~/ 0, | |
45 () => 123 ~/ confuse(0), | |
46 () => 123 ~/ 0); | |
47 | 43 |
48 find('-Infinity: 123 ~/ -0.0', | 44 find( |
49 () => confuse(123) ~/ confuse(-0.0), | 45 '-Infinity: 123 ~/ -0.0', |
50 () => confuse(123) ~/ -0.0, | 46 () => confuse(123) ~/ confuse(-0.0), |
51 () => 123 ~/ confuse(-0.0), | 47 () => confuse(123) ~/ -0.0, |
52 () => 123 ~/ -0.0); | 48 () => 123 ~/ confuse(-0.0), |
| 49 () => 123 ~/ -0.0); |
53 | 50 |
54 find(' NaN: NaN ~/ 123', | 51 find(' NaN: NaN ~/ 123', () => confuse(NaN) ~/ confuse(123), |
55 () => confuse(NaN) ~/ confuse(123), | 52 () => confuse(NaN) ~/ 123, () => NaN ~/ confuse(123), () => NaN ~/ 123); |
56 () => confuse(NaN) ~/ 123, | |
57 () => NaN ~/ confuse(123), | |
58 () => NaN ~/ 123); | |
59 | 53 |
60 find(' Infinity: 1e+200 ~/ 1e-200', | 54 find( |
61 () => confuse(1e200) ~/ confuse(1e-200), | 55 ' Infinity: 1e+200 ~/ 1e-200', |
62 () => confuse(1e200) ~/ 1e-200, | 56 () => confuse(1e200) ~/ confuse(1e-200), |
63 () => 1e200 ~/ confuse(1e-200), | 57 () => confuse(1e200) ~/ 1e-200, |
64 () => 1e200 ~/ 1e-200); | 58 () => 1e200 ~/ confuse(1e-200), |
| 59 () => 1e200 ~/ 1e-200); |
65 | 60 |
66 find('NaN.toInt()', | 61 find('NaN.toInt()', () => confuse(NaN).toInt(), () => NaN.toInt()); |
67 () => confuse(NaN).toInt(), | 62 find(' Infinity.toInt()', () => confuse(Infinity).toInt(), |
68 () => NaN.toInt()); | 63 () => Infinity.toInt()); |
69 find(' Infinity.toInt()', | 64 find('-Infinity.toInt()', () => confuse(-Infinity).toInt(), |
70 () => confuse(Infinity).toInt(), | 65 () => (-Infinity).toInt()); |
71 () => Infinity.toInt()); | |
72 find('-Infinity.toInt()', | |
73 () => confuse(-Infinity).toInt(), | |
74 () => (-Infinity).toInt()); | |
75 | 66 |
76 find('NaN.ceil()', | 67 find('NaN.ceil()', () => confuse(NaN).ceil(), () => NaN.ceil()); |
77 () => confuse(NaN).ceil(), | 68 find(' Infinity.ceil()', () => confuse(Infinity).ceil(), |
78 () => NaN.ceil()); | 69 () => Infinity.ceil()); |
79 find(' Infinity.ceil()', | 70 find('-Infinity.ceil()', () => confuse(-Infinity).ceil(), |
80 () => confuse(Infinity).ceil(), | 71 () => (-Infinity).ceil()); |
81 () => Infinity.ceil()); | |
82 find('-Infinity.ceil()', | |
83 () => confuse(-Infinity).ceil(), | |
84 () => (-Infinity).ceil()); | |
85 | 72 |
86 find('NaN.floor()', | 73 find('NaN.floor()', () => confuse(NaN).floor(), () => NaN.floor()); |
87 () => confuse(NaN).floor(), | 74 find(' Infinity.floor()', () => confuse(Infinity).floor(), |
88 () => NaN.floor()); | 75 () => Infinity.floor()); |
89 find(' Infinity.floor()', | 76 find('-Infinity.floor()', () => confuse(-Infinity).floor(), |
90 () => confuse(Infinity).floor(), | 77 () => (-Infinity).floor()); |
91 () => Infinity.floor()); | |
92 find('-Infinity.floor()', | |
93 () => confuse(-Infinity).floor(), | |
94 () => (-Infinity).floor()); | |
95 | 78 |
96 find('NaN.round()', | 79 find('NaN.round()', () => confuse(NaN).round(), () => NaN.round()); |
97 () => confuse(NaN).round(), | 80 find(' Infinity.round()', () => confuse(Infinity).round(), |
98 () => NaN.round()); | 81 () => Infinity.round()); |
99 find(' Infinity.round()', | 82 find('-Infinity.round()', () => confuse(-Infinity).round(), |
100 () => confuse(Infinity).round(), | 83 () => (-Infinity).round()); |
101 () => Infinity.round()); | |
102 find('-Infinity.round()', | |
103 () => confuse(-Infinity).round(), | |
104 () => (-Infinity).round()); | |
105 | 84 |
106 // `truncate()` is the same as `toInt()`. | 85 // `truncate()` is the same as `toInt()`. |
107 // We could change the runtime so that `truncate` is reported. | 86 // We could change the runtime so that `truncate` is reported. |
108 find('NaN.toInt()', | 87 find('NaN.toInt()', () => confuse(NaN).truncate(), () => NaN.truncate()); |
109 () => confuse(NaN).truncate(), | 88 find(' Infinity.toInt()', () => confuse(Infinity).truncate(), |
110 () => NaN.truncate()); | 89 () => Infinity.truncate()); |
111 find(' Infinity.toInt()', | 90 find('-Infinity.toInt()', () => confuse(-Infinity).truncate(), |
112 () => confuse(Infinity).truncate(), | 91 () => (-Infinity).truncate()); |
113 () => Infinity.truncate()); | |
114 find('-Infinity.toInt()', | |
115 () => confuse(-Infinity).truncate(), | |
116 () => (-Infinity).truncate()); | |
117 | |
118 } | 92 } |
119 | |
OLD | NEW |