Skip to content

Commit

Permalink
Fixes #989. Runtime type equality operator tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Jan 27, 2021
1 parent 6f42695 commit 73f7c6b
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 0 deletions.
33 changes: 33 additions & 0 deletions LanguageFeatures/nnbd/runtime_equality_operator_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
import "../../Utils/expect.dart";

main() {
int i1 = 42;
int i2 = 0;
int? i3 = 11;

Expect.equals(i1.runtimeType, i2.runtimeType);
Expect.equals(i1.runtimeType, i3.runtimeType);

i3 = null;
Expect.notEquals(i1.runtimeType, i3.runtimeType);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/nnbd/runtime_equality_operator_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
import "../../Utils/expect.dart";

class C {}

test<T>(T t1, T t2) {
List<T> l1 = [];
List<T?> l2 = [t1, t2];
Expect.equals(l1.runtimeType, l2.runtimeType);
}

main() {
test<int?>(1, 2);
test<C?>(C(), C());
test<Null>(null, null);
test<dynamic>(1, "2");
test<void>(1, 2);
}
34 changes: 34 additions & 0 deletions LanguageFeatures/nnbd/runtime_equality_operator_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
import "../../Utils/expect.dart";

class C {}

test<T>(T t1, T t2) {
List<T> l1 = [];
List<T?> l2 = [t1, t2];
Expect.notEquals(l1.runtimeType, l2.runtimeType);
}

main() {
test<int>(1, 2);
test<C>(C(), C());
}
36 changes: 36 additions & 0 deletions LanguageFeatures/nnbd/runtime_equality_operator_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
import "dart:async";
import "../../Utils/expect.dart";

test<T1, T2>() {
List<T1> l1 = [];
List<T2> l2 = [];
Expect.equals(l1.runtimeType, l2.runtimeType);
}

main() {
test<Never?, Null>();
test<FutureOr<dynamic>, dynamic>();
test<FutureOr<void>, void>();
test<FutureOr<Object>, Object>();
test<FutureOr<Object?>, Object?>();
}
34 changes: 34 additions & 0 deletions LanguageFeatures/nnbd/runtime_equality_operator_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Note that we do not equate primitive top types. List<void> and
* List<dynamic> are still considered distinct runtime type objects. Note that
* we also do not equate Never and Null, and we do not equate function types
* which differ in the placement of required on parameter types.
*
* @description Checks that primitive types are not equal
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
import "../../Utils/expect.dart";

test<T1, T2>() {
List<T1> l1 = [];
List<T2> l2 = [];
Expect.notEquals(l1.runtimeType, l2.runtimeType);
}

main() {
test<void, dynamic>();
test<Never, Null>();
test<void, Null>();
test<dynamic, Null>();
test<Never, dynamic>();
test<Object?, dynamic>();
test<Never, void>();
}
3 changes: 3 additions & 0 deletions LanguageFeatures/nnbd/weak/legacy_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ class F2<X extends LegacyFoo> {

F1<Function> funcLegacy1 = F1<Function>(legacyFoo);
F2<LegacyFoo> funcLegacy2 = F2<LegacyFoo>(legacyFoo);

int getInt() => 42;
T getType<T>(T t) => t;
33 changes: 33 additions & 0 deletions LanguageFeatures/nnbd/weak/runtime_equality_operator_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-weak
import "../../../Utils/expect.dart";

main() {
int i1 = 42;
int i2 = 0;
int? i3 = 11;

Expect.equals(i1.runtimeType, i2.runtimeType);
Expect.equals(i1.runtimeType, i3.runtimeType);

i3 = null;
Expect.notEquals(i1.runtimeType, i3.runtimeType);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/nnbd/weak/runtime_equality_operator_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-weak
import "../../../Utils/expect.dart";

class C {}

test<T>(T t1, T t2) {
List<T> l1 = [];
List<T?> l2 = [t1, t2];
Expect.equals(l1.runtimeType, l2.runtimeType);
}

main() {
test<int?>(1, 2);
test<C?>(C(), C());
test<Null>(null, null);
test<dynamic>(1, "2");
test<void>(1, 2);
}
34 changes: 34 additions & 0 deletions LanguageFeatures/nnbd/weak/runtime_equality_operator_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-weak
import "../../../Utils/expect.dart";

class C {}

test<T>(T t1, T t2) {
List<T> l1 = [];
List<T?> l2 = [t1, t2];
Expect.notEquals(l1.runtimeType, l2.runtimeType);
}

main() {
test<int>(1, 2);
test<C>(C(), C());
}
36 changes: 36 additions & 0 deletions LanguageFeatures/nnbd/weak/runtime_equality_operator_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-weak
import "../../../Utils/expect.dart";
import "dart:async";

test<T1, T2>() {
List<T1> l1 = [];
List<T2> l2 = [];
Expect.equals(l1.runtimeType, l2.runtimeType);
}

main() {
test<Never?, Null>();
test<FutureOr<dynamic>, dynamic>();
test<FutureOr<void>, void>();
test<FutureOr<Object>, Object>();
test<FutureOr<Object?>, Object?>();
}
44 changes: 44 additions & 0 deletions LanguageFeatures/nnbd/weak/runtime_equality_operator_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion Two objects T1 and T2 which are instances of Type (that is,
* runtime type objects) are considered equal if and only if the runtime type
* objects T1 and T2 corresponds to the types S1 and S2 respectively, and the
* normal forms NORM(S1) and NORM(S2) are syntactically equal up to equivalence
* of bound variables and ignoring * modifiers on types.
*
* @description Checks that runtime type of objects T1 and T2 are equal if and
* only if the runtime type objects T1 and T2 corresponds to the types S1 and S2
* respectively, and the normal forms NORM(S1) and NORM(S2) are syntactically
* equal
*
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-weak
import "../../../Utils/expect.dart";
import "legacy_lib.dart";

main() {
var v1 = getInt();
int v2 = 0;
Expect.equals(v1.runtimeType, v2.runtimeType);

var v3 = getType<int?>(42);
int? v4 = 0;
Expect.equals(v3.runtimeType, v4.runtimeType);
v4 = null;
Expect.notEquals(v3.runtimeType, v4.runtimeType);
v3 = null;
Expect.equals(v3.runtimeType, v4.runtimeType);

var v5 = getType<int>(42);
int v6 = 0;
Expect.equals(v5.runtimeType, v6.runtimeType);

var v7 = getType<dynamic>(42);
dynamic v8 = 0;
Expect.equals(v7.runtimeType, v8.runtimeType);
}
Loading

0 comments on commit 73f7c6b

Please sign in to comment.