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

Side by Side Diff: pkg/lookup_map/test/lookup_map_test.dart

Issue 1308993008: Add version validation for LookupMap, also add unittest directly in LookupMap (take 2) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix on top of previous CL Created 5 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
« no previous file with comments | « pkg/lookup_map/pubspec.yaml ('k') | pkg/lookup_map/test/version_check_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) 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 }
OLDNEW
« no previous file with comments | « pkg/lookup_map/pubspec.yaml ('k') | pkg/lookup_map/test/version_check_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698