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

Side by Side Diff: test/codegen/lib/mirrors/equality_test.dart

Issue 2265533002: Add mirrors tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 4 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
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 class B extends A<int> {}
20
21 class BadEqualityHash {
22 int count = 0;
23 bool operator ==(other) => true;
24 int get hashCode => count++;
25 }
26
27 typedef bool Predicate(Object o);
28 Predicate somePredicate;
29
30 checkEquality(List<Map> equivalenceClasses) {
31 for (var equivalenceClass in equivalenceClasses) {
32 equivalenceClass.forEach((name, member) {
33 equivalenceClass.forEach((otherName, otherMember) {
34 // Reflexivity, symmetry and transitivity.
35 Expect.equals(member,
36 otherMember,
37 "$name == $otherName");
38 Expect.equals(member.hashCode,
39 otherMember.hashCode,
40 "$name.hashCode == $otherName.hashCode");
41 });
42 for (var otherEquivalenceClass in equivalenceClasses) {
43 if (otherEquivalenceClass == equivalenceClass) continue;
44 otherEquivalenceClass.forEach((otherName, otherMember) {
45 Expect.notEquals(member,
46 otherMember,
47 "$name != $otherName"); // Exclusion.
48 // Hash codes may or may not be equal.
49 });
50 }
51 });
52 }
53 }
54
55 void subroutine() {
56 }
57
58 main() {
59 LibraryMirror thisLibrary =
60 currentMirrorSystem()
61 .findLibrary(const Symbol('test.class_equality_test'));
62
63 var o1 = new Object();
64 var o2 = new Object();
65
66 var badEqualityHash1 = new BadEqualityHash();
67 var badEqualityHash2 = new BadEqualityHash();
68
69 checkEquality([
70 {'reflect(o1)' : reflect(o1),
71 'reflect(o1), again' : reflect(o1)},
72
73 {'reflect(o2)' : reflect(o2),
74 'reflect(o2), again' : reflect(o2)},
75
76 {'reflect(badEqualityHash1)' : reflect(badEqualityHash1),
77 'reflect(badEqualityHash1), again' : reflect(badEqualityHash1)},
78
79 {'reflect(badEqualityHash2)' : reflect(badEqualityHash2),
80 'reflect(badEqualityHash2), again' : reflect(badEqualityHash2)},
81
82 {'reflect(true)' : reflect(true),
83 'reflect(true), again' : reflect(true)},
84
85 {'reflect(false)' : reflect(false),
86 'reflect(false), again' : reflect(false)},
87
88 {'reflect(null)' : reflect(null),
89 'reflect(null), again' : reflect(null)},
90
91 {'reflect(3.5+4.5)' : reflect(3.5+4.5),
92 'reflect(6.5+1.5)' : reflect(6.5+1.5)},
93
94 {'reflect(3+4)' : reflect(3+4),
95 'reflect(6+1)' : reflect(6+1)},
96
97 {'reflect("foo")' : reflect("foo"),
98 'reflect("foo"), again' : reflect("foo")},
99
100 {'currentMirrorSystem().voidType' : currentMirrorSystem().voidType,
101 'thisLibrary.declarations[#subroutine].returnType' :
102 (thisLibrary.declarations[#subroutine] as MethodMirror).returnType},
103
104 {'currentMirrorSystem().dynamicType' : currentMirrorSystem().dynamicType,
105 'thisLibrary.declarations[#main].returnType' :
106 (thisLibrary.declarations[#main] as MethodMirror).returnType},
107
108 {'reflectClass(A)' : reflectClass(A),
109 'thisLibrary.declarations[#A]' : thisLibrary.declarations[#A],
110 'reflect(new A<int>()).type.originalDeclaration' :
111 reflect(new A<int>()).type.originalDeclaration},
112
113 {'reflectClass(B).superclass' : reflectClass(B).superclass,
114 'reflect(new A<int>()).type' : reflect(new A<int>()).type},
115
116 {'reflectClass(B)' : reflectClass(B),
117 'thisLibrary.declarations[#B]' : thisLibrary.declarations[#B],
118 'reflect(new B()).type' : reflect(new B()).type},
119
120 {'reflectClass(BadEqualityHash).declarations[#==]'
121 : reflectClass(BadEqualityHash).declarations[#==],
122 'reflect(new BadEqualityHash()).type.declarations[#==]'
123 : reflect(new BadEqualityHash()).type.declarations[#==]},
124
125 {'reflectClass(BadEqualityHash).declarations[#==].parameters[0]'
126 : (reflectClass(BadEqualityHash).
127 declarations[#==] as MethodMirror).parameters[0],
128 'reflect(new BadEqualityHash()).type.declarations[#==].parameters[0]'
129 : (reflect(new BadEqualityHash()).type.
130 declarations[#==] as MethodMirror).parameters[0]},
131
132 {'reflectClass(BadEqualityHash).declarations[#count]'
133 : reflectClass(BadEqualityHash).declarations[#count],
134 'reflect(new BadEqualityHash()).type.declarations[#count]'
135 : reflect(new BadEqualityHash()).type.declarations[#count]},
136
137 {'reflectType(Predicate)' : reflectType(Predicate),
138 'thisLibrary.declarations[#somePredicate].type'
139 : (thisLibrary.declarations[#somePredicate] as VariableMirror).type},
140
141 {'reflectType(Predicate).referent' : (reflectType(Predicate) as TypedefMirro r).referent,
142 'thisLibrary.declarations[#somePredicate].type.referent'
143 : ((thisLibrary.declarations[#somePredicate] as VariableMirror).type as TypedefMirror).referent},
144
145 {'reflectClass(A).typeVariables.single'
146 : reflectClass(A).typeVariables.single,
147 'reflect(new A<int>()).type.originalDeclaration.typeVariables.single'
148 : reflect(new A<int>()).type.originalDeclaration.typeVariables.single},
149
150 {'currentMirrorSystem()' : currentMirrorSystem()},
151
152 {'currentMirrorSystem().isolate' : currentMirrorSystem().isolate},
153
154 {'thisLibrary' : thisLibrary,
155 'reflectClass(A).owner' : reflectClass(A).owner,
156 'reflectClass(B).owner' : reflectClass(B).owner,
157 'reflect(new A()).type.owner' : reflect(new A()).type.owner,
158 'reflect(new B()).type.owner' : reflect(new B()).type.owner},
159 ]);
160 }
OLDNEW
« no previous file with comments | « test/codegen/lib/mirrors/enum_test.dart ('k') | test/codegen/lib/mirrors/fake_function_with_call_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698