mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 13:08:10 +00:00
Migrate language_2/identity to NNBD.
Change-Id: Ie2940ca89811d02cb9b51cb7ea1fc939c872d149 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148147 Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
166d083389
commit
e11cac8d8b
20
tests/language/identity/closure2_test.dart
Normal file
20
tests/language/identity/closure2_test.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
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));
|
||||
|
||||
// NaN handling.
|
||||
Expect.isTrue(myIdentical(double.nan, double.nan));
|
||||
}
|
44
tests/language/identity/closure_test.dart
Normal file
44
tests/language/identity/closure_test.dart
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
var myIdentical = identical;
|
||||
|
||||
class Point {
|
||||
num x, y;
|
||||
Point(this.x, this.y);
|
||||
}
|
||||
|
||||
main() {
|
||||
// int.
|
||||
Expect.isTrue(myIdentical(42, 42));
|
||||
Expect.isFalse(myIdentical(42, 41));
|
||||
|
||||
// double.
|
||||
Expect.isTrue(myIdentical(42.0, 42.0));
|
||||
Expect.isFalse(myIdentical(42.0, 41.0));
|
||||
|
||||
// Mint (2^45).
|
||||
Expect.isTrue(myIdentical(35184372088832, 35184372088832));
|
||||
Expect.isFalse(myIdentical(35184372088832, 35184372088831));
|
||||
|
||||
// Different types.
|
||||
Expect.isFalse(myIdentical("hello", 41));
|
||||
|
||||
// Points.
|
||||
var p = new Point(1, 1);
|
||||
var q = new Point(1, 1);
|
||||
Expect.isFalse(myIdentical(p, q));
|
||||
|
||||
// Strings.
|
||||
var a = "hello";
|
||||
var b = "hello";
|
||||
// Identical strings are coalesced into single instances.
|
||||
Expect.isTrue(myIdentical(a, b));
|
||||
|
||||
// Null handling.
|
||||
Expect.isFalse(myIdentical(42, null));
|
||||
Expect.isTrue(myIdentical(null, null));
|
||||
}
|
39
tests/language/identity/const_test.dart
Normal file
39
tests/language/identity/const_test.dart
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
f() {}
|
||||
const g = 1;
|
||||
|
||||
const identical_ff = identical(f, f);
|
||||
const identical_fg = identical(f, g);
|
||||
const identical_gf = identical(g, f);
|
||||
const identical_gg = identical(g, g);
|
||||
|
||||
// Verify proper compile time computation of identical()
|
||||
const a = const {
|
||||
identical_ff: 0, //# 01: compile-time error
|
||||
identical_gg: 0, //# 02: compile-time error
|
||||
true: 0
|
||||
};
|
||||
|
||||
const b = const {
|
||||
identical_fg: 0, //# 03: compile-time error
|
||||
identical_gf: 0, //# 04: compile-time error
|
||||
false: 0
|
||||
};
|
||||
|
||||
use(x) => x;
|
||||
|
||||
main() {
|
||||
use(a);
|
||||
use(b);
|
||||
|
||||
// Verify proper run time computation of identical()
|
||||
Expect.isTrue(identical_ff); //# 05: ok
|
||||
Expect.isTrue(identical_gg); //# 06: ok
|
||||
Expect.isFalse(identical_fg); //# 07: ok
|
||||
Expect.isFalse(identical_gf); //# 08: ok
|
||||
}
|
39
tests/language/identity/identical_test.dart
Normal file
39
tests/language/identity/identical_test.dart
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
// Test efficient and correct implementation of !identical(a, b).
|
||||
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
notIdenticalTest1(a) {
|
||||
if (!identical("ho", a)) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
notIdenticalTest2(a) {
|
||||
var x = identical("ho", a);
|
||||
if (!x) {
|
||||
Expect.equals(false, x);
|
||||
return x;
|
||||
} else {
|
||||
Expect.equals(true, x);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
notIdenticalTest3(a) {
|
||||
var x = identical("ho", a);
|
||||
return !x;
|
||||
}
|
||||
|
||||
main() {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Expect.equals(1, notIdenticalTest1("ho"));
|
||||
Expect.equals(1, notIdenticalTest2("ho"));
|
||||
Expect.equals(false, notIdenticalTest3("ho"));
|
||||
}
|
||||
}
|
17
tests/language/identity/mint_identical_test.dart
Normal file
17
tests/language/identity/mint_identical_test.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2018, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
// Smis on 64-bit.
|
||||
Expect.isTrue(identical(2305843009213693952, 2305843009213693952));
|
||||
Expect.isTrue(identical(2305843009213693953, 2305843009213693953));
|
||||
Expect.isTrue(identical(2305843009213693954, 2305843009213693954));
|
||||
Expect.isTrue(identical(4611686018427387903, 4611686018427387903));
|
||||
|
||||
// Mints on 64-bit.
|
||||
Expect.isTrue(identical(4611686018427387904, 4611686018427387904));
|
||||
Expect.isTrue(identical(4611686018427387905, 4611686018427387905));
|
||||
}
|
51
tests/language/identity/nan_identical_test.dart
Normal file
51
tests/language/identity/nan_identical_test.dart
Normal file
|
@ -0,0 +1,51 @@
|
|||
// 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.
|
||||
// Test a new statement by itself.
|
||||
// VMOptions=--optimization-counter-threshold=4 --no-use-osr
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
double uint64toDouble(int i) {
|
||||
var buffer = new Uint8List(8).buffer;
|
||||
var bdata = new ByteData.view(buffer);
|
||||
bdata.setUint64(0, i);
|
||||
return bdata.getFloat64(0);
|
||||
}
|
||||
|
||||
double createOtherNAN() {
|
||||
return uint64toDouble((1 << 64) - 2);
|
||||
}
|
||||
|
||||
main() {
|
||||
var otherNAN = createOtherNAN();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Expect.isFalse(checkIdentical(double.nan, -double.nan));
|
||||
Expect.isTrue(checkIdentical(double.nan, double.nan));
|
||||
Expect.isTrue(checkIdentical(-double.nan, -double.nan));
|
||||
|
||||
Expect.isFalse(checkIdentical(otherNAN, -otherNAN));
|
||||
Expect.isTrue(checkIdentical(otherNAN, otherNAN));
|
||||
Expect.isTrue(checkIdentical(-otherNAN, -otherNAN));
|
||||
|
||||
var a = otherNAN;
|
||||
var b = double.nan;
|
||||
Expect.isFalse(checkIdentical(a, b));
|
||||
Expect.isFalse(checkIdentical(-a, -b));
|
||||
Expect.isFalse(checkIdentical(-a, b));
|
||||
Expect.isFalse(checkIdentical(a, -b));
|
||||
|
||||
a = -a;
|
||||
Expect.isFalse(checkIdentical(a, b));
|
||||
Expect.isFalse(checkIdentical(-a, -b));
|
||||
Expect.isFalse(checkIdentical(-a, b));
|
||||
Expect.isFalse(checkIdentical(a, -b));
|
||||
|
||||
Expect.isTrue(checkIdentical(-(-a), a));
|
||||
Expect.isTrue(checkIdentical(-(-b), b));
|
||||
}
|
||||
}
|
||||
|
||||
checkIdentical(a, b) => identical(a, b);
|
128
tests/language/identity/strict_equal_test.dart
Normal file
128
tests/language/identity/strict_equal_test.dart
Normal file
|
@ -0,0 +1,128 @@
|
|||
// Copyright (c) 2011, 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.
|
||||
// VMOptions=--optimization-counter-threshold=10
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Expect.isFalse(test1(5));
|
||||
Expect.isTrue(test1(3));
|
||||
|
||||
Expect.isTrue(test2(5));
|
||||
Expect.isFalse(test2(3));
|
||||
|
||||
Expect.isTrue(test2r(5));
|
||||
Expect.isFalse(test2r(3));
|
||||
|
||||
Expect.isTrue(test3());
|
||||
|
||||
Expect.equals(2, test4(5));
|
||||
Expect.equals(1, test4(3));
|
||||
|
||||
Expect.equals(1, test5(5));
|
||||
Expect.equals(2, test5(3));
|
||||
|
||||
Expect.equals(1, test6());
|
||||
|
||||
Expect.isFalse(test7());
|
||||
Expect.equals(2, test8());
|
||||
|
||||
Expect.isFalse(test9(2));
|
||||
Expect.isFalse(test9r(2));
|
||||
Expect.isTrue(test9(0));
|
||||
Expect.isTrue(test9r(0));
|
||||
|
||||
Expect.isFalse(test10(0));
|
||||
Expect.isFalse(test10r(0));
|
||||
Expect.isTrue(test10(2));
|
||||
Expect.isTrue(test10r(2));
|
||||
|
||||
test11(i);
|
||||
}
|
||||
}
|
||||
|
||||
test1(a) {
|
||||
return identical(a, 3);
|
||||
}
|
||||
|
||||
test2(a) {
|
||||
return !identical(a, 3);
|
||||
}
|
||||
|
||||
test2r(a) {
|
||||
return !identical(3, a);
|
||||
}
|
||||
|
||||
test3() {
|
||||
return identical(get5(), 5);
|
||||
}
|
||||
|
||||
test4(a) {
|
||||
if (identical(a, 3)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
test5(a) {
|
||||
if (!identical(a, 3)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
test6() {
|
||||
if (identical(get5(), 5)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
get5() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
test7() {
|
||||
return null != null;
|
||||
}
|
||||
|
||||
test8() {
|
||||
if (null != null) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
test9(a) {
|
||||
return identical(a, 0);
|
||||
}
|
||||
|
||||
test9r(a) {
|
||||
return identical(0, a);
|
||||
}
|
||||
|
||||
test10(a) {
|
||||
return !identical(a, 0);
|
||||
}
|
||||
|
||||
test10r(a) {
|
||||
return !identical(0, a);
|
||||
}
|
||||
|
||||
test11(a) {
|
||||
if (identical(a, 0)) {
|
||||
Expect.isTrue(identical(0, a));
|
||||
Expect.isFalse(!identical(a, 0));
|
||||
Expect.isFalse(!identical(0, a));
|
||||
} else {
|
||||
Expect.isFalse(identical(0, a));
|
||||
Expect.isTrue(!identical(a, 0));
|
||||
Expect.isTrue(!identical(0, a));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue