OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // This tests uses the multi-test "ok" feature: | 5 // This tests uses the multi-test "ok" feature: |
6 // none: Trimmed behaviour. Passing on the VM. | 6 // none: Trimmed behaviour. Passing on the VM. |
7 // 01: Trimmed version for dart2js. | 7 // 01: Trimmed version for dart2js. |
8 // 02: Full version passing in the VM. | 8 // 02: Full version passing in the VM. |
9 // | 9 // |
10 // TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par. | 10 // TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par. |
11 | 11 |
12 library test.class_equality_test; | 12 library test.class_equality_test; |
13 | 13 |
14 import 'dart:mirrors'; | 14 import 'dart:mirrors'; |
15 | 15 |
16 import 'package:expect/expect.dart'; | 16 import 'package:expect/expect.dart'; |
17 | 17 |
18 class A<T> {} | 18 class A<T> {} |
19 class B extends A<int> {} | 19 class B extends A<int> {} |
20 | 20 |
21 class BadEqualityHash { | 21 class BadEqualityHash { |
22 int count = 0; | 22 int count = 0; |
23 bool operator ==(other) => true; | 23 bool operator ==(other) => true; |
24 int get hashCode => count++; | 24 int get hashCode => count++; |
25 } | 25 } |
26 | 26 |
| 27 typedef bool Predicate(Object o); |
| 28 Predicate somePredicate; |
| 29 |
27 checkEquality(List<Map> equivalenceClasses) { | 30 checkEquality(List<Map> equivalenceClasses) { |
28 for (var equivalenceClass in equivalenceClasses) { | 31 for (var equivalenceClass in equivalenceClasses) { |
29 equivalenceClass.forEach((name, member) { | 32 equivalenceClass.forEach((name, member) { |
30 equivalenceClass.forEach((otherName, otherMember) { | 33 equivalenceClass.forEach((otherName, otherMember) { |
31 // Reflexivity, symmetry and transitivity. | 34 // Reflexivity, symmetry and transitivity. |
32 Expect.equals(member, | 35 Expect.equals(member, |
33 otherMember, | 36 otherMember, |
34 "$name == $otherName"); | 37 "$name == $otherName"); |
35 Expect.equals(member.hashCode, | 38 Expect.equals(member.hashCode, |
36 otherMember.hashCode, | 39 otherMember.hashCode, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 'reflect(new A<int>()).type.originalDeclaration' : | 113 'reflect(new A<int>()).type.originalDeclaration' : |
111 reflect(new A<int>()).type.originalDeclaration}, | 114 reflect(new A<int>()).type.originalDeclaration}, |
112 | 115 |
113 {'reflectClass(B).superclass' : reflectClass(B).superclass, /// 02: ok | 116 {'reflectClass(B).superclass' : reflectClass(B).superclass, /// 02: ok |
114 'reflect(new A<int>()).type' : reflect(new A<int>()).type}, /// 02: ok | 117 'reflect(new A<int>()).type' : reflect(new A<int>()).type}, /// 02: ok |
115 | 118 |
116 {'reflectClass(B)' : reflectClass(B), | 119 {'reflectClass(B)' : reflectClass(B), |
117 'thisLibrary.classes[#B]' : thisLibrary.classes[#B], | 120 'thisLibrary.classes[#B]' : thisLibrary.classes[#B], |
118 'reflect(new B()).type' : reflect(new B()).type}, | 121 'reflect(new B()).type' : reflect(new B()).type}, |
119 | 122 |
| 123 {'reflectClass(BadEqualityHash).methods[#==]' /// 02: ok |
| 124 : reflectClass(BadEqualityHash).methods[#==], /// 02: ok |
| 125 'reflect(new BadEqualityHash()).type.methods[#==]' /// 02: ok |
| 126 : reflect(new BadEqualityHash()).type.methods[#==]}, /// 02: ok |
| 127 |
| 128 {'reflectClass(BadEqualityHash).methods[#==].parameters[0]' /// 02: ok |
| 129 : reflectClass(BadEqualityHash).methods[#==].parameters[0], /// 02: ok |
| 130 'reflect(new BadEqualityHash()).type.methods[#==].parameters[0]' /// 02: o
k |
| 131 : reflect(new BadEqualityHash()).type.methods[#==].parameters[0]}, ///
02: ok |
| 132 |
| 133 {'reflectClass(BadEqualityHash).variables[#count]' /// 02: ok |
| 134 : reflectClass(BadEqualityHash).variables[#count], /// 02: ok |
| 135 'reflect(new BadEqualityHash()).type.variables[#count]' /// 02: ok |
| 136 : reflect(new BadEqualityHash()).type.variables[#count]}, /// 02: ok |
| 137 |
| 138 {'reflectType(Predicate)' : reflectType(Predicate), /// 02: ok |
| 139 'thisLibrary.variables[#somePredicate].type' /// 02: ok |
| 140 : thisLibrary.variables[#somePredicate].type}, /// 02: ok |
| 141 |
| 142 {'reflectType(Predicate).referent' : reflectType(Predicate).referent, /// 0
2: ok |
| 143 'thisLibrary.variables[#somePredicate].type.referent' /// 02: ok |
| 144 : thisLibrary.variables[#somePredicate].type.referent}, /// 02: ok |
| 145 |
| 146 {'reflectClass(A).typeVariables.single' /// 02: ok |
| 147 : reflectClass(A).typeVariables.single, /// 02: ok |
| 148 'reflect(new A<int>()).type.originalDeclaration.typeVariables.single' ///
02: ok |
| 149 : reflect(new A<int>()).type.originalDeclaration.typeVariables.single},
/// 02: ok |
| 150 |
| 151 {'currentMirrorSystem()' : currentMirrorSystem()}, |
| 152 |
| 153 {'currentMirrorSystem().isolate' : currentMirrorSystem().isolate}, |
| 154 |
120 {'thisLibrary' : thisLibrary, | 155 {'thisLibrary' : thisLibrary, |
121 'reflectClass(A).owner' : reflectClass(A).owner, | 156 'reflectClass(A).owner' : reflectClass(A).owner, |
122 'reflectClass(B).owner' : reflectClass(B).owner, | 157 'reflectClass(B).owner' : reflectClass(B).owner, |
123 'reflect(new A()).type.owner' : reflect(new A()).type.owner, | 158 'reflect(new A()).type.owner' : reflect(new A()).type.owner, |
124 'reflect(new B()).type.owner' : reflect(new B()).type.owner}, | 159 'reflect(new B()).type.owner' : reflect(new B()).type.owner}, |
125 ]); | 160 ]); |
126 } | 161 } |
OLD | NEW |