| 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 = 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(wrapper, | 
|  | 33           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(wrapper, | 
|  | 39           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(results, | 
|  | 63           unorderedEquals([["foo", 1], ["bar", 2], ["baz", 3], ["bang", 4]])); | 
|  | 64 | 
|  | 65       emptyWrapper.forEach(expectAsync((_, __) {}, count: 0)); | 
|  | 66     }); | 
|  | 67 | 
|  | 68     test("isEmpty", () { | 
|  | 69       expect(wrapper.isEmpty, isFalse); | 
|  | 70       expect(emptyWrapper.isEmpty, isTrue); | 
|  | 71     }); | 
|  | 72 | 
|  | 73     test("isNotEmpty", () { | 
|  | 74       expect(wrapper.isNotEmpty, isTrue); | 
|  | 75       expect(emptyWrapper.isNotEmpty, isFalse); | 
|  | 76     }); | 
|  | 77 | 
|  | 78     test("keys", () { | 
|  | 79       expect(wrapper.keys, unorderedEquals(["foo", "bar", "baz", "bang"])); | 
|  | 80       expect(emptyWrapper.keys, isEmpty); | 
|  | 81     }); | 
|  | 82 | 
|  | 83     test("length", () { | 
|  | 84       expect(wrapper.length, equals(4)); | 
|  | 85       expect(emptyWrapper.length, equals(0)); | 
|  | 86     }); | 
|  | 87 | 
|  | 88     test("putIfAbsent()", () { | 
|  | 89       expect(wrapper.putIfAbsent("foo", expectAsync(() => null, count: 0)), | 
|  | 90           equals(1)); | 
|  | 91 | 
|  | 92       expect(wrapper.putIfAbsent("qux", () => 6), equals(6)); | 
|  | 93       expect(wrapper, | 
|  | 94           equals({"foo": 1, "bar": 2, "baz": 3, "bang": 4, "qux": 6})); | 
|  | 95     }); | 
|  | 96 | 
|  | 97     test("remove()", () { | 
|  | 98       expect(wrapper.remove("foo"), equals(1)); | 
|  | 99       expect(wrapper, equals({"bar": 2, "baz": 3, "bang": 4})); | 
|  | 100 | 
|  | 101       expect(wrapper.remove("foo"), isNull); | 
|  | 102       expect(wrapper.remove(3), isNull); | 
|  | 103     }); | 
|  | 104 | 
|  | 105     test("values", () { | 
|  | 106       expect(wrapper.values, unorderedEquals([1, 2, 3, 4])); | 
|  | 107       expect(emptyWrapper.values, isEmpty); | 
|  | 108     }); | 
|  | 109 | 
|  | 110     test("toString()", () { | 
|  | 111       expect(wrapper.toString(), allOf([ | 
|  | 112         startsWith("{"), | 
|  | 113         contains("foo: 1"), | 
|  | 114         contains("bar: 2"), | 
|  | 115         contains("baz: 3"), | 
|  | 116         contains("bang: 4"), | 
|  | 117         endsWith("}") | 
|  | 118       ])); | 
|  | 119     }); | 
|  | 120   }); | 
|  | 121 | 
|  | 122   group("with invalid key types", () { | 
|  | 123     var inner; | 
|  | 124     var wrapper; | 
|  | 125     setUp(() { | 
|  | 126       inner = <Object, Object>{1: 1, 2: 2, 3: 3, 4: 4}; | 
|  | 127       wrapper = DelegatingMap.typed/*<String, int>*/(inner); | 
|  | 128     }); | 
|  | 129 | 
|  | 130     group("throws a CastError for", () { | 
|  | 131       test("forEach()", () { | 
|  | 132         expect(() => wrapper.forEach(expectAsync((_, __) {}, count: 0)), | 
|  | 133             throwsCastError); | 
|  | 134       }); | 
|  | 135 | 
|  | 136       test("keys", () { | 
|  | 137         var lazy = wrapper.keys; | 
|  | 138         expect(() => lazy.first, throwsCastError); | 
|  | 139       }); | 
|  | 140     }); | 
|  | 141 | 
|  | 142     group("doesn't throw a CastError for", () { | 
|  | 143       test("[]", () { | 
|  | 144         expect(wrapper["foo"], isNull); | 
|  | 145         expect(wrapper[1], equals(1)); | 
|  | 146         expect(wrapper[7], isNull); | 
|  | 147       }); | 
|  | 148 | 
|  | 149       test("[]=", () { | 
|  | 150         wrapper["foo"] = 5; | 
|  | 151         expect(inner, equals({"foo": 5, 1: 1, 2: 2, 3: 3, 4: 4})); | 
|  | 152       }); | 
|  | 153 | 
|  | 154       test("addAll()", () { | 
|  | 155         wrapper.addAll({"foo": 1, "bar": 2}); | 
|  | 156         expect(inner, equals({"foo": 1, "bar": 2, 1: 1, 2: 2, 3: 3, 4: 4})); | 
|  | 157       }); | 
|  | 158 | 
|  | 159       test("clear()", () { | 
|  | 160         wrapper.clear(); | 
|  | 161         expect(wrapper, isEmpty); | 
|  | 162       }); | 
|  | 163 | 
|  | 164       test("containsKey()", () { | 
|  | 165         expect(wrapper.containsKey(1), isTrue); | 
|  | 166         expect(wrapper.containsKey(7), isFalse); | 
|  | 167         expect(wrapper.containsKey("foo"), isFalse); | 
|  | 168       }); | 
|  | 169 | 
|  | 170       test("containsValue()", () { | 
|  | 171         expect(wrapper.containsValue(1), isTrue); | 
|  | 172         expect(wrapper.containsValue(7), isFalse); | 
|  | 173         expect(wrapper.containsValue("foo"), isFalse); | 
|  | 174       }); | 
|  | 175 | 
|  | 176       test("isEmpty", () { | 
|  | 177         expect(wrapper.isEmpty, isFalse); | 
|  | 178       }); | 
|  | 179 | 
|  | 180       test("isNotEmpty", () { | 
|  | 181         expect(wrapper.isNotEmpty, isTrue); | 
|  | 182       }); | 
|  | 183 | 
|  | 184       test("length", () { | 
|  | 185         expect(wrapper.length, equals(4)); | 
|  | 186       }); | 
|  | 187 | 
|  | 188       test("putIfAbsent()", () { | 
|  | 189         expect(wrapper.putIfAbsent("foo", () => 1), equals(1)); | 
|  | 190         expect(inner, equals({"foo": 1, 1: 1, 2: 2, 3: 3, 4: 4})); | 
|  | 191       }); | 
|  | 192 | 
|  | 193       test("remove()", () { | 
|  | 194         expect(wrapper.remove(1), equals(1)); | 
|  | 195         expect(inner, equals({2: 2, 3: 3, 4: 4})); | 
|  | 196 | 
|  | 197         expect(wrapper.remove("foo"), isNull); | 
|  | 198         expect(wrapper.remove(7), isNull); | 
|  | 199       }); | 
|  | 200 | 
|  | 201       test("values", () { | 
|  | 202         expect(wrapper.values, unorderedEquals([1, 2, 3, 4])); | 
|  | 203       }); | 
|  | 204 | 
|  | 205       test("toString()", () { | 
|  | 206         expect(wrapper.toString(), allOf([ | 
|  | 207           startsWith("{"), | 
|  | 208           contains("1: 1"), | 
|  | 209           contains("2: 2"), | 
|  | 210           contains("3: 3"), | 
|  | 211           contains("4: 4"), | 
|  | 212           endsWith("}") | 
|  | 213         ])); | 
|  | 214       }); | 
|  | 215     }); | 
|  | 216   }, skip: "Re-enable this when test can run DDC (test#414)."); | 
|  | 217 | 
|  | 218   group("with invalid value types", () { | 
|  | 219     var inner; | 
|  | 220     var wrapper; | 
|  | 221     setUp(() { | 
|  | 222       inner = <Object, Object>{"foo": "bar", "baz": "bang"}; | 
|  | 223       wrapper = DelegatingMap.typed/*<String, int>*/(inner); | 
|  | 224     }); | 
|  | 225 | 
|  | 226     group("throws a CastError for", () { | 
|  | 227       test("forEach()", () { | 
|  | 228         expect(() => wrapper.forEach(expectAsync((_, __) {}, count: 0)), | 
|  | 229             throwsCastError); | 
|  | 230       }); | 
|  | 231 | 
|  | 232       test("[]", () { | 
|  | 233         expect(() => wrapper["foo"], throwsCastError); | 
|  | 234         expect(wrapper["qux"], isNull); | 
|  | 235       }); | 
|  | 236 | 
|  | 237       test("putIfAbsent()", () { | 
|  | 238         expect(() => wrapper.putIfAbsent("foo", () => 1), throwsCastError); | 
|  | 239       }); | 
|  | 240 | 
|  | 241       test("remove()", () { | 
|  | 242         expect(() => wrapper.remove("foo"), throwsCastError); | 
|  | 243       }); | 
|  | 244 | 
|  | 245       test("values", () { | 
|  | 246         var lazy = wrapper.values; | 
|  | 247         expect(() => lazy.first, throwsCastError); | 
|  | 248       }); | 
|  | 249     }); | 
|  | 250 | 
|  | 251     group("doesn't throw a CastError for", () { | 
|  | 252       test("[]=", () { | 
|  | 253         wrapper["foo"] = 5; | 
|  | 254         expect(inner, equals({"foo": 5, "baz": "bang"})); | 
|  | 255       }); | 
|  | 256 | 
|  | 257       test("addAll()", () { | 
|  | 258         wrapper.addAll({"foo": 1, "qux": 2}); | 
|  | 259         expect(inner, equals({"foo": 1, "baz": "bang", "qux": 2})); | 
|  | 260       }); | 
|  | 261 | 
|  | 262       test("clear()", () { | 
|  | 263         wrapper.clear(); | 
|  | 264         expect(wrapper, isEmpty); | 
|  | 265       }); | 
|  | 266 | 
|  | 267       test("containsKey()", () { | 
|  | 268         expect(wrapper.containsKey("foo"), isTrue); | 
|  | 269         expect(wrapper.containsKey(1), isFalse); | 
|  | 270         expect(wrapper.containsKey("qux"), isFalse); | 
|  | 271       }); | 
|  | 272 | 
|  | 273       test("containsValue()", () { | 
|  | 274         expect(wrapper.containsValue("bar"), isTrue); | 
|  | 275         expect(wrapper.containsValue(1), isFalse); | 
|  | 276         expect(wrapper.containsValue("foo"), isFalse); | 
|  | 277       }); | 
|  | 278 | 
|  | 279       test("isEmpty", () { | 
|  | 280         expect(wrapper.isEmpty, isFalse); | 
|  | 281       }); | 
|  | 282 | 
|  | 283       test("isNotEmpty", () { | 
|  | 284         expect(wrapper.isNotEmpty, isTrue); | 
|  | 285       }); | 
|  | 286 | 
|  | 287       test("keys", () { | 
|  | 288         expect(wrapper.keys, unorderedEquals(["foo", "baz"])); | 
|  | 289       }); | 
|  | 290 | 
|  | 291       test("length", () { | 
|  | 292         expect(wrapper.length, equals(2)); | 
|  | 293       }); | 
|  | 294 | 
|  | 295       test("putIfAbsent()", () { | 
|  | 296         expect(wrapper.putIfAbsent("qux", () => 1), equals(1)); | 
|  | 297         expect(inner, equals({"foo": "bar", "baz": "bang", "qux": 1})); | 
|  | 298       }); | 
|  | 299 | 
|  | 300       test("remove()", () { | 
|  | 301         expect(wrapper.remove("qux"), isNull); | 
|  | 302         expect(wrapper.remove(7), isNull); | 
|  | 303       }); | 
|  | 304 | 
|  | 305       test("toString()", () { | 
|  | 306         expect(wrapper.toString(), allOf([ | 
|  | 307           startsWith("{"), | 
|  | 308           contains("foo: bar"), | 
|  | 309           contains("baz: bang"), | 
|  | 310           endsWith("}") | 
|  | 311         ])); | 
|  | 312       }); | 
|  | 313     }); | 
|  | 314   }, skip: "Re-enable this when test can run DDC (test#414)."); | 
|  | 315 } | 
| OLD | NEW | 
|---|