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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js_extra/truncation_errors_test.dart
diff --git a/tests/compiler/dart2js_extra/truncation_errors_test.dart b/tests/compiler/dart2js_extra/truncation_errors_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1e3767cf06444f4f05aca4a1d59021d61f2f0ce9
--- /dev/null
+++ b/tests/compiler/dart2js_extra/truncation_errors_test.dart
@@ -0,0 +1,119 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Check that exception messages for truncating operations contains the
+// operands.
+
+import 'package:expect/expect.dart';
+
+@NoInline() @AssumeDynamic()
+confuse(x) => x;
+
+void find1(expected, thunk) {
+ if (thunk == null) return;
+ var returned, exceptionText;
+ try {
+ returned = thunk();
+ } catch (e) {
+ exceptionText = '$e';
+ }
+ if (exceptionText == null) {
+ Expect.fail(
+ 'Expected exception containing "$expected", returned: $returned');
+ }
+ Expect.isTrue(
+ exceptionText.contains(expected),
+ 'Expected "$expected" in "$exceptionText"');
+}
+
+void find(expected, [thunk1, thunk2, thunk3, thunk4]) {
+ find1(expected, thunk1);
+ find1(expected, thunk2);
+ find1(expected, thunk3);
+ find1(expected, thunk4);
+}
+
+main() {
+
+ var NaN = double.NAN;
+ var Infinity = double.INFINITY;
+
+ find(' Infinity: 123 ~/ 0',
+ () => confuse(123) ~/ confuse(0),
+ () => confuse(123) ~/ 0,
+ () => 123 ~/ confuse(0),
+ () => 123 ~/ 0);
+
+ find('-Infinity: 123 ~/ -0.0',
+ () => confuse(123) ~/ confuse(-0.0),
+ () => confuse(123) ~/ -0.0,
+ () => 123 ~/ confuse(-0.0),
+ () => 123 ~/ -0.0);
+
+ find(' NaN: NaN ~/ 123',
+ () => confuse(NaN) ~/ confuse(123),
+ () => confuse(NaN) ~/ 123,
+ () => NaN ~/ confuse(123),
+ () => NaN ~/ 123);
+
+ find(' Infinity: 1e+200 ~/ 1e-200',
+ () => confuse(1e200) ~/ confuse(1e-200),
+ () => confuse(1e200) ~/ 1e-200,
+ () => 1e200 ~/ confuse(1e-200),
+ () => 1e200 ~/ 1e-200);
+
+ find('NaN.toInt()',
+ () => confuse(NaN).toInt(),
+ () => NaN.toInt());
+ find(' Infinity.toInt()',
+ () => confuse(Infinity).toInt(),
+ () => Infinity.toInt());
+ find('-Infinity.toInt()',
+ () => confuse(-Infinity).toInt(),
+ () => (-Infinity).toInt());
+
+ find('NaN.ceil()',
+ () => confuse(NaN).ceil(),
+ () => NaN.ceil());
+ find(' Infinity.ceil()',
+ () => confuse(Infinity).ceil(),
+ () => Infinity.ceil());
+ find('-Infinity.ceil()',
+ () => confuse(-Infinity).ceil(),
+ () => (-Infinity).ceil());
+
+ find('NaN.floor()',
+ () => confuse(NaN).floor(),
+ () => NaN.floor());
+ find(' Infinity.floor()',
+ () => confuse(Infinity).floor(),
+ () => Infinity.floor());
+ find('-Infinity.floor()',
+ () => confuse(-Infinity).floor(),
+ () => (-Infinity).floor());
+
+ find('NaN.round()',
+ () => confuse(NaN).round(),
+ () => NaN.round());
+ find(' Infinity.round()',
+ () => confuse(Infinity).round(),
+ () => Infinity.round());
+ find('-Infinity.round()',
+ () => confuse(-Infinity).round(),
+ () => (-Infinity).round());
+
+ // `truncate()` is the same as `toInt()`.
+ // We could change the runtime so that `truncate` is reported.
+ find('NaN.toInt()',
+ () => confuse(NaN).truncate(),
+ () => NaN.truncate());
+ find(' Infinity.toInt()',
+ () => confuse(Infinity).truncate(),
+ () => Infinity.truncate());
+ find('-Infinity.toInt()',
+ () => confuse(-Infinity).truncate(),
+ () => (-Infinity).truncate());
+
+}
+
« 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