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

Side by Side Diff: tests/corelib/map_test.dart

Issue 336863008: Make the JSON decoder (parser) create Dart maps lazily (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review feedback. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « tests/corelib/json_map_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 library map_test; 5 library map_test;
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' show JSON;
9
10 Map newJsonMap() => JSON.decode('{}');
8 11
9 void main() { 12 void main() {
10 test(new HashMap()); 13 test(new HashMap());
11 test(new LinkedHashMap()); 14 test(new LinkedHashMap());
12 test(new SplayTreeMap()); 15 test(new SplayTreeMap());
13 test(new SplayTreeMap(Comparable.compare)); 16 test(new SplayTreeMap(Comparable.compare));
14 test(new MapView(new HashMap())); 17 test(new MapView(new HashMap()));
15 test(new MapView(new SplayTreeMap())); 18 test(new MapView(new SplayTreeMap()));
16 test(new MapBaseMap()); 19 test(new MapBaseMap());
17 test(new MapMixinMap()); 20 test(new MapMixinMap());
21 test(newJsonMap());
18 testLinkedHashMap(); 22 testLinkedHashMap();
19 testMapLiteral(); 23 testMapLiteral();
20 testNullValue(); 24 testNullValue();
21 testTypes(); 25 testTypes();
22 26
23 testWeirdStringKeys(new Map()); 27 testWeirdStringKeys(new Map());
24 testWeirdStringKeys(new Map<String, String>()); 28 testWeirdStringKeys(new Map<String, String>());
25 testWeirdStringKeys(new HashMap()); 29 testWeirdStringKeys(new HashMap());
26 testWeirdStringKeys(new HashMap<String, String>()); 30 testWeirdStringKeys(new HashMap<String, String>());
27 testWeirdStringKeys(new LinkedHashMap()); 31 testWeirdStringKeys(new LinkedHashMap());
28 testWeirdStringKeys(new LinkedHashMap<String, String>()); 32 testWeirdStringKeys(new LinkedHashMap<String, String>());
29 testWeirdStringKeys(new SplayTreeMap()); 33 testWeirdStringKeys(new SplayTreeMap());
30 testWeirdStringKeys(new SplayTreeMap<String, String>()); 34 testWeirdStringKeys(new SplayTreeMap<String, String>());
31 testWeirdStringKeys(new MapBaseMap<String, String>()); 35 testWeirdStringKeys(new MapBaseMap<String, String>());
32 testWeirdStringKeys(new MapMixinMap<String, String>()); 36 testWeirdStringKeys(new MapMixinMap<String, String>());
37 testWeirdStringKeys(newJsonMap());
33 38
34 testNumericKeys(new Map()); 39 testNumericKeys(new Map());
35 testNumericKeys(new Map<num, String>()); 40 testNumericKeys(new Map<num, String>());
36 testNumericKeys(new HashMap()); 41 testNumericKeys(new HashMap());
37 testNumericKeys(new HashMap<num, String>()); 42 testNumericKeys(new HashMap<num, String>());
38 testNumericKeys(new HashMap.identity()); 43 testNumericKeys(new HashMap.identity());
39 testNumericKeys(new HashMap<num, String>.identity()); 44 testNumericKeys(new HashMap<num, String>.identity());
40 testNumericKeys(new LinkedHashMap()); 45 testNumericKeys(new LinkedHashMap());
41 testNumericKeys(new LinkedHashMap<num, String>()); 46 testNumericKeys(new LinkedHashMap<num, String>());
42 testNumericKeys(new LinkedHashMap.identity()); 47 testNumericKeys(new LinkedHashMap.identity());
43 testNumericKeys(new LinkedHashMap<num, String>.identity()); 48 testNumericKeys(new LinkedHashMap<num, String>.identity());
44 testNumericKeys(new MapBaseMap<num, String>()); 49 testNumericKeys(new MapBaseMap<num, String>());
45 testNumericKeys(new MapMixinMap<num, String>()); 50 testNumericKeys(new MapMixinMap<num, String>());
51 testNumericKeys(newJsonMap());
46 52
47 testNaNKeys(new Map()); 53 testNaNKeys(new Map());
48 testNaNKeys(new Map<num, String>()); 54 testNaNKeys(new Map<num, String>());
49 testNaNKeys(new HashMap()); 55 testNaNKeys(new HashMap());
50 testNaNKeys(new HashMap<num, String>()); 56 testNaNKeys(new HashMap<num, String>());
51 testNaNKeys(new LinkedHashMap()); 57 testNaNKeys(new LinkedHashMap());
52 testNaNKeys(new LinkedHashMap<num, String>()); 58 testNaNKeys(new LinkedHashMap<num, String>());
53 testNaNKeys(new MapBaseMap<num, String>()); 59 testNaNKeys(new MapBaseMap<num, String>());
54 testNaNKeys(new MapMixinMap<num, String>()); 60 testNaNKeys(new MapMixinMap<num, String>());
61 testNaNKeys(newJsonMap());
55 // Identity maps fail the NaN-keys tests because the test assumes that 62 // Identity maps fail the NaN-keys tests because the test assumes that
56 // NaN is not equal to NaN. 63 // NaN is not equal to NaN.
57 64
58 testIdentityMap(new Map.identity()); 65 testIdentityMap(new Map.identity());
59 testIdentityMap(new HashMap.identity()); 66 testIdentityMap(new HashMap.identity());
60 testIdentityMap(new LinkedHashMap.identity()); 67 testIdentityMap(new LinkedHashMap.identity());
61 testIdentityMap(new HashMap(equals: identical, 68 testIdentityMap(new HashMap(equals: identical,
62 hashCode: identityHashCode)); 69 hashCode: identityHashCode));
63 testIdentityMap(new LinkedHashMap(equals: identical, 70 testIdentityMap(new LinkedHashMap(equals: identical,
64 hashCode: identityHashCode)); 71 hashCode: identityHashCode));
65 testIdentityMap(new HashMap(equals: (x, y) => identical(x, y), 72 testIdentityMap(new HashMap(equals: (x, y) => identical(x, y),
66 hashCode: (x) => identityHashCode(x))); 73 hashCode: (x) => identityHashCode(x)));
67 testIdentityMap(new LinkedHashMap(equals: (x, y) => identical(x, y), 74 testIdentityMap(new LinkedHashMap(equals: (x, y) => identical(x, y),
68 hashCode: (x) => identityHashCode(x))); 75 hashCode: (x) => identityHashCode(x)));
69 76
70 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode, 77 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode,
71 isValidKey: (v) => v is Customer)); 78 isValidKey: (v) => v is Customer));
72 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode, 79 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode,
73 isValidKey: (v) => v is Customer)); 80 isValidKey: (v) => v is Customer));
74 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals, 81 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals,
75 hashCode: myHashCode)); 82 hashCode: myHashCode));
76 83
77 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals, 84 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals,
78 hashCode: myHashCode)); 85 hashCode: myHashCode));
79 86
80 testIterationOrder(new LinkedHashMap()); 87 testIterationOrder(new LinkedHashMap());
81 testIterationOrder(new LinkedHashMap.identity()); 88 testIterationOrder(new LinkedHashMap.identity());
89 testIterationOrder(newJsonMap());
82 90
83 testOtherKeys(new SplayTreeMap<int, int>()); 91 testOtherKeys(new SplayTreeMap<int, int>());
84 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b, 92 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b,
85 (v) => v is int)); 93 (v) => v is int));
86 testOtherKeys(new SplayTreeMap((int a, int b) => a - b, 94 testOtherKeys(new SplayTreeMap((int a, int b) => a - b,
87 (v) => v is int)); 95 (v) => v is int));
88 testOtherKeys(new HashMap<int, int>()); 96 testOtherKeys(new HashMap<int, int>());
89 testOtherKeys(new HashMap<int, int>.identity()); 97 testOtherKeys(new HashMap<int, int>.identity());
90 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode, 98 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode,
91 isValidKey: (v) => v is int)); 99 isValidKey: (v) => v is int));
92 testOtherKeys(new HashMap(equals: (int x, int y) => x == y, 100 testOtherKeys(new HashMap(equals: (int x, int y) => x == y,
93 hashCode: (int v) => v.hashCode, 101 hashCode: (int v) => v.hashCode,
94 isValidKey: (v) => v is int)); 102 isValidKey: (v) => v is int));
95 testOtherKeys(new LinkedHashMap<int, int>()); 103 testOtherKeys(new LinkedHashMap<int, int>());
96 testOtherKeys(new LinkedHashMap<int, int>.identity()); 104 testOtherKeys(new LinkedHashMap<int, int>.identity());
97 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode, 105 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode,
98 isValidKey: (v) => v is int)); 106 isValidKey: (v) => v is int));
99 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y, 107 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y,
100 hashCode: (int v) => v.hashCode, 108 hashCode: (int v) => v.hashCode,
101 isValidKey: (v) => v is int)); 109 isValidKey: (v) => v is int));
102 testOtherKeys(new MapBaseMap<int, int>()); 110 testOtherKeys(new MapBaseMap<int, int>());
103 testOtherKeys(new MapMixinMap<int, int>()); 111 testOtherKeys(new MapMixinMap<int, int>());
112 testOtherKeys(newJsonMap());
104 113
105 testUnmodifiableMap(const {1 : 37}); 114 testUnmodifiableMap(const {1 : 37});
106 testUnmodifiableMap(new UnmodifiableMapView({1 : 37})); 115 testUnmodifiableMap(new UnmodifiableMapView({1 : 37}));
107 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37])); 116 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37]));
108 } 117 }
109 118
110 119
111 void test(Map map) { 120 void test(Map map) {
112 testDeletedElement(map); 121 testDeletedElement(map);
113 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8); 122 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8);
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 int get _modCount => 0; 882 int get _modCount => 0;
874 883
875 V operator[](K key) { 884 V operator[](K key) {
876 int index = _keys.indexOf(key); 885 int index = _keys.indexOf(key);
877 if (index < 0) return null; 886 if (index < 0) return null;
878 return _values[index]; 887 return _values[index];
879 } 888 }
880 889
881 Iterable<K> get keys => _keys.skip(0); 890 Iterable<K> get keys => _keys.skip(0);
882 } 891 }
OLDNEW
« no previous file with comments | « tests/corelib/json_map_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698