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

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

Issue 367683002: Use JsonMap even for JSON.decode with custom reviver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line in test. 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; 8 import 'dart:convert' show JSON;
9 9
10 Map newJsonMap() => JSON.decode('{}'); 10 Map newJsonMap()
11 => JSON.decode('{}');
12 Map newJsonMapCustomReviver()
13 => JSON.decode('{}', reviver: (key, value) => value);
11 14
12 void main() { 15 void main() {
13 test(new HashMap()); 16 test(new HashMap());
14 test(new LinkedHashMap()); 17 test(new LinkedHashMap());
15 test(new SplayTreeMap()); 18 test(new SplayTreeMap());
16 test(new SplayTreeMap(Comparable.compare)); 19 test(new SplayTreeMap(Comparable.compare));
17 test(new MapView(new HashMap())); 20 test(new MapView(new HashMap()));
18 test(new MapView(new SplayTreeMap())); 21 test(new MapView(new SplayTreeMap()));
19 test(new MapBaseMap()); 22 test(new MapBaseMap());
20 test(new MapMixinMap()); 23 test(new MapMixinMap());
21 test(newJsonMap()); 24 test(newJsonMap());
25 test(newJsonMapCustomReviver());
22 testLinkedHashMap(); 26 testLinkedHashMap();
23 testMapLiteral(); 27 testMapLiteral();
24 testNullValue(); 28 testNullValue();
25 testTypes(); 29 testTypes();
26 30
27 testWeirdStringKeys(new Map()); 31 testWeirdStringKeys(new Map());
28 testWeirdStringKeys(new Map<String, String>()); 32 testWeirdStringKeys(new Map<String, String>());
29 testWeirdStringKeys(new HashMap()); 33 testWeirdStringKeys(new HashMap());
30 testWeirdStringKeys(new HashMap<String, String>()); 34 testWeirdStringKeys(new HashMap<String, String>());
31 testWeirdStringKeys(new LinkedHashMap()); 35 testWeirdStringKeys(new LinkedHashMap());
32 testWeirdStringKeys(new LinkedHashMap<String, String>()); 36 testWeirdStringKeys(new LinkedHashMap<String, String>());
33 testWeirdStringKeys(new SplayTreeMap()); 37 testWeirdStringKeys(new SplayTreeMap());
34 testWeirdStringKeys(new SplayTreeMap<String, String>()); 38 testWeirdStringKeys(new SplayTreeMap<String, String>());
35 testWeirdStringKeys(new MapBaseMap<String, String>()); 39 testWeirdStringKeys(new MapBaseMap<String, String>());
36 testWeirdStringKeys(new MapMixinMap<String, String>()); 40 testWeirdStringKeys(new MapMixinMap<String, String>());
37 testWeirdStringKeys(newJsonMap()); 41 testWeirdStringKeys(newJsonMap());
42 testWeirdStringKeys(newJsonMapCustomReviver());
38 43
39 testNumericKeys(new Map()); 44 testNumericKeys(new Map());
40 testNumericKeys(new Map<num, String>()); 45 testNumericKeys(new Map<num, String>());
41 testNumericKeys(new HashMap()); 46 testNumericKeys(new HashMap());
42 testNumericKeys(new HashMap<num, String>()); 47 testNumericKeys(new HashMap<num, String>());
43 testNumericKeys(new HashMap.identity()); 48 testNumericKeys(new HashMap.identity());
44 testNumericKeys(new HashMap<num, String>.identity()); 49 testNumericKeys(new HashMap<num, String>.identity());
45 testNumericKeys(new LinkedHashMap()); 50 testNumericKeys(new LinkedHashMap());
46 testNumericKeys(new LinkedHashMap<num, String>()); 51 testNumericKeys(new LinkedHashMap<num, String>());
47 testNumericKeys(new LinkedHashMap.identity()); 52 testNumericKeys(new LinkedHashMap.identity());
48 testNumericKeys(new LinkedHashMap<num, String>.identity()); 53 testNumericKeys(new LinkedHashMap<num, String>.identity());
49 testNumericKeys(new MapBaseMap<num, String>()); 54 testNumericKeys(new MapBaseMap<num, String>());
50 testNumericKeys(new MapMixinMap<num, String>()); 55 testNumericKeys(new MapMixinMap<num, String>());
51 testNumericKeys(newJsonMap()); 56 testNumericKeys(newJsonMap());
57 testNumericKeys(newJsonMapCustomReviver());
52 58
53 testNaNKeys(new Map()); 59 testNaNKeys(new Map());
54 testNaNKeys(new Map<num, String>()); 60 testNaNKeys(new Map<num, String>());
55 testNaNKeys(new HashMap()); 61 testNaNKeys(new HashMap());
56 testNaNKeys(new HashMap<num, String>()); 62 testNaNKeys(new HashMap<num, String>());
57 testNaNKeys(new LinkedHashMap()); 63 testNaNKeys(new LinkedHashMap());
58 testNaNKeys(new LinkedHashMap<num, String>()); 64 testNaNKeys(new LinkedHashMap<num, String>());
59 testNaNKeys(new MapBaseMap<num, String>()); 65 testNaNKeys(new MapBaseMap<num, String>());
60 testNaNKeys(new MapMixinMap<num, String>()); 66 testNaNKeys(new MapMixinMap<num, String>());
61 testNaNKeys(newJsonMap()); 67 testNaNKeys(newJsonMap());
68 testNaNKeys(newJsonMapCustomReviver());
62 // Identity maps fail the NaN-keys tests because the test assumes that 69 // Identity maps fail the NaN-keys tests because the test assumes that
63 // NaN is not equal to NaN. 70 // NaN is not equal to NaN.
64 71
65 testIdentityMap(new Map.identity()); 72 testIdentityMap(new Map.identity());
66 testIdentityMap(new HashMap.identity()); 73 testIdentityMap(new HashMap.identity());
67 testIdentityMap(new LinkedHashMap.identity()); 74 testIdentityMap(new LinkedHashMap.identity());
68 testIdentityMap(new HashMap(equals: identical, 75 testIdentityMap(new HashMap(equals: identical,
69 hashCode: identityHashCode)); 76 hashCode: identityHashCode));
70 testIdentityMap(new LinkedHashMap(equals: identical, 77 testIdentityMap(new LinkedHashMap(equals: identical,
71 hashCode: identityHashCode)); 78 hashCode: identityHashCode));
72 testIdentityMap(new HashMap(equals: (x, y) => identical(x, y), 79 testIdentityMap(new HashMap(equals: (x, y) => identical(x, y),
73 hashCode: (x) => identityHashCode(x))); 80 hashCode: (x) => identityHashCode(x)));
74 testIdentityMap(new LinkedHashMap(equals: (x, y) => identical(x, y), 81 testIdentityMap(new LinkedHashMap(equals: (x, y) => identical(x, y),
75 hashCode: (x) => identityHashCode(x))); 82 hashCode: (x) => identityHashCode(x)));
76 83
77 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode, 84 testCustomMap(new HashMap(equals: myEquals, hashCode: myHashCode,
78 isValidKey: (v) => v is Customer)); 85 isValidKey: (v) => v is Customer));
79 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode, 86 testCustomMap(new LinkedHashMap(equals: myEquals, hashCode: myHashCode,
80 isValidKey: (v) => v is Customer)); 87 isValidKey: (v) => v is Customer));
81 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals, 88 testCustomMap(new HashMap<Customer,dynamic>(equals: myEquals,
82 hashCode: myHashCode)); 89 hashCode: myHashCode));
83 90
84 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals, 91 testCustomMap(new LinkedHashMap<Customer,dynamic>(equals: myEquals,
85 hashCode: myHashCode)); 92 hashCode: myHashCode));
86 93
87 testIterationOrder(new LinkedHashMap()); 94 testIterationOrder(new LinkedHashMap());
88 testIterationOrder(new LinkedHashMap.identity()); 95 testIterationOrder(new LinkedHashMap.identity());
89 testIterationOrder(newJsonMap()); 96 testIterationOrder(newJsonMap());
97 testIterationOrder(newJsonMapCustomReviver());
90 98
91 testOtherKeys(new SplayTreeMap<int, int>()); 99 testOtherKeys(new SplayTreeMap<int, int>());
92 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b, 100 testOtherKeys(new SplayTreeMap<int, int>((int a, int b) => a - b,
93 (v) => v is int)); 101 (v) => v is int));
94 testOtherKeys(new SplayTreeMap((int a, int b) => a - b, 102 testOtherKeys(new SplayTreeMap((int a, int b) => a - b,
95 (v) => v is int)); 103 (v) => v is int));
96 testOtherKeys(new HashMap<int, int>()); 104 testOtherKeys(new HashMap<int, int>());
97 testOtherKeys(new HashMap<int, int>.identity()); 105 testOtherKeys(new HashMap<int, int>.identity());
98 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode, 106 testOtherKeys(new HashMap<int, int>(hashCode: (v) => v.hashCode,
99 isValidKey: (v) => v is int)); 107 isValidKey: (v) => v is int));
100 testOtherKeys(new HashMap(equals: (int x, int y) => x == y, 108 testOtherKeys(new HashMap(equals: (int x, int y) => x == y,
101 hashCode: (int v) => v.hashCode, 109 hashCode: (int v) => v.hashCode,
102 isValidKey: (v) => v is int)); 110 isValidKey: (v) => v is int));
103 testOtherKeys(new LinkedHashMap<int, int>()); 111 testOtherKeys(new LinkedHashMap<int, int>());
104 testOtherKeys(new LinkedHashMap<int, int>.identity()); 112 testOtherKeys(new LinkedHashMap<int, int>.identity());
105 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode, 113 testOtherKeys(new LinkedHashMap<int, int>(hashCode: (v) => v.hashCode,
106 isValidKey: (v) => v is int)); 114 isValidKey: (v) => v is int));
107 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y, 115 testOtherKeys(new LinkedHashMap(equals: (int x, int y) => x == y,
108 hashCode: (int v) => v.hashCode, 116 hashCode: (int v) => v.hashCode,
109 isValidKey: (v) => v is int)); 117 isValidKey: (v) => v is int));
110 testOtherKeys(new MapBaseMap<int, int>()); 118 testOtherKeys(new MapBaseMap<int, int>());
111 testOtherKeys(new MapMixinMap<int, int>()); 119 testOtherKeys(new MapMixinMap<int, int>());
112 testOtherKeys(newJsonMap()); 120 testOtherKeys(newJsonMap());
121 testOtherKeys(newJsonMapCustomReviver());
113 122
114 testUnmodifiableMap(const {1 : 37}); 123 testUnmodifiableMap(const {1 : 37});
115 testUnmodifiableMap(new UnmodifiableMapView({1 : 37})); 124 testUnmodifiableMap(new UnmodifiableMapView({1 : 37}));
116 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37])); 125 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37]));
117 } 126 }
118 127
119 128
120 void test(Map map) { 129 void test(Map map) {
121 testDeletedElement(map); 130 testDeletedElement(map);
122 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8); 131 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8);
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 int get _modCount => 0; 891 int get _modCount => 0;
883 892
884 V operator[](K key) { 893 V operator[](K key) {
885 int index = _keys.indexOf(key); 894 int index = _keys.indexOf(key);
886 if (index < 0) return null; 895 if (index < 0) return null;
887 return _values[index]; 896 return _values[index];
888 } 897 }
889 898
890 Iterable<K> get keys => _keys.skip(0); 899 Iterable<K> get keys => _keys.skip(0);
891 } 900 }
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