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