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

Side by Side Diff: tests/corelib/hashcode_test.dart

Issue 2990623002: Migrate test block 9 to Dart 2.0 (Closed)
Patch Set: nits Created 3 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
« no previous file with comments | « tests/corelib/hashcode_boxed_test.dart ('k') | tests/corelib/hidden_library2_test.dart » ('j') | 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 import "package:expect/expect.dart";
6
7 class Override {
8 int hash;
9 int get superHash => super.hashCode;
10 int get hashCode => hash;
11
12 int foo() => hash; // Just some function that can be closurized.
13
14 bool operator ==(Object other) =>
15 other is Override && (other as Override).hash == hash;
16 }
17
18 int bar() => 42; // Some global function.
19
20 main() {
21 var o = new Object();
22 var hash = o.hashCode;
23 // Doesn't change.
24 Expect.equals(hash, o.hashCode);
25 Expect.equals(hash, identityHashCode(o));
26
27 var c = new Override();
28 int identityHash = c.superHash;
29 hash = (identityHash == 42) ? 37 : 42;
30 c.hash = hash;
31 Expect.equals(hash, c.hashCode);
32 Expect.equals(identityHash, identityHashCode(c));
33
34 // These classes don't override hashCode.
35 var samples = [0, 0x10000000, 1.5, -0, null, true, false, const Object()];
36 for (var v in samples) {
37 print(v);
38 Expect.equals(v.hashCode, identityHashCode(v));
39 }
40 // These do, or might do, but we can still use hashCodeOf and get the same
41 // result each time.
42 samples = ["string", "", (x) => 42, c.foo, bar];
43 for (var v in samples) {
44 print(v);
45 Expect.equals(v.hashCode, v.hashCode);
46 Expect.equals(identityHashCode(v), identityHashCode(v));
47 }
48 }
OLDNEW
« no previous file with comments | « tests/corelib/hashcode_boxed_test.dart ('k') | tests/corelib/hidden_library2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698