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

Side by Side Diff: tests/language/map_literal11_test.dart

Issue 22909056: Support general expressions as keys in literal maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « tests/language/map_literal10_test.dart ('k') | tests/language/map_literal5_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 // Test the use of reliance on identity for keys in constant maps.
6
7 library map_literal11_test;
8
9 import "package:expect/expect.dart";
10
11
12 class A {
13 static int accessCount = 0;
14
15 final int field;
16
17 const A(this.field);
18 int get hashCode => accessCount++;
19 }
20
21 void main() {
22 // Non-constant map are not based on identity.
23 var m1 = {const A(0): 0, const A(1): 1, null: 2, "3": 3, 4: 4};
24 Expect.isFalse(m1.containsKey(const A(0)));
25 Expect.isFalse(m1.containsKey(const A(1)));
26 Expect.isTrue(m1.containsKey(null));
27 Expect.isTrue(m1.containsKey("3"));
28 Expect.isTrue(m1.containsKey(4));
29 Expect.isNull(m1[const A(0)]);
30 Expect.isNull(m1[const A(1)]);
31 Expect.equals(2, m1[null]);
32 Expect.equals(3, m1["3"]);
33 Expect.equals(4, m1[4]);
34
35 // Constant map are based on identity.
36 var m2 = const {const A(0): 0, const A(1): 1, null: 2, "3": 3, 4: 4};
37 Expect.isTrue(m2.containsKey(const A(0)));
38 Expect.isTrue(m2.containsKey(const A(1)));
39 Expect.isTrue(m2.containsKey(null));
40 Expect.isTrue(m2.containsKey("3"));
41 Expect.isTrue(m2.containsKey(4));
42 Expect.equals(0, m2[const A(0)]);
43 Expect.equals(1, m2[const A(1)]);
44 Expect.equals(2, m2[null]);
45 Expect.equals(3, m2["3"]);
46 Expect.equals(4, m2[4]);
47 }
OLDNEW
« no previous file with comments | « tests/language/map_literal10_test.dart ('k') | tests/language/map_literal5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698