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

Side by Side Diff: tests/lib_strong/mirrors/equality_test.dart

Issue 3011633002: Added back helper file accidentally deleted during test block 219 migration. (Closed)
Patch Set: Created 3 years, 3 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 unified diff | Download patch
« no previous file with comments | « tests/lib_strong/mirrors/enum_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This tests uses the multi-test "ok" feature:
6 // none: Trimmed behaviour. Passing on the VM.
7 // 01: Trimmed version for dart2js.
8 // 02: Full version passing in the VM.
9 //
10 // TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par.
11
12 library test.class_equality_test;
13
14 import 'dart:mirrors';
15
16 import 'package:expect/expect.dart';
17
18 class A<T> {}
19
20 class B extends A<int> {}
21
22 class BadEqualityHash {
23 int count = 0;
24 bool operator ==(other) => true;
25 int get hashCode => count++;
26 }
27
28 typedef bool Predicate(Object o);
29 Predicate somePredicate;
30
31 checkEquality(List<Map> equivalenceClasses) {
32 for (var equivalenceClass in equivalenceClasses) {
33 equivalenceClass.forEach((name, member) {
34 equivalenceClass.forEach((otherName, otherMember) {
35 // Reflexivity, symmetry and transitivity.
36 Expect.equals(member, otherMember, "$name == $otherName");
37 Expect.equals(member.hashCode, otherMember.hashCode,
38 "$name.hashCode == $otherName.hashCode");
39 });
40 for (var otherEquivalenceClass in equivalenceClasses) {
41 if (otherEquivalenceClass == equivalenceClass) continue;
42 otherEquivalenceClass.forEach((otherName, otherMember) {
43 Expect.notEquals(
44 member, otherMember, "$name != $otherName"); // Exclusion.
45 // Hash codes may or may not be equal.
46 });
47 }
48 });
49 }
50 }
51
52 void subroutine() {}
53
54 main() {
55 LibraryMirror thisLibrary = currentMirrorSystem()
56 .findLibrary(const Symbol('test.class_equality_test'));
57
58 var o1 = new Object();
59 var o2 = new Object();
60
61 var badEqualityHash1 = new BadEqualityHash();
62 var badEqualityHash2 = new BadEqualityHash();
63
64 checkEquality([
65 {'reflect(o1)': reflect(o1), 'reflect(o1), again': reflect(o1)},
66 {'reflect(o2)': reflect(o2), 'reflect(o2), again': reflect(o2)},
67 {
68 'reflect(badEqualityHash1)': reflect(badEqualityHash1),
69 'reflect(badEqualityHash1), again': reflect(badEqualityHash1)
70 },
71 {
72 'reflect(badEqualityHash2)': reflect(badEqualityHash2),
73 'reflect(badEqualityHash2), again': reflect(badEqualityHash2)
74 },
75 {'reflect(true)': reflect(true), 'reflect(true), again': reflect(true)},
76 {'reflect(false)': reflect(false), 'reflect(false), again': reflect(false)},
77 {'reflect(null)': reflect(null), 'reflect(null), again': reflect(null)},
78 {
79 'reflect(3.5+4.5)': reflect(3.5 + 4.5),
80 'reflect(6.5+1.5)': reflect(6.5 + 1.5)
81 },
82 {'reflect(3+4)': reflect(3 + 4), 'reflect(6+1)': reflect(6 + 1)},
83 {'reflect("foo")': reflect("foo"), 'reflect("foo"), again': reflect("foo")},
84 {
85 'currentMirrorSystem().voidType': currentMirrorSystem().voidType,
86 'thisLibrary.declarations[#subroutine].returnType':
87 (thisLibrary.declarations[#subroutine] as MethodMirror).returnType
88 },
89 {
90 'currentMirrorSystem().dynamicType': currentMirrorSystem().dynamicType,
91 'thisLibrary.declarations[#main].returnType':
92 (thisLibrary.declarations[#main] as MethodMirror).returnType
93 },
94 {
95 'reflectClass(A)': reflectClass(A),
96 'thisLibrary.declarations[#A]': thisLibrary.declarations[#A],
97 'reflect(new A<int>()).type.originalDeclaration':
98 reflect(new A<int>()).type.originalDeclaration
99 },
100 {
101 'reflectClass(B).superclass': reflectClass(B).superclass,
102 'reflect(new A<int>()).type': reflect(new A<int>()).type
103 },
104 {
105 'reflectClass(B)': reflectClass(B),
106 'thisLibrary.declarations[#B]': thisLibrary.declarations[#B],
107 'reflect(new B()).type': reflect(new B()).type
108 },
109 {
110 'reflectClass(BadEqualityHash).declarations[#==]':
111 reflectClass(BadEqualityHash).declarations[#==],
112 'reflect(new BadEqualityHash()).type.declarations[#==]':
113 reflect(new BadEqualityHash()).type.declarations[#==]
114 },
115 {
116 'reflectClass(BadEqualityHash).declarations[#==].parameters[0]':
117 (reflectClass(BadEqualityHash).declarations[#==] as MethodMirror)
118 .parameters[0],
119 'reflect(new BadEqualityHash()).type.declarations[#==].parameters[0]':
120 (reflect(new BadEqualityHash()).type.declarations[#==]
121 as MethodMirror)
122 .parameters[0]
123 },
124 {
125 'reflectClass(BadEqualityHash).declarations[#count]':
126 reflectClass(BadEqualityHash).declarations[#count],
127 'reflect(new BadEqualityHash()).type.declarations[#count]':
128 reflect(new BadEqualityHash()).type.declarations[#count]
129 },
130 {
131 'reflectType(Predicate)': reflectType(Predicate),
132 'thisLibrary.declarations[#somePredicate].type':
133 (thisLibrary.declarations[#somePredicate] as VariableMirror).type
134 },
135 {
136 'reflectType(Predicate).referent':
137 (reflectType(Predicate) as TypedefMirror).referent,
138 'thisLibrary.declarations[#somePredicate].type.referent':
139 ((thisLibrary.declarations[#somePredicate] as VariableMirror).type
140 as TypedefMirror)
141 .referent
142 },
143 {
144 'reflectClass(A).typeVariables.single':
145 reflectClass(A).typeVariables.single,
146 'reflect(new A<int>()).type.originalDeclaration.typeVariables.single':
147 reflect(new A<int>()).type.originalDeclaration.typeVariables.single
148 },
149 {'currentMirrorSystem()': currentMirrorSystem()},
150 {'currentMirrorSystem().isolate': currentMirrorSystem().isolate},
151 {
152 'thisLibrary': thisLibrary,
153 'reflectClass(A).owner': reflectClass(A).owner,
154 'reflectClass(B).owner': reflectClass(B).owner,
155 'reflect(new A()).type.owner': reflect(new A()).type.owner,
156 'reflect(new B()).type.owner': reflect(new B()).type.owner
157 },
158 ]);
159 }
OLDNEW
« no previous file with comments | « tests/lib_strong/mirrors/enum_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698