mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:43:57 +00:00
[tests] Fix some tests for web numbers and dart2js production mode
Change-Id: I05a1814f2a2c5810f75708ba72bfafe137122f67 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332486 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Mark Zhou <markzipan@google.com>
This commit is contained in:
parent
e19e4bfaaf
commit
8ee403e86c
|
@ -23,13 +23,18 @@ void main() {
|
|||
Expect.isTrue(f is Foo<Foo<int>>);
|
||||
Expect.isFalse(f is Foo<int>);
|
||||
Expect.isFalse(f is Foo<Object>);
|
||||
Expect.throwsTypeError(() => f(f));
|
||||
Expect.throwsTypeError(() => f(42));
|
||||
if (!dart2jsProductionMode) {
|
||||
Expect.throwsTypeError(() => f(f));
|
||||
Expect.throwsTypeError(() => f(42));
|
||||
}
|
||||
|
||||
Foo<Foo<int>> bazInt = baz; // implicit instantiation baz<int>
|
||||
f = bazInt;
|
||||
Expect.isTrue(f(bar));
|
||||
Expect.isFalse(f is Foo<int>);
|
||||
Expect.throwsTypeError(() => f(f));
|
||||
Expect.throwsTypeError(() => f(42));
|
||||
|
||||
if (!dart2jsProductionMode) {
|
||||
Expect.throwsTypeError(() => f(f));
|
||||
Expect.throwsTypeError(() => f(42));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class C<T> {
|
|||
void test(String nameOfT, bool expectedResult) {
|
||||
check(bool expectedResult, f()) {
|
||||
if (!expectedResult) {
|
||||
Expect.throwsTypeError(f);
|
||||
if (!dart2jsProductionMode) Expect.throwsTypeError(f);
|
||||
} else {
|
||||
f();
|
||||
}
|
||||
|
|
|
@ -8,13 +8,21 @@ var myIdentical = identical;
|
|||
|
||||
main() {
|
||||
// Mint (2^63).
|
||||
// TODO(rnystrom): Figure out how to change this to work on the web.
|
||||
Expect.isTrue(myIdentical(0x8000000000000000, 0x8000000000000000));
|
||||
Expect.isFalse(myIdentical(0x8000000000000000, 0x8000000000000001));
|
||||
|
||||
// Different types.
|
||||
Expect.isFalse(myIdentical(42, 42.0));
|
||||
if (!webNumbers) {
|
||||
Expect.isFalse(myIdentical(0x8000000000000000, 0x8000000000000000 + 1));
|
||||
|
||||
// NaN handling.
|
||||
Expect.isTrue(myIdentical(double.nan, double.nan));
|
||||
// Different types.
|
||||
Expect.isFalse(myIdentical(42, 42.0));
|
||||
|
||||
// NaN handling.
|
||||
Expect.isTrue(myIdentical(double.nan, double.nan));
|
||||
} else {
|
||||
// Web numbers have less precision, conflate int and double values, and have
|
||||
// an incorrect implementation of `identical` for NaNs.
|
||||
Expect.isTrue(myIdentical(0x8000000000000000, 0x8000000000000000 + 1));
|
||||
Expect.isTrue(myIdentical(42, 42.0));
|
||||
Expect.isFalse(myIdentical(double.nan, double.nan));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,7 @@ main() {
|
|||
// Null handling.
|
||||
Expect.isFalse(myIdentical(42, null));
|
||||
Expect.isTrue(myIdentical(null, null));
|
||||
|
||||
// Assigning to the variable prevents dart2js from optimizing calls.
|
||||
myIdentical = identical;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,22 @@ double createOtherNAN() {
|
|||
}
|
||||
|
||||
main() {
|
||||
if (webNumbers) {
|
||||
// (1) The web compilers elect to generate smaller, faster code for
|
||||
// `identical` using `===`, with the result that `identical(NaN, NaN)` is
|
||||
// false.
|
||||
//
|
||||
// (2) In JavaScript different NaN values are treated the same by
|
||||
// `Object.is`, and can only be distinguished by writing the bits into typed
|
||||
// data, making it costly to compare NaN values.
|
||||
|
||||
// Validate current behaviour so we will be alerted if (1) changes.
|
||||
Expect.isFalse(checkIdentical(double.nan, -double.nan));
|
||||
Expect.isFalse(checkIdentical(double.nan, double.nan));
|
||||
Expect.isFalse(checkIdentical(-double.nan, -double.nan));
|
||||
return;
|
||||
}
|
||||
|
||||
var otherNAN = createOtherNAN();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Expect.isFalse(checkIdentical(double.nan, -double.nan));
|
||||
|
|
Loading…
Reference in a new issue