| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:lookup_map/lookup_map.dart'; | 5 import 'package:lookup_map/lookup_map.dart'; |
| 6 | 6 |
| 7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
| 8 | 8 |
| 9 class Key { | 9 class Key { |
| 10 final int id; | 10 final int id; |
| 11 const Key(this.id); | 11 const Key(this.id); |
| 12 } | 12 } |
| 13 | 13 |
| 14 class A{} | 14 class A {} |
| 15 |
| 15 const B = const Key(1); | 16 const B = const Key(1); |
| 16 class C{} | 17 |
| 18 class C {} |
| 17 | 19 |
| 18 main() { | 20 main() { |
| 19 test('entries constructor', () { | 21 test('entries constructor', () { |
| 20 var m = const LookupMap(const [ | 22 var m = const LookupMap(const [ |
| 21 A, "the-text-for-A", | 23 A, |
| 22 B, "the-text-for-B", | 24 "the-text-for-A", |
| 23 1.2, "the-text-for-1.2"]); | 25 B, |
| 26 "the-text-for-B", |
| 27 1.2, |
| 28 "the-text-for-1.2" |
| 29 ]); |
| 24 expect(m[A], 'the-text-for-A'); | 30 expect(m[A], 'the-text-for-A'); |
| 25 expect(m[B], 'the-text-for-B'); | 31 expect(m[B], 'the-text-for-B'); |
| 26 expect(m[1.2], 'the-text-for-1.2'); | 32 expect(m[1.2], 'the-text-for-1.2'); |
| 27 expect(m[C], null); | 33 expect(m[C], null); |
| 28 expect(m[1.3], null); | 34 expect(m[1.3], null); |
| 29 }); | 35 }); |
| 30 | 36 |
| 31 test('pair constructor', () { | 37 test('pair constructor', () { |
| 32 var m = const LookupMap<dynamic, String>.pair(A, "the-text-for-A"); | 38 var m = const LookupMap<dynamic, String>.pair(A, "the-text-for-A"); |
| 33 expect(m[A], 'the-text-for-A'); | 39 expect(m[A], 'the-text-for-A'); |
| 34 expect(m[B], null); | 40 expect(m[B], null); |
| 35 }); | 41 }); |
| 36 | 42 |
| 37 test('nested lookup', () { | 43 test('nested lookup', () { |
| 38 var m = const LookupMap(const [], | 44 var m = const LookupMap(const [], |
| 39 const [const LookupMap<dynamic, String>.pair(A, "the-text-for-A")]); | 45 const [const LookupMap<dynamic, String>.pair(A, "the-text-for-A")]); |
| 40 expect(m[A], 'the-text-for-A'); | 46 expect(m[A], 'the-text-for-A'); |
| 41 expect(m[B], null); | 47 expect(m[B], null); |
| 42 }); | 48 }); |
| 43 | 49 |
| 44 test('entry shadows nested maps', () { | 50 test('entry shadows nested maps', () { |
| 45 var m = const LookupMap(const [ | 51 var m = const LookupMap(const [ |
| 46 A, "the-text-for-A2", | 52 A, |
| 53 "the-text-for-A2", |
| 47 ], const [ | 54 ], const [ |
| 48 const LookupMap.pair(A, "the-text-for-A1"), | 55 const LookupMap.pair(A, "the-text-for-A1"), |
| 49 ]); | 56 ]); |
| 50 expect(m[A], 'the-text-for-A2'); | 57 expect(m[A], 'the-text-for-A2'); |
| 51 }); | 58 }); |
| 52 | 59 |
| 53 test('nested maps shadow in order', () { | 60 test('nested maps shadow in order', () { |
| 54 var m = const LookupMap(const [ ], const [ | 61 var m = const LookupMap(const [], const [ |
| 55 const LookupMap.pair(A, "the-text-for-A1"), | 62 const LookupMap.pair(A, "the-text-for-A1"), |
| 56 const LookupMap.pair(B, "the-text-for-B2"), | 63 const LookupMap.pair(B, "the-text-for-B2"), |
| 57 const LookupMap.pair(A, "the-text-for-A2"), | 64 const LookupMap.pair(A, "the-text-for-A2"), |
| 58 const LookupMap.pair(B, "the-text-for-B1"), | 65 const LookupMap.pair(B, "the-text-for-B1"), |
| 59 ]); | 66 ]); |
| 60 expect(m[A], 'the-text-for-A2'); | 67 expect(m[A], 'the-text-for-A2'); |
| 61 expect(m[B], 'the-text-for-B1'); | 68 expect(m[B], 'the-text-for-B1'); |
| 62 }); | 69 }); |
| 63 | 70 |
| 64 // This test would fail if dart2js has a bug, but we keep it here for our | 71 // This test would fail if dart2js has a bug, but we keep it here for our |
| 65 // sanity. | 72 // sanity. |
| 66 test('reachable lookups are not tree-shaken', () { | 73 test('reachable lookups are not tree-shaken', () { |
| 67 var m = const LookupMap(const [ | 74 var m = const LookupMap(const [ |
| 68 A, B, | 75 A, |
| 69 B, C, | 76 B, |
| 70 C, 3.4, | 77 B, |
| 78 C, |
| 79 C, |
| 80 3.4, |
| 71 ]); | 81 ]); |
| 72 expect(m[m[m[A]]], 3.4); | 82 expect(m[m[m[A]]], 3.4); |
| 73 }); | 83 }); |
| 74 } | 84 } |
| OLD | NEW |