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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class Override { | 7 class Override { |
8 int hash; | 8 int hash; |
9 int get superHash => super.hashCode; | 9 int get superHash => super.hashCode; |
10 int get hashCode => hash; | 10 int get hashCode => hash; |
11 | 11 |
12 int foo() => hash; // Just some function that can be closurized. | 12 int foo() => hash; // Just some function that can be closurized. |
13 | 13 |
14 bool operator ==(Object other) => | 14 bool operator ==(Object other) => other is Override && other.hash == hash; |
15 other is Override && (other as Override).hash == hash; | |
16 } | 15 } |
17 | 16 |
18 int bar() => 42; // Some global function. | 17 int bar() => 42; // Some global function. |
19 | 18 |
20 main() { | 19 main() { |
21 var o = new Object(); | 20 var o = new Object(); |
22 var hash = o.hashCode; | 21 var hash = o.hashCode; |
23 // Doesn't change. | 22 // Doesn't change. |
24 Expect.equals(hash, o.hashCode); | 23 Expect.equals(hash, o.hashCode); |
25 Expect.equals(hash, identityHashCode(o)); | 24 Expect.equals(hash, identityHashCode(o)); |
(...skipping 13 matching lines...) Expand all Loading... |
39 } | 38 } |
40 // These do, or might do, but we can still use hashCodeOf and get the same | 39 // These do, or might do, but we can still use hashCodeOf and get the same |
41 // result each time. | 40 // result each time. |
42 samples = ["string", "", (x) => 42, c.foo, bar]; | 41 samples = ["string", "", (x) => 42, c.foo, bar]; |
43 for (var v in samples) { | 42 for (var v in samples) { |
44 print(v); | 43 print(v); |
45 Expect.equals(v.hashCode, v.hashCode); | 44 Expect.equals(v.hashCode, v.hashCode); |
46 Expect.equals(identityHashCode(v), identityHashCode(v)); | 45 Expect.equals(identityHashCode(v), identityHashCode(v)); |
47 } | 46 } |
48 } | 47 } |
OLD | NEW |