| OLD | NEW |
| (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 } |
| OLD | NEW |