OLD | NEW |
(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 setUp(() { |
| 14 wrapper = DelegatingSet.typed<int>(new Set<Object>.from([1, 2, 3, 4, 5])); |
| 15 }); |
| 16 |
| 17 test("add()", () { |
| 18 wrapper.add(1); |
| 19 wrapper.add(6); |
| 20 expect(wrapper, unorderedEquals([1, 2, 3, 4, 5, 6])); |
| 21 }); |
| 22 |
| 23 test("addAll()", () { |
| 24 wrapper.addAll([1, 6, 7]); |
| 25 expect(wrapper, unorderedEquals([1, 2, 3, 4, 5, 6, 7])); |
| 26 }); |
| 27 |
| 28 test("clear()", () { |
| 29 wrapper.clear(); |
| 30 expect(wrapper, isEmpty); |
| 31 }); |
| 32 |
| 33 test("containsAll()", () { |
| 34 expect(wrapper.containsAll([1, 3, 5]), isTrue); |
| 35 expect(wrapper.containsAll([1, 3, 6]), isFalse); |
| 36 expect(wrapper.containsAll([1, 3, "foo"]), isFalse); |
| 37 }); |
| 38 |
| 39 test("difference()", () { |
| 40 expect(wrapper.difference(new Set.from([1, 3, 6])), |
| 41 unorderedEquals([2, 4, 5])); |
| 42 }); |
| 43 |
| 44 test("intersection()", () { |
| 45 expect(wrapper.intersection(new Set.from([1, 3, 6, "foo"])), |
| 46 unorderedEquals([1, 3])); |
| 47 }); |
| 48 |
| 49 test("lookup()", () { |
| 50 expect(wrapper.lookup(1), equals(1)); |
| 51 expect(wrapper.lookup(7), isNull); |
| 52 expect(wrapper.lookup("foo"), isNull); |
| 53 }); |
| 54 |
| 55 test("remove()", () { |
| 56 expect(wrapper.remove(3), isTrue); |
| 57 expect(wrapper, unorderedEquals([1, 2, 4, 5])); |
| 58 |
| 59 expect(wrapper.remove(3), isFalse); |
| 60 expect(wrapper.remove("foo"), isFalse); |
| 61 }); |
| 62 |
| 63 test("removeAll()", () { |
| 64 wrapper.removeAll([1, 3, 6, "foo"]); |
| 65 expect(wrapper, unorderedEquals([2, 4, 5])); |
| 66 }); |
| 67 |
| 68 test("removeWhere()", () { |
| 69 wrapper.removeWhere((i) => i.isOdd); |
| 70 expect(wrapper, unorderedEquals([2, 4])); |
| 71 }); |
| 72 |
| 73 test("retainAll()", () { |
| 74 wrapper.retainAll([1, 3, 6, "foo"]); |
| 75 expect(wrapper, unorderedEquals([1, 3])); |
| 76 }); |
| 77 |
| 78 test("retainWhere()", () { |
| 79 wrapper.retainWhere((i) => i.isOdd); |
| 80 expect(wrapper, unorderedEquals([1, 3, 5])); |
| 81 }); |
| 82 |
| 83 test("union()", () { |
| 84 expect(wrapper.union(new Set.from([5, 6, 7])), |
| 85 unorderedEquals([1, 2, 3, 4, 5, 6, 7])); |
| 86 }); |
| 87 }); |
| 88 |
| 89 group("with invalid types", () { |
| 90 var inner; |
| 91 var wrapper; |
| 92 setUp(() { |
| 93 inner = new Set<Object>.from(["foo", "bar", "baz"]); |
| 94 wrapper = DelegatingSet.typed<int>(inner); |
| 95 }); |
| 96 |
| 97 group("throws a CastError for", () { |
| 98 test("difference()", () { |
| 99 var result = wrapper.difference(new Set.from([1, 3, 6])); |
| 100 expect(() => result.first, throwsCastError); |
| 101 }); |
| 102 |
| 103 test("intersection()", () { |
| 104 var result = wrapper.intersection(new Set.from([1, 3, 6, "foo"])); |
| 105 expect(() => result.first, throwsCastError); |
| 106 }); |
| 107 |
| 108 test("lookup()", () { |
| 109 expect(() => wrapper.lookup("foo"), throwsCastError); |
| 110 }); |
| 111 |
| 112 test("removeWhere()", () { |
| 113 expect(() => wrapper.removeWhere(expectAsync1((_) => false, count: 0)), |
| 114 throwsCastError); |
| 115 }); |
| 116 |
| 117 test("retainWhere()", () { |
| 118 expect(() => wrapper.retainWhere(expectAsync1((_) => false, count: 0)), |
| 119 throwsCastError); |
| 120 }); |
| 121 |
| 122 test("union()", () { |
| 123 var result = wrapper.union(new Set.from([5, 6, 7])); |
| 124 expect(() => result.first, throwsCastError); |
| 125 }); |
| 126 }); |
| 127 |
| 128 group("doesn't throw a CastError for", () { |
| 129 test("add()", () { |
| 130 wrapper.add(6); |
| 131 expect(inner, unorderedEquals(["foo", "bar", "baz", 6])); |
| 132 }); |
| 133 |
| 134 test("addAll()", () { |
| 135 wrapper.addAll([6, 7]); |
| 136 expect(inner, unorderedEquals(["foo", "bar", "baz", 6, 7])); |
| 137 }); |
| 138 |
| 139 test("clear()", () { |
| 140 wrapper.clear(); |
| 141 expect(wrapper, isEmpty); |
| 142 }); |
| 143 |
| 144 test("containsAll()", () { |
| 145 expect(wrapper.containsAll(["foo", "bar"]), isTrue); |
| 146 expect(wrapper.containsAll(["foo", "bar", 1]), isFalse); |
| 147 }); |
| 148 |
| 149 test("lookup()", () { |
| 150 expect(wrapper.lookup(1), isNull); |
| 151 expect(wrapper.lookup("zap"), isNull); |
| 152 }); |
| 153 |
| 154 test("remove()", () { |
| 155 expect(wrapper.remove("foo"), isTrue); |
| 156 expect(inner, unorderedEquals(["bar", "baz"])); |
| 157 |
| 158 expect(wrapper.remove(3), isFalse); |
| 159 expect(wrapper.remove("foo"), isFalse); |
| 160 }); |
| 161 |
| 162 test("removeAll()", () { |
| 163 wrapper.removeAll([1, "foo", "baz"]); |
| 164 expect(inner, unorderedEquals(["bar"])); |
| 165 }); |
| 166 |
| 167 test("retainAll()", () { |
| 168 wrapper.retainAll([1, "foo", "baz"]); |
| 169 expect(inner, unorderedEquals(["foo", "baz"])); |
| 170 }); |
| 171 }); |
| 172 }, skip: "Re-enable this when test can run DDC (test#414)."); |
| 173 } |
OLD | NEW |