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

Side by Side Diff: packages/collection/test/typed_wrapper/map_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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:collection/collection.dart";
6 import "package:test/test.dart";
7
8 import '../utils.dart';
9
10 void main() {
11 group("with valid types, forwards", () {
12 var wrapper;
13 var emptyWrapper;
14 setUp(() {
15 wrapper = DelegatingMap.typed<String, int>(
16 <Object, Object>{"foo": 1, "bar": 2, "baz": 3, "bang": 4});
17 emptyWrapper = DelegatingMap.typed<String, int>(<Object, Object>{});
18 });
19
20 test("[]", () {
21 expect(wrapper["foo"], equals(1));
22 expect(wrapper["bar"], equals(2));
23 expect(wrapper["qux"], isNull);
24 expect(wrapper[1], isNull);
25 });
26
27 test("[]=", () {
28 wrapper["foo"] = 5;
29 expect(wrapper, equals({"foo": 5, "bar": 2, "baz": 3, "bang": 4}));
30
31 wrapper["qux"] = 6;
32 expect(
33 wrapper, equals({"foo": 5, "bar": 2, "baz": 3, "bang": 4, "qux": 6}));
34 });
35
36 test("addAll()", () {
37 wrapper.addAll({"bar": 5, "qux": 6});
38 expect(
39 wrapper, equals({"foo": 1, "bar": 5, "baz": 3, "bang": 4, "qux": 6}));
40 });
41
42 test("clear()", () {
43 wrapper.clear();
44 expect(wrapper, isEmpty);
45 });
46
47 test("containsKey()", () {
48 expect(wrapper.containsKey("foo"), isTrue);
49 expect(wrapper.containsKey("qux"), isFalse);
50 expect(wrapper.containsKey(1), isFalse);
51 });
52
53 test("containsValue()", () {
54 expect(wrapper.containsValue(1), isTrue);
55 expect(wrapper.containsValue(7), isFalse);
56 expect(wrapper.containsValue("foo"), isFalse);
57 });
58
59 test("forEach()", () {
60 var results = [];
61 wrapper.forEach((key, value) => results.add([key, value]));
62 expect(
63 results,
64 unorderedEquals([
65 ["foo", 1],
66 ["bar", 2],
67 ["baz", 3],
68 ["bang", 4]
69 ]));
70
71 emptyWrapper.forEach(expectAsync2((_, __) {}, count: 0));
72 });
73
74 test("isEmpty", () {
75 expect(wrapper.isEmpty, isFalse);
76 expect(emptyWrapper.isEmpty, isTrue);
77 });
78
79 test("isNotEmpty", () {
80 expect(wrapper.isNotEmpty, isTrue);
81 expect(emptyWrapper.isNotEmpty, isFalse);
82 });
83
84 test("keys", () {
85 expect(wrapper.keys, unorderedEquals(["foo", "bar", "baz", "bang"]));
86 expect(emptyWrapper.keys, isEmpty);
87 });
88
89 test("length", () {
90 expect(wrapper.length, equals(4));
91 expect(emptyWrapper.length, equals(0));
92 });
93
94 test("putIfAbsent()", () {
95 expect(wrapper.putIfAbsent("foo", expectAsync1((_) => null, count: 0)),
96 equals(1));
97
98 expect(wrapper.putIfAbsent("qux", () => 6), equals(6));
99 expect(
100 wrapper, equals({"foo": 1, "bar": 2, "baz": 3, "bang": 4, "qux": 6}));
101 });
102
103 test("remove()", () {
104 expect(wrapper.remove("foo"), equals(1));
105 expect(wrapper, equals({"bar": 2, "baz": 3, "bang": 4}));
106
107 expect(wrapper.remove("foo"), isNull);
108 expect(wrapper.remove(3), isNull);
109 });
110
111 test("values", () {
112 expect(wrapper.values, unorderedEquals([1, 2, 3, 4]));
113 expect(emptyWrapper.values, isEmpty);
114 });
115
116 test("toString()", () {
117 expect(
118 wrapper.toString(),
119 allOf([
120 startsWith("{"),
121 contains("foo: 1"),
122 contains("bar: 2"),
123 contains("baz: 3"),
124 contains("bang: 4"),
125 endsWith("}")
126 ]));
127 });
128 });
129
130 group("with invalid key types", () {
131 var inner;
132 var wrapper;
133 setUp(() {
134 inner = <Object, Object>{1: 1, 2: 2, 3: 3, 4: 4};
135 wrapper = DelegatingMap.typed<String, int>(inner);
136 });
137
138 group("throws a CastError for", () {
139 test("forEach()", () {
140 expect(() => wrapper.forEach(expectAsync2((_, __) {}, count: 0)),
141 throwsCastError);
142 });
143
144 test("keys", () {
145 var lazy = wrapper.keys;
146 expect(() => lazy.first, throwsCastError);
147 });
148 });
149
150 group("doesn't throw a CastError for", () {
151 test("[]", () {
152 expect(wrapper["foo"], isNull);
153 expect(wrapper[1], equals(1));
154 expect(wrapper[7], isNull);
155 });
156
157 test("[]=", () {
158 wrapper["foo"] = 5;
159 expect(inner, equals({"foo": 5, 1: 1, 2: 2, 3: 3, 4: 4}));
160 });
161
162 test("addAll()", () {
163 wrapper.addAll({"foo": 1, "bar": 2});
164 expect(inner, equals({"foo": 1, "bar": 2, 1: 1, 2: 2, 3: 3, 4: 4}));
165 });
166
167 test("clear()", () {
168 wrapper.clear();
169 expect(wrapper, isEmpty);
170 });
171
172 test("containsKey()", () {
173 expect(wrapper.containsKey(1), isTrue);
174 expect(wrapper.containsKey(7), isFalse);
175 expect(wrapper.containsKey("foo"), isFalse);
176 });
177
178 test("containsValue()", () {
179 expect(wrapper.containsValue(1), isTrue);
180 expect(wrapper.containsValue(7), isFalse);
181 expect(wrapper.containsValue("foo"), isFalse);
182 });
183
184 test("isEmpty", () {
185 expect(wrapper.isEmpty, isFalse);
186 });
187
188 test("isNotEmpty", () {
189 expect(wrapper.isNotEmpty, isTrue);
190 });
191
192 test("length", () {
193 expect(wrapper.length, equals(4));
194 });
195
196 test("putIfAbsent()", () {
197 expect(wrapper.putIfAbsent("foo", () => 1), equals(1));
198 expect(inner, equals({"foo": 1, 1: 1, 2: 2, 3: 3, 4: 4}));
199 });
200
201 test("remove()", () {
202 expect(wrapper.remove(1), equals(1));
203 expect(inner, equals({2: 2, 3: 3, 4: 4}));
204
205 expect(wrapper.remove("foo"), isNull);
206 expect(wrapper.remove(7), isNull);
207 });
208
209 test("values", () {
210 expect(wrapper.values, unorderedEquals([1, 2, 3, 4]));
211 });
212
213 test("toString()", () {
214 expect(
215 wrapper.toString(),
216 allOf([
217 startsWith("{"),
218 contains("1: 1"),
219 contains("2: 2"),
220 contains("3: 3"),
221 contains("4: 4"),
222 endsWith("}")
223 ]));
224 });
225 });
226 }, skip: "Re-enable this when test can run DDC (test#414).");
227
228 group("with invalid value types", () {
229 var inner;
230 var wrapper;
231 setUp(() {
232 inner = <Object, Object>{"foo": "bar", "baz": "bang"};
233 wrapper = DelegatingMap.typed<String, int>(inner);
234 });
235
236 group("throws a CastError for", () {
237 test("forEach()", () {
238 expect(() => wrapper.forEach(expectAsync2((_, __) {}, count: 0)),
239 throwsCastError);
240 });
241
242 test("[]", () {
243 expect(() => wrapper["foo"], throwsCastError);
244 expect(wrapper["qux"], isNull);
245 });
246
247 test("putIfAbsent()", () {
248 expect(() => wrapper.putIfAbsent("foo", () => 1), throwsCastError);
249 });
250
251 test("remove()", () {
252 expect(() => wrapper.remove("foo"), throwsCastError);
253 });
254
255 test("values", () {
256 var lazy = wrapper.values;
257 expect(() => lazy.first, throwsCastError);
258 });
259 });
260
261 group("doesn't throw a CastError for", () {
262 test("[]=", () {
263 wrapper["foo"] = 5;
264 expect(inner, equals({"foo": 5, "baz": "bang"}));
265 });
266
267 test("addAll()", () {
268 wrapper.addAll({"foo": 1, "qux": 2});
269 expect(inner, equals({"foo": 1, "baz": "bang", "qux": 2}));
270 });
271
272 test("clear()", () {
273 wrapper.clear();
274 expect(wrapper, isEmpty);
275 });
276
277 test("containsKey()", () {
278 expect(wrapper.containsKey("foo"), isTrue);
279 expect(wrapper.containsKey(1), isFalse);
280 expect(wrapper.containsKey("qux"), isFalse);
281 });
282
283 test("containsValue()", () {
284 expect(wrapper.containsValue("bar"), isTrue);
285 expect(wrapper.containsValue(1), isFalse);
286 expect(wrapper.containsValue("foo"), isFalse);
287 });
288
289 test("isEmpty", () {
290 expect(wrapper.isEmpty, isFalse);
291 });
292
293 test("isNotEmpty", () {
294 expect(wrapper.isNotEmpty, isTrue);
295 });
296
297 test("keys", () {
298 expect(wrapper.keys, unorderedEquals(["foo", "baz"]));
299 });
300
301 test("length", () {
302 expect(wrapper.length, equals(2));
303 });
304
305 test("putIfAbsent()", () {
306 expect(wrapper.putIfAbsent("qux", () => 1), equals(1));
307 expect(inner, equals({"foo": "bar", "baz": "bang", "qux": 1}));
308 });
309
310 test("remove()", () {
311 expect(wrapper.remove("qux"), isNull);
312 expect(wrapper.remove(7), isNull);
313 });
314
315 test("toString()", () {
316 expect(
317 wrapper.toString(),
318 allOf([
319 startsWith("{"),
320 contains("foo: bar"),
321 contains("baz: bang"),
322 endsWith("}")
323 ]));
324 });
325 });
326 }, skip: "Re-enable this when test can run DDC (test#414).");
327 }
OLDNEW
« no previous file with comments | « packages/collection/test/typed_wrapper/list_test.dart ('k') | packages/collection/test/typed_wrapper/queue_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698