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

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