| 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 library test.class_equality_test; | 5 library test.class_equality_test; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 | 10 |
| 11 class A<T> {} | 11 class A<T> {} |
| 12 class B extends A<int> {} | 12 class B extends A<int> {} |
| 13 | 13 |
| 14 class BadEqualityHash { |
| 15 int count = 0; |
| 16 bool operator ==(other) => true; |
| 17 int get hashCode => count++; |
| 18 } |
| 19 |
| 14 checkEquality(List<Map> equivalenceClasses) { | 20 checkEquality(List<Map> equivalenceClasses) { |
| 15 for (var equivalenceClass in equivalenceClasses) { | 21 for (var equivalenceClass in equivalenceClasses) { |
| 16 equivalenceClass.forEach((name, member) { | 22 equivalenceClass.forEach((name, member) { |
| 17 equivalenceClass.forEach((otherName, otherMember) { | 23 equivalenceClass.forEach((otherName, otherMember) { |
| 18 // Reflexivity, symmetry and transitivity. | 24 // Reflexivity, symmetry and transitivity. |
| 19 Expect.equals(member, | 25 Expect.equals(member, |
| 20 otherMember, | 26 otherMember, |
| 21 "$name == $otherName"); | 27 "$name == $otherName"); |
| 22 Expect.equals(member.hashCode, | 28 Expect.equals(member.hashCode, |
| 23 otherMember.hashCode, | 29 otherMember.hashCode, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 | 44 |
| 39 void subroutine() { | 45 void subroutine() { |
| 40 } | 46 } |
| 41 | 47 |
| 42 main() { | 48 main() { |
| 43 LibraryMirror thisLibrary = | 49 LibraryMirror thisLibrary = |
| 44 currentMirrorSystem() | 50 currentMirrorSystem() |
| 45 .findLibrary(const Symbol('test.class_equality_test')) | 51 .findLibrary(const Symbol('test.class_equality_test')) |
| 46 .single; | 52 .single; |
| 47 | 53 |
| 48 Object o1 = new Object(); | 54 var o1 = new Object(); |
| 49 Object o2 = new Object(); | 55 var o2 = new Object(); |
| 56 |
| 57 var badEqualityHash1 = new BadEqualityHash(); |
| 58 var badEqualityHash2 = new BadEqualityHash(); |
| 50 | 59 |
| 51 checkEquality([ | 60 checkEquality([ |
| 52 {'reflect(o1)' : reflect(o1), | 61 {'reflect(o1)' : reflect(o1), |
| 53 'reflect(o1), again' : reflect(o1)}, | 62 'reflect(o1), again' : reflect(o1)}, |
| 54 | 63 |
| 55 {'reflect(o2)' : reflect(o2), | 64 {'reflect(o2)' : reflect(o2), |
| 56 'reflect(o2), again' : reflect(o2)}, | 65 'reflect(o2), again' : reflect(o2)}, |
| 57 | 66 |
| 67 {'reflect(badEqualityHash1)' : reflect(badEqualityHash1), |
| 68 'reflect(badEqualityHash1), again' : reflect(badEqualityHash1)}, |
| 69 |
| 70 {'reflect(badEqualityHash2)' : reflect(badEqualityHash2), |
| 71 'reflect(badEqualityHash2), again' : reflect(badEqualityHash2)}, |
| 72 |
| 73 {'reflect(true)' : reflect(true), |
| 74 'reflect(true), again' : reflect(true)}, |
| 75 |
| 76 {'reflect(false)' : reflect(false), |
| 77 'reflect(false), again' : reflect(false)}, |
| 78 |
| 79 {'reflect(null)' : reflect(null), |
| 80 'reflect(null), again' : reflect(null)}, |
| 81 |
| 82 {'reflect(3.5+4.5)' : reflect(3.5+4.5), |
| 83 'reflect(6.5+1.5)' : reflect(6.5+1.5)}, |
| 84 |
| 58 {'reflect(3+4)' : reflect(3+4), | 85 {'reflect(3+4)' : reflect(3+4), |
| 59 'reflect(6+1)' : reflect(6+1)}, | 86 'reflect(6+1)' : reflect(6+1)}, |
| 60 | 87 |
| 88 {'reflect("foo")' : reflect("foo"), |
| 89 'reflect("foo"), again' : reflect("foo")}, |
| 90 |
| 61 {'currentMirrorSystem().voidType' : currentMirrorSystem().voidType, | 91 {'currentMirrorSystem().voidType' : currentMirrorSystem().voidType, |
| 62 'thisLibrary.functions[#subroutine].returnType' : | 92 'thisLibrary.functions[#subroutine].returnType' : |
| 63 thisLibrary.functions[const Symbol('subroutine')].returnType}, | 93 thisLibrary.functions[const Symbol('subroutine')].returnType}, |
| 64 | 94 |
| 65 {'currentMirrorSystem().dynamicType' : currentMirrorSystem().dynamicType, | 95 {'currentMirrorSystem().dynamicType' : currentMirrorSystem().dynamicType, |
| 66 'thisLibrary.functions[#main].returnType' : | 96 'thisLibrary.functions[#main].returnType' : |
| 67 thisLibrary.functions[const Symbol('main')].returnType}, | 97 thisLibrary.functions[const Symbol('main')].returnType}, |
| 68 | 98 |
| 69 {'reflectClass(A)' : reflectClass(A), | 99 {'reflectClass(A)' : reflectClass(A), |
| 70 'thisLibrary.classes[#A]' : thisLibrary.classes[const Symbol('A')], | 100 'thisLibrary.classes[#A]' : thisLibrary.classes[const Symbol('A')], |
| 71 'reflect(new A<int>()).type.originalDeclaration' : | 101 'reflect(new A<int>()).type.originalDeclaration' : |
| 72 reflect(new A<int>()).type.originalDeclaration}, | 102 reflect(new A<int>()).type.originalDeclaration}, |
| 73 | 103 |
| 74 {'reflectClass(B).superclass' : reflectClass(B).superclass, | 104 {'reflectClass(B).superclass' : reflectClass(B).superclass, |
| 75 'reflect(new A<int>()).type' : reflect(new A<int>()).type}, | 105 'reflect(new A<int>()).type' : reflect(new A<int>()).type}, |
| 76 | 106 |
| 77 {'reflectClass(B)' : reflectClass(B), | 107 {'reflectClass(B)' : reflectClass(B), |
| 78 'thisLibrary.classes[#B]' : thisLibrary.classes[const Symbol('B')], | 108 'thisLibrary.classes[#B]' : thisLibrary.classes[const Symbol('B')], |
| 79 'reflect(new B()).type' : reflect(new B()).type}, | 109 'reflect(new B()).type' : reflect(new B()).type}, |
| 80 | 110 |
| 81 {'thisLibrary' : thisLibrary, | 111 {'thisLibrary' : thisLibrary, |
| 82 'reflectClass(A).owner' : reflectClass(A).owner, | 112 'reflectClass(A).owner' : reflectClass(A).owner, |
| 83 'reflectClass(B).owner' : reflectClass(B).owner, | 113 'reflectClass(B).owner' : reflectClass(B).owner, |
| 84 'reflect(new A()).type.owner' : reflect(new A()).type.owner, | 114 'reflect(new A()).type.owner' : reflect(new A()).type.owner, |
| 85 'reflect(new A()).type.owner' : reflect(new A()).type.owner}, | 115 'reflect(new A()).type.owner' : reflect(new A()).type.owner}, |
| 86 ]); | 116 ]); |
| 87 } | 117 } |
| OLD | NEW |