Skip to content

Commit

Permalink
[tests] Fix web-number edge cases in language/operator/modulo_test
Browse files Browse the repository at this point in the history
Change-Id: Ia2b919afa3fca7f78c50a3ea089abe4da8dca8c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332372
Reviewed-by: Mark Zhou <[email protected]>
Commit-Queue: Stephen Adams <[email protected]>
  • Loading branch information
rakudrama authored and Commit Queue committed Oct 27, 2023
1 parent 2f52ffa commit 5e8e6aa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/language/operator/modulo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ main() {
for (int i = -30; i < 30; i++) {
Expect.equals(i % 256, foo(i));
Expect.equals(i % -256, boo(i));
Expect.throws(() => hoo(i), (e) => e is UnsupportedError);

if (!webNumbers) {
Expect.throws(() => hoo(i), (e) => e is UnsupportedError);
} else {
// web numbers can't distinguish doubles from ints, so `i % 0`, which
// should throw, is evaluated as `i % 0.0`, which yields NaN.
Expect.isTrue(hoo(i).isNaN);
}

Expect.equals(i ~/ 254 + i % 254, fooTwo(i));
Expect.equals(i ~/ -254 + i % -254, booTwo(i));
Expand All @@ -35,7 +42,13 @@ main() {
Expect.equals(i ~/ i + i % i, fooTwo2(i));
}
}
Expect.throws(() => foo2(0), (e) => e is UnsupportedError);
if (!webNumbers) {
Expect.throws(() => foo2(0), (e) => e is UnsupportedError);
} else {
// web numbers can't distinguish doubles from ints, so `0 % 0`, which should
// throw, is evaluated as `0.0 % 0.0`, which yields NaN.
Expect.isTrue(foo2(0).isNaN);
}
Expect.throws(() => fooTwo2(0), (e) => e is UnsupportedError);
}

Expand Down

0 comments on commit 5e8e6aa

Please sign in to comment.