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