OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "package:collection/wrappers.dart"; | 5 import "package:collection/wrappers.dart"; |
6 import "package:test/test.dart"; | 6 import "package:test/test.dart"; |
7 | 7 |
8 // Test unmodifiable collection views. | 8 // Test unmodifiable collection views. |
9 // The collections should pass through the operations that are allowed, | 9 // The collections should pass through the operations that are allowed, |
10 // an throw on the ones that aren't without affecting the original. | 10 // an throw on the ones that aren't without affecting the original. |
(...skipping 24 matching lines...) Expand all Loading... |
35 Set aSet = new Set(); | 35 Set aSet = new Set(); |
36 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "empty"); | 36 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "empty"); |
37 aSet = new Set.from([42]); | 37 aSet = new Set.from([42]); |
38 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single-42"); | 38 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single-42"); |
39 aSet = new Set.from([7]); | 39 aSet = new Set.from([7]); |
40 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single!42"); | 40 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single!42"); |
41 aSet = new Set.from([1, 42, 10]); | 41 aSet = new Set.from([1, 42, 10]); |
42 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three-42"); | 42 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three-42"); |
43 aSet = new Set.from([1, 7, 10]); | 43 aSet = new Set.from([1, 7, 10]); |
44 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three!42"); | 44 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three!42"); |
45 | |
46 Map map = new Map(); | |
47 testUnmodifiableMap(map, new UnmodifiableMapView(map), "empty"); | |
48 map = new Map()..[0] = 2; | |
49 testUnmodifiableMap(map, new UnmodifiableMapView(map), "single-0"); | |
50 map = new Map()..[3] = 2; | |
51 testUnmodifiableMap(map, new UnmodifiableMapView(map), "single!0"); | |
52 map = new Map()..[0] = 2 | |
53 ..[1] = 1 | |
54 ..[2] = 0; | |
55 testUnmodifiableMap(map, new UnmodifiableMapView(map), "three-0"); | |
56 map = new Map()..[3] = 2 | |
57 ..[1] = 1 | |
58 ..[2] = 3; | |
59 testUnmodifiableMap(map, new UnmodifiableMapView(map), "three!0"); | |
60 } | 45 } |
61 | 46 |
62 void testUnmodifiableList(List original, List wrapped, String name) { | 47 void testUnmodifiableList(List original, List wrapped, String name) { |
63 name = "unmodifiable-list-$name"; | 48 name = "unmodifiable-list-$name"; |
64 testIterable(original, wrapped, name); | 49 testIterable(original, wrapped, name); |
65 testReadList(original, wrapped, name); | 50 testReadList(original, wrapped, name); |
66 testNoWriteList(original, wrapped, name); | 51 testNoWriteList(original, wrapped, name); |
67 testNoChangeLengthList(original, wrapped, name); | 52 testNoChangeLengthList(original, wrapped, name); |
68 } | 53 } |
69 | 54 |
70 void testNonGrowableList(List original, List wrapped, String name) { | 55 void testNonGrowableList(List original, List wrapped, String name) { |
71 name = "nongrowable-list-$name"; | 56 name = "nongrowable-list-$name"; |
72 testIterable(original, wrapped, name); | 57 testIterable(original, wrapped, name); |
73 testReadList(original, wrapped, name); | 58 testReadList(original, wrapped, name); |
74 testWriteList(original, wrapped, name); | 59 testWriteList(original, wrapped, name); |
75 testNoChangeLengthList(original, wrapped, name); | 60 testNoChangeLengthList(original, wrapped, name); |
76 } | 61 } |
77 | 62 |
78 void testUnmodifiableSet(Set original, Set wrapped, String name) { | 63 void testUnmodifiableSet(Set original, Set wrapped, String name) { |
79 name = "unmodifiable-set-$name"; | 64 name = "unmodifiable-set-$name"; |
80 testIterable(original, wrapped, name); | 65 testIterable(original, wrapped, name); |
81 testReadSet(original, wrapped, name); | 66 testReadSet(original, wrapped, name); |
82 testNoChangeSet(original, wrapped, name); | 67 testNoChangeSet(original, wrapped, name); |
83 } | 68 } |
84 | 69 |
85 void testUnmodifiableMap(Map original, Map wrapped, name) { | |
86 name = "unmodifiable-map-$name"; | |
87 testReadMap(original, wrapped, name); | |
88 testNoChangeMap(original, wrapped, name); | |
89 } | |
90 | |
91 void testIterable(Iterable original, Iterable wrapped, String name) { | 70 void testIterable(Iterable original, Iterable wrapped, String name) { |
92 test("$name - any", () { | 71 test("$name - any", () { |
93 expect(wrapped.any((x) => true), equals(original.any((x) => true))); | 72 expect(wrapped.any((x) => true), equals(original.any((x) => true))); |
94 expect(wrapped.any((x) => false), equals(original.any((x) => false))); | 73 expect(wrapped.any((x) => false), equals(original.any((x) => false))); |
95 }); | 74 }); |
96 | 75 |
97 test("$name - contains", () { | 76 test("$name - contains", () { |
98 expect(wrapped.contains(0), equals(original.contains(0))); | 77 expect(wrapped.contains(0), equals(original.contains(0))); |
99 }); | 78 }); |
100 | 79 |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 }); | 599 }); |
621 | 600 |
622 testThrows("$name remove throws", () { | 601 testThrows("$name remove throws", () { |
623 wrapped.remove(0); | 602 wrapped.remove(0); |
624 }); | 603 }); |
625 | 604 |
626 testThrows("$name clear throws", () { | 605 testThrows("$name clear throws", () { |
627 wrapped.clear(); | 606 wrapped.clear(); |
628 }); | 607 }); |
629 } | 608 } |
OLD | NEW |