Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: tests/compiler/dart2js_extra/truncation_errors_test.dart

Issue 1405113003: dart2js js_runtime: faster code for floor() & ceil() (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: bug fix for floor() Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/js_number.dart ('k') | tests/corelib/double_floor_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Check that exception messages for truncating operations contains the
6 // operands.
7
8 import 'package:expect/expect.dart';
9
10 @NoInline() @AssumeDynamic()
11 confuse(x) => x;
12
13 void find1(expected, thunk) {
14 if (thunk == null) return;
15 var returned, exceptionText;
16 try {
17 returned = thunk();
18 } catch (e) {
19 exceptionText = '$e';
20 }
21 if (exceptionText == null) {
22 Expect.fail(
23 'Expected exception containing "$expected", returned: $returned');
24 }
25 Expect.isTrue(
26 exceptionText.contains(expected),
27 'Expected "$expected" in "$exceptionText"');
28 }
29
30 void find(expected, [thunk1, thunk2, thunk3, thunk4]) {
31 find1(expected, thunk1);
32 find1(expected, thunk2);
33 find1(expected, thunk3);
34 find1(expected, thunk4);
35 }
36
37 main() {
38
39 var NaN = double.NAN;
40 var Infinity = double.INFINITY;
41
42 find(' Infinity: 123 ~/ 0',
43 () => confuse(123) ~/ confuse(0),
44 () => confuse(123) ~/ 0,
45 () => 123 ~/ confuse(0),
46 () => 123 ~/ 0);
47
48 find('-Infinity: 123 ~/ -0.0',
49 () => confuse(123) ~/ confuse(-0.0),
50 () => confuse(123) ~/ -0.0,
51 () => 123 ~/ confuse(-0.0),
52 () => 123 ~/ -0.0);
53
54 find(' NaN: NaN ~/ 123',
55 () => confuse(NaN) ~/ confuse(123),
56 () => confuse(NaN) ~/ 123,
57 () => NaN ~/ confuse(123),
58 () => NaN ~/ 123);
59
60 find(' Infinity: 1e+200 ~/ 1e-200',
61 () => confuse(1e200) ~/ confuse(1e-200),
62 () => confuse(1e200) ~/ 1e-200,
63 () => 1e200 ~/ confuse(1e-200),
64 () => 1e200 ~/ 1e-200);
65
66 find('NaN.toInt()',
67 () => confuse(NaN).toInt(),
68 () => NaN.toInt());
69 find(' Infinity.toInt()',
70 () => confuse(Infinity).toInt(),
71 () => Infinity.toInt());
72 find('-Infinity.toInt()',
73 () => confuse(-Infinity).toInt(),
74 () => (-Infinity).toInt());
75
76 find('NaN.ceil()',
77 () => confuse(NaN).ceil(),
78 () => NaN.ceil());
79 find(' Infinity.ceil()',
80 () => confuse(Infinity).ceil(),
81 () => Infinity.ceil());
82 find('-Infinity.ceil()',
83 () => confuse(-Infinity).ceil(),
84 () => (-Infinity).ceil());
85
86 find('NaN.floor()',
87 () => confuse(NaN).floor(),
88 () => NaN.floor());
89 find(' Infinity.floor()',
90 () => confuse(Infinity).floor(),
91 () => Infinity.floor());
92 find('-Infinity.floor()',
93 () => confuse(-Infinity).floor(),
94 () => (-Infinity).floor());
95
96 find('NaN.round()',
97 () => confuse(NaN).round(),
98 () => NaN.round());
99 find(' Infinity.round()',
100 () => confuse(Infinity).round(),
101 () => Infinity.round());
102 find('-Infinity.round()',
103 () => confuse(-Infinity).round(),
104 () => (-Infinity).round());
105
106 // `truncate()` is the same as `toInt()`.
107 // We could change the runtime so that `truncate` is reported.
108 find('NaN.toInt()',
109 () => confuse(NaN).truncate(),
110 () => NaN.truncate());
111 find(' Infinity.toInt()',
112 () => confuse(Infinity).truncate(),
113 () => Infinity.truncate());
114 find('-Infinity.toInt()',
115 () => confuse(-Infinity).truncate(),
116 () => (-Infinity).truncate());
117
118 }
119
OLDNEW
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/js_number.dart ('k') | tests/corelib/double_floor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698