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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/language/map_literal10_test.dart ('k') | tests/language/map_literal5_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/map_literal11_test.dart
diff --git a/tests/language/map_literal11_test.dart b/tests/language/map_literal11_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7461b808547c7c00f8a880ba4fca4c07f47b0bea
--- /dev/null
+++ b/tests/language/map_literal11_test.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test the use of reliance on identity for keys in constant maps.
+
+library map_literal11_test;
+
+import "package:expect/expect.dart";
+
+
+class A {
+ static int accessCount = 0;
+
+ final int field;
+
+ const A(this.field);
+ int get hashCode => accessCount++;
+}
+
+void main() {
+ // Non-constant map are not based on identity.
+ var m1 = {const A(0): 0, const A(1): 1, null: 2, "3": 3, 4: 4};
+ Expect.isFalse(m1.containsKey(const A(0)));
+ Expect.isFalse(m1.containsKey(const A(1)));
+ Expect.isTrue(m1.containsKey(null));
+ Expect.isTrue(m1.containsKey("3"));
+ Expect.isTrue(m1.containsKey(4));
+ Expect.isNull(m1[const A(0)]);
+ Expect.isNull(m1[const A(1)]);
+ Expect.equals(2, m1[null]);
+ Expect.equals(3, m1["3"]);
+ Expect.equals(4, m1[4]);
+
+ // Constant map are based on identity.
+ var m2 = const {const A(0): 0, const A(1): 1, null: 2, "3": 3, 4: 4};
+ Expect.isTrue(m2.containsKey(const A(0)));
+ Expect.isTrue(m2.containsKey(const A(1)));
+ Expect.isTrue(m2.containsKey(null));
+ Expect.isTrue(m2.containsKey("3"));
+ Expect.isTrue(m2.containsKey(4));
+ Expect.equals(0, m2[const A(0)]);
+ Expect.equals(1, m2[const A(1)]);
+ Expect.equals(2, m2[null]);
+ Expect.equals(3, m2["3"]);
+ Expect.equals(4, m2[4]);
+}
« 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