| 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"; | |
| 6 import "package:test/test.dart"; | 5 import "package:test/test.dart"; |
| 7 | 6 |
| 7 import "package:collection/collection.dart"; |
| 8 |
| 8 // Test unmodifiable collection views. | 9 // Test unmodifiable collection views. |
| 9 // The collections should pass through the operations that are allowed, | 10 // The collections should pass through the operations that are allowed, |
| 10 // an throw on the ones that aren't without affecting the original. | 11 // an throw on the ones that aren't without affecting the original. |
| 11 | 12 |
| 12 main() { | 13 main() { |
| 13 List list = []; | 14 List list = []; |
| 14 testUnmodifiableList(list, new UnmodifiableListView(list), "empty"); | 15 testUnmodifiableList(list, new UnmodifiableListView(list), "empty"); |
| 15 list = [42]; | 16 list = [42]; |
| 16 testUnmodifiableList(list, new UnmodifiableListView(list), "single-42"); | 17 testUnmodifiableList(list, new UnmodifiableListView(list), "single-42"); |
| 17 list = [7]; | 18 list = [7]; |
| 18 testUnmodifiableList(list, new UnmodifiableListView(list), "single!42"); | 19 testUnmodifiableList(list, new UnmodifiableListView(list), "single!42"); |
| 19 list = [1, 42, 10]; | 20 list = [1, 42, 10]; |
| 20 testUnmodifiableList(list, new UnmodifiableListView(list), "three-42"); | 21 testUnmodifiableList(list, new UnmodifiableListView(list), "three-42"); |
| 21 list = [1, 7, 10]; | 22 list = [1, 7, 10]; |
| 22 testUnmodifiableList(list, new UnmodifiableListView(list), "three!42"); | 23 testUnmodifiableList(list, new UnmodifiableListView(list), "three!42"); |
| 23 | 24 |
| 24 list = []; | 25 list = []; |
| 25 testNonGrowableList(list, new NonGrowableListView(list), "empty"); | 26 testNonGrowableList(list, new NonGrowableListView(list), "empty"); |
| 26 list = [42]; | 27 list = [42]; |
| 27 testNonGrowableList(list, new NonGrowableListView(list), "single-42"); | 28 testNonGrowableList(list, new NonGrowableListView(list), "single-42"); |
| 28 list = [7]; | 29 list = [7]; |
| 29 testNonGrowableList(list, new NonGrowableListView(list), "single!42"); | 30 testNonGrowableList(list, new NonGrowableListView(list), "single!42"); |
| 30 list = [1, 42, 10]; | 31 list = [1, 42, 10]; |
| 31 testNonGrowableList(list, new NonGrowableListView(list), "three-42"); | 32 testNonGrowableList(list, new NonGrowableListView(list), "three-42"); |
| 32 list = [1, 7, 10]; | 33 list = [1, 7, 10]; |
| 33 testNonGrowableList(list, new NonGrowableListView(list), "three!42"); | 34 testNonGrowableList(list, new NonGrowableListView(list), "three!42"); |
| 34 | 35 |
| 35 Set aSet = new Set(); | 36 Set aSet = new Set(); |
| 36 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "empty"); | 37 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "empty"); |
| 38 aSet = new Set(); |
| 39 testUnmodifiableSet(aSet, const UnmodifiableSetView.empty(), "const empty"); |
| 37 aSet = new Set.from([42]); | 40 aSet = new Set.from([42]); |
| 38 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single-42"); | 41 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single-42"); |
| 39 aSet = new Set.from([7]); | 42 aSet = new Set.from([7]); |
| 40 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single!42"); | 43 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single!42"); |
| 41 aSet = new Set.from([1, 42, 10]); | 44 aSet = new Set.from([1, 42, 10]); |
| 42 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three-42"); | 45 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three-42"); |
| 43 aSet = new Set.from([1, 7, 10]); | 46 aSet = new Set.from([1, 7, 10]); |
| 44 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three!42"); | 47 testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three!42"); |
| 45 } | 48 } |
| 46 | 49 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 expect(wrapped.elementAt(0), equals(original.elementAt(0))); | 87 expect(wrapped.elementAt(0), equals(original.elementAt(0))); |
| 85 } | 88 } |
| 86 }); | 89 }); |
| 87 | 90 |
| 88 test("$name - every", () { | 91 test("$name - every", () { |
| 89 expect(wrapped.every((x) => true), equals(original.every((x) => true))); | 92 expect(wrapped.every((x) => true), equals(original.every((x) => true))); |
| 90 expect(wrapped.every((x) => false), equals(original.every((x) => false))); | 93 expect(wrapped.every((x) => false), equals(original.every((x) => false))); |
| 91 }); | 94 }); |
| 92 | 95 |
| 93 test("$name - expand", () { | 96 test("$name - expand", () { |
| 94 expect(wrapped.expand((x) => [x, x]), | 97 expect( |
| 95 equals(original.expand((x) => [x, x]))); | 98 wrapped.expand((x) => [x, x]), equals(original.expand((x) => [x, x]))); |
| 96 }); | 99 }); |
| 97 | 100 |
| 98 test("$name - first", () { | 101 test("$name - first", () { |
| 99 if (original.isEmpty) { | 102 if (original.isEmpty) { |
| 100 expect(() => wrapped.first, throws); | 103 expect(() => wrapped.first, throws); |
| 101 } else { | 104 } else { |
| 102 expect(wrapped.first, equals(original.first)); | 105 expect(wrapped.first, equals(original.first)); |
| 103 } | 106 } |
| 104 }); | 107 }); |
| 105 | 108 |
| 106 test("$name - firstWhere", () { | 109 test("$name - firstWhere", () { |
| 107 if (original.isEmpty) { | 110 if (original.isEmpty) { |
| 108 expect(() => wrapped.firstWhere((_) => true), throws); | 111 expect(() => wrapped.firstWhere((_) => true), throws); |
| 109 } else { | 112 } else { |
| 110 expect(wrapped.firstWhere((_) => true), | 113 expect(wrapped.firstWhere((_) => true), |
| 111 equals(original.firstWhere((_) => true))); | 114 equals(original.firstWhere((_) => true))); |
| 112 } | 115 } |
| 113 expect(() => wrapped.firstWhere((_) => false), throws); | 116 expect(() => wrapped.firstWhere((_) => false), throws); |
| 114 }); | 117 }); |
| 115 | 118 |
| 116 test("$name - fold", () { | 119 test("$name - fold", () { |
| 117 expect(wrapped.fold(0, (x, y) => x + y), | 120 expect(wrapped.fold(0, (x, y) => x + y), |
| 118 equals(original.fold(0, (x, y) => x + y))); | 121 equals(original.fold(0, (x, y) => x + y))); |
| 119 }); | 122 }); |
| 120 | 123 |
| 121 test("$name - forEach", () { | 124 test("$name - forEach", () { |
| 122 int wrapCtr = 0; | 125 int wrapCtr = 0; |
| 123 int origCtr = 0; | 126 int origCtr = 0; |
| 124 wrapped.forEach((x) { wrapCtr += x; }); | 127 wrapped.forEach((x) { |
| 125 original.forEach((x) { origCtr += x; }); | 128 wrapCtr += x; |
| 129 }); |
| 130 original.forEach((x) { |
| 131 origCtr += x; |
| 132 }); |
| 126 expect(wrapCtr, equals(origCtr)); | 133 expect(wrapCtr, equals(origCtr)); |
| 127 }); | 134 }); |
| 128 | 135 |
| 129 test("$name - isEmpty", () { | 136 test("$name - isEmpty", () { |
| 130 expect(wrapped.isEmpty, equals(original.isEmpty)); | 137 expect(wrapped.isEmpty, equals(original.isEmpty)); |
| 131 }); | 138 }); |
| 132 | 139 |
| 133 test("$name - isNotEmpty", () { | 140 test("$name - isNotEmpty", () { |
| 134 expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); | 141 expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); |
| 135 }); | 142 }); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 155 } else { | 162 } else { |
| 156 expect(wrapped.last, equals(original.last)); | 163 expect(wrapped.last, equals(original.last)); |
| 157 } | 164 } |
| 158 }); | 165 }); |
| 159 | 166 |
| 160 test("$name - lastWhere", () { | 167 test("$name - lastWhere", () { |
| 161 if (original.isEmpty) { | 168 if (original.isEmpty) { |
| 162 expect(() => wrapped.lastWhere((_) => true), throws); | 169 expect(() => wrapped.lastWhere((_) => true), throws); |
| 163 } else { | 170 } else { |
| 164 expect(wrapped.lastWhere((_) => true), | 171 expect(wrapped.lastWhere((_) => true), |
| 165 equals(original.lastWhere((_) => true))); | 172 equals(original.lastWhere((_) => true))); |
| 166 } | 173 } |
| 167 expect(() => wrapped.lastWhere((_) => false), throws); | 174 expect(() => wrapped.lastWhere((_) => false), throws); |
| 168 }); | 175 }); |
| 169 | 176 |
| 170 test("$name - length", () { | 177 test("$name - length", () { |
| 171 expect(wrapped.length, equals(original.length)); | 178 expect(wrapped.length, equals(original.length)); |
| 172 }); | 179 }); |
| 173 | 180 |
| 174 test("$name - map", () { | 181 test("$name - map", () { |
| 175 expect(wrapped.map((x) => "[$x]"), | 182 expect(wrapped.map((x) => "[$x]"), equals(original.map((x) => "[$x]"))); |
| 176 equals(original.map((x) => "[$x]"))); | |
| 177 }); | 183 }); |
| 178 | 184 |
| 179 test("$name - reduce", () { | 185 test("$name - reduce", () { |
| 180 if (original.isEmpty) { | 186 if (original.isEmpty) { |
| 181 expect(() => wrapped.reduce((x, y) => x + y), throws); | 187 expect(() => wrapped.reduce((x, y) => x + y), throws); |
| 182 } else { | 188 } else { |
| 183 expect(wrapped.reduce((x, y) => x + y), | 189 expect(wrapped.reduce((x, y) => x + y), |
| 184 equals(original.reduce((x, y) => x + y))); | 190 equals(original.reduce((x, y) => x + y))); |
| 185 } | 191 } |
| 186 }); | 192 }); |
| 187 | 193 |
| 188 test("$name - single", () { | 194 test("$name - single", () { |
| 189 if (original.length != 1) { | 195 if (original.length != 1) { |
| 190 expect(() => wrapped.single, throws); | 196 expect(() => wrapped.single, throws); |
| 191 } else { | 197 } else { |
| 192 expect(wrapped.single, equals(original.single)); | 198 expect(wrapped.single, equals(original.single)); |
| 193 } | 199 } |
| 194 }); | 200 }); |
| 195 | 201 |
| 196 test("$name - singleWhere", () { | 202 test("$name - singleWhere", () { |
| 197 if (original.length != 1) { | 203 if (original.length != 1) { |
| 198 expect(() => wrapped.singleWhere((_) => true), throws); | 204 expect(() => wrapped.singleWhere((_) => true), throws); |
| 199 } else { | 205 } else { |
| 200 expect(wrapped.singleWhere((_) => true), | 206 expect(wrapped.singleWhere((_) => true), |
| 201 equals(original.singleWhere((_) => true))); | 207 equals(original.singleWhere((_) => true))); |
| 202 } | 208 } |
| 203 expect(() => wrapped.singleWhere((_) => false), throws); | 209 expect(() => wrapped.singleWhere((_) => false), throws); |
| 204 }); | 210 }); |
| 205 | 211 |
| 206 test("$name - skip", () { | 212 test("$name - skip", () { |
| 207 expect(wrapped.skip(0), orderedEquals(original.skip(0))); | 213 expect(wrapped.skip(0), orderedEquals(original.skip(0))); |
| 208 expect(wrapped.skip(1), orderedEquals(original.skip(1))); | 214 expect(wrapped.skip(1), orderedEquals(original.skip(1))); |
| 209 expect(wrapped.skip(5), orderedEquals(original.skip(5))); | 215 expect(wrapped.skip(5), orderedEquals(original.skip(5))); |
| 210 }); | 216 }); |
| 211 | 217 |
| 212 test("$name - skipWhile", () { | 218 test("$name - skipWhile", () { |
| 213 expect(wrapped.skipWhile((x) => true), | 219 expect(wrapped.skipWhile((x) => true), |
| 214 orderedEquals(original.skipWhile((x) => true))); | 220 orderedEquals(original.skipWhile((x) => true))); |
| 215 expect(wrapped.skipWhile((x) => false), | 221 expect(wrapped.skipWhile((x) => false), |
| 216 orderedEquals(original.skipWhile((x) => false))); | 222 orderedEquals(original.skipWhile((x) => false))); |
| 217 expect(wrapped.skipWhile((x) => x != 42), | 223 expect(wrapped.skipWhile((x) => x != 42), |
| 218 orderedEquals(original.skipWhile((x) => x != 42))); | 224 orderedEquals(original.skipWhile((x) => x != 42))); |
| 219 }); | 225 }); |
| 220 | 226 |
| 221 test("$name - take", () { | 227 test("$name - take", () { |
| 222 expect(wrapped.take(0), orderedEquals(original.take(0))); | 228 expect(wrapped.take(0), orderedEquals(original.take(0))); |
| 223 expect(wrapped.take(1), orderedEquals(original.take(1))); | 229 expect(wrapped.take(1), orderedEquals(original.take(1))); |
| 224 expect(wrapped.take(5), orderedEquals(original.take(5))); | 230 expect(wrapped.take(5), orderedEquals(original.take(5))); |
| 225 }); | 231 }); |
| 226 | 232 |
| 227 test("$name - takeWhile", () { | 233 test("$name - takeWhile", () { |
| 228 expect(wrapped.takeWhile((x) => true), | 234 expect(wrapped.takeWhile((x) => true), |
| 229 orderedEquals(original.takeWhile((x) => true))); | 235 orderedEquals(original.takeWhile((x) => true))); |
| 230 expect(wrapped.takeWhile((x) => false), | 236 expect(wrapped.takeWhile((x) => false), |
| 231 orderedEquals(original.takeWhile((x) => false))); | 237 orderedEquals(original.takeWhile((x) => false))); |
| 232 expect(wrapped.takeWhile((x) => x != 42), | 238 expect(wrapped.takeWhile((x) => x != 42), |
| 233 orderedEquals(original.takeWhile((x) => x != 42))); | 239 orderedEquals(original.takeWhile((x) => x != 42))); |
| 234 }); | 240 }); |
| 235 | 241 |
| 236 test("$name - toList", () { | 242 test("$name - toList", () { |
| 237 expect(wrapped.toList(), orderedEquals(original.toList())); | 243 expect(wrapped.toList(), orderedEquals(original.toList())); |
| 238 expect(wrapped.toList(growable: false), | 244 expect(wrapped.toList(growable: false), |
| 239 orderedEquals(original.toList(growable: false))); | 245 orderedEquals(original.toList(growable: false))); |
| 240 }); | 246 }); |
| 241 | 247 |
| 242 test("$name - toSet", () { | 248 test("$name - toSet", () { |
| 243 expect(wrapped.toSet(), unorderedEquals(original.toSet())); | 249 expect(wrapped.toSet(), unorderedEquals(original.toSet())); |
| 244 }); | 250 }); |
| 245 | 251 |
| 246 test("$name - where", () { | 252 test("$name - where", () { |
| 247 expect(wrapped.where((x) => true), | 253 expect( |
| 248 orderedEquals(original.where((x) => true))); | 254 wrapped.where((x) => true), orderedEquals(original.where((x) => true))); |
| 249 expect(wrapped.where((x) => false), | 255 expect(wrapped.where((x) => false), |
| 250 orderedEquals(original.where((x) => false))); | 256 orderedEquals(original.where((x) => false))); |
| 251 expect(wrapped.where((x) => x != 42), | 257 expect(wrapped.where((x) => x != 42), |
| 252 orderedEquals(original.where((x) => x != 42))); | 258 orderedEquals(original.where((x) => x != 42))); |
| 253 }); | 259 }); |
| 254 } | 260 } |
| 255 | 261 |
| 256 void testReadList(List original, List wrapped, String name) { | 262 void testReadList(List original, List wrapped, String name) { |
| 257 test("$name - length", () { | 263 test("$name - length", () { |
| 258 expect(wrapped.length, equals(original.length)); | 264 expect(wrapped.length, equals(original.length)); |
| 259 }); | 265 }); |
| 260 | 266 |
| 261 test("$name - isEmpty", () { | 267 test("$name - isEmpty", () { |
| 262 expect(wrapped.isEmpty, equals(original.isEmpty)); | 268 expect(wrapped.isEmpty, equals(original.isEmpty)); |
| 263 }); | 269 }); |
| 264 | 270 |
| 265 test("$name - isNotEmpty", () { | 271 test("$name - isNotEmpty", () { |
| 266 expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); | 272 expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); |
| 267 }); | 273 }); |
| 268 | 274 |
| 269 test("$name - []", () { | 275 test("$name - []", () { |
| 270 if (original.isEmpty) { | 276 if (original.isEmpty) { |
| 271 expect(() { wrapped[0]; }, throwsRangeError); | 277 expect(() { |
| 278 wrapped[0]; |
| 279 }, throwsRangeError); |
| 272 } else { | 280 } else { |
| 273 expect(wrapped[0], equals(original[0])); | 281 expect(wrapped[0], equals(original[0])); |
| 274 } | 282 } |
| 275 }); | 283 }); |
| 276 | 284 |
| 277 test("$name - indexOf", () { | 285 test("$name - indexOf", () { |
| 278 expect(wrapped.indexOf(42), equals(original.indexOf(42))); | 286 expect(wrapped.indexOf(42), equals(original.indexOf(42))); |
| 279 }); | 287 }); |
| 280 | 288 |
| 281 test("$name - lastIndexOf", () { | 289 test("$name - lastIndexOf", () { |
| 282 expect(wrapped.lastIndexOf(42), equals(original.lastIndexOf(42))); | 290 expect(wrapped.lastIndexOf(42), equals(original.lastIndexOf(42))); |
| 283 }); | 291 }); |
| 284 | 292 |
| 285 test("$name - getRange", () { | 293 test("$name - getRange", () { |
| 286 int len = original.length; | 294 int len = original.length; |
| 287 expect(wrapped.getRange(0, len), equals(original.getRange(0, len))); | 295 expect(wrapped.getRange(0, len), equals(original.getRange(0, len))); |
| 288 expect(wrapped.getRange(len ~/ 2, len), | 296 expect(wrapped.getRange(len ~/ 2, len), |
| 289 equals(original.getRange(len ~/ 2, len))); | 297 equals(original.getRange(len ~/ 2, len))); |
| 290 expect(wrapped.getRange(0, len ~/ 2), | 298 expect( |
| 291 equals(original.getRange(0, len ~/ 2))); | 299 wrapped.getRange(0, len ~/ 2), equals(original.getRange(0, len ~/ 2))); |
| 292 }); | 300 }); |
| 293 | 301 |
| 294 test("$name - sublist", () { | 302 test("$name - sublist", () { |
| 295 int len = original.length; | 303 int len = original.length; |
| 296 expect(wrapped.sublist(0), equals(original.sublist(0))); | 304 expect(wrapped.sublist(0), equals(original.sublist(0))); |
| 297 expect(wrapped.sublist(len ~/ 2), equals(original.sublist(len ~/ 2))); | 305 expect(wrapped.sublist(len ~/ 2), equals(original.sublist(len ~/ 2))); |
| 298 expect(wrapped.sublist(0, len ~/ 2), | 306 expect(wrapped.sublist(0, len ~/ 2), equals(original.sublist(0, len ~/ 2))); |
| 299 equals(original.sublist(0, len ~/ 2))); | |
| 300 }); | 307 }); |
| 301 | 308 |
| 302 test("$name - asMap", () { | 309 test("$name - asMap", () { |
| 303 expect(wrapped.asMap(), equals(original.asMap())); | 310 expect(wrapped.asMap(), equals(original.asMap())); |
| 304 }); | 311 }); |
| 305 } | 312 } |
| 306 | 313 |
| 307 void testNoWriteList(List original, List wrapped, String name) { | 314 void testNoWriteList(List original, List wrapped, String name) { |
| 308 List copy = new List.from(original); | 315 List copy = new List.from(original); |
| 309 | 316 |
| 310 testThrows(name, thunk) { | 317 testThrows(name, thunk) { |
| 311 test(name, () { | 318 test(name, () { |
| 312 expect(thunk, throwsUnsupportedError); | 319 expect(thunk, throwsUnsupportedError); |
| 313 // No modifications happened. | 320 // No modifications happened. |
| 314 expect(original, equals(copy)); | 321 expect(original, equals(copy)); |
| 315 }); | 322 }); |
| 316 } | 323 } |
| 317 | 324 |
| 318 testThrows("$name - []= throws", () { wrapped[0] = 42; }); | 325 testThrows("$name - []= throws", () { |
| 326 wrapped[0] = 42; |
| 327 }); |
| 319 | 328 |
| 320 testThrows("$name - sort throws", () { wrapped.sort(); }); | 329 testThrows("$name - sort throws", () { |
| 330 wrapped.sort(); |
| 331 }); |
| 321 | 332 |
| 322 testThrows("$name - fillRange throws", () { | 333 testThrows("$name - fillRange throws", () { |
| 323 wrapped.fillRange(0, wrapped.length, 42); | 334 wrapped.fillRange(0, wrapped.length, 42); |
| 324 }); | 335 }); |
| 325 | 336 |
| 326 testThrows("$name - setRange throws", () { | 337 testThrows("$name - setRange throws", () { |
| 327 wrapped.setRange(0, wrapped.length, | 338 wrapped.setRange( |
| 328 new Iterable.generate(wrapped.length, (i) => i)); | 339 0, wrapped.length, new Iterable.generate(wrapped.length, (i) => i)); |
| 329 }); | 340 }); |
| 330 | 341 |
| 331 testThrows("$name - setAll throws", () { | 342 testThrows("$name - setAll throws", () { |
| 332 wrapped.setAll(0, new Iterable.generate(wrapped.length, (i) => i)); | 343 wrapped.setAll(0, new Iterable.generate(wrapped.length, (i) => i)); |
| 333 }); | 344 }); |
| 334 } | 345 } |
| 335 | 346 |
| 336 void testWriteList(List original, List wrapped, String name) { | 347 void testWriteList(List original, List wrapped, String name) { |
| 337 List copy = new List.from(original); | 348 List copy = new List.from(original); |
| 338 | 349 |
| 339 test("$name - []=", () { | 350 test("$name - []=", () { |
| 340 if (original.isNotEmpty) { | 351 if (original.isNotEmpty) { |
| 341 int originalFirst = original[0]; | 352 int originalFirst = original[0]; |
| 342 wrapped[0] = originalFirst + 1; | 353 wrapped[0] = originalFirst + 1; |
| 343 expect(original[0], equals(originalFirst + 1)); | 354 expect(original[0], equals(originalFirst + 1)); |
| 344 original[0] = originalFirst; | 355 original[0] = originalFirst; |
| 345 } else { | 356 } else { |
| 346 expect(() { wrapped[0] = 42; }, throws); | 357 expect(() { |
| 358 wrapped[0] = 42; |
| 359 }, throws); |
| 347 } | 360 } |
| 348 }); | 361 }); |
| 349 | 362 |
| 350 test("$name - sort", () { | 363 test("$name - sort", () { |
| 351 List sortCopy = new List.from(original); | 364 List sortCopy = new List.from(original); |
| 352 sortCopy.sort(); | 365 sortCopy.sort(); |
| 353 wrapped.sort(); | 366 wrapped.sort(); |
| 354 expect(original, orderedEquals(sortCopy)); | 367 expect(original, orderedEquals(sortCopy)); |
| 355 original.setAll(0, copy); | 368 original.setAll(0, copy); |
| 356 }); | 369 }); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 expect(wrapped.containsAll(copy), isTrue); | 462 expect(wrapped.containsAll(copy), isTrue); |
| 450 expect(wrapped.containsAll(copy.toList()), isTrue); | 463 expect(wrapped.containsAll(copy.toList()), isTrue); |
| 451 expect(wrapped.containsAll([]), isTrue); | 464 expect(wrapped.containsAll([]), isTrue); |
| 452 expect(wrapped.containsAll([42]), equals(original.containsAll([42]))); | 465 expect(wrapped.containsAll([42]), equals(original.containsAll([42]))); |
| 453 }); | 466 }); |
| 454 | 467 |
| 455 test("$name - intersection", () { | 468 test("$name - intersection", () { |
| 456 expect(wrapped.intersection(new Set()), isEmpty); | 469 expect(wrapped.intersection(new Set()), isEmpty); |
| 457 expect(wrapped.intersection(copy), unorderedEquals(original)); | 470 expect(wrapped.intersection(copy), unorderedEquals(original)); |
| 458 expect(wrapped.intersection(new Set.from([42])), | 471 expect(wrapped.intersection(new Set.from([42])), |
| 459 new Set.from(original.contains(42) ? [42] : [])); | 472 new Set.from(original.contains(42) ? [42] : [])); |
| 460 }); | 473 }); |
| 461 | 474 |
| 462 test("$name - union", () { | 475 test("$name - union", () { |
| 463 expect(wrapped.union(new Set()), unorderedEquals(original)); | 476 expect(wrapped.union(new Set()), unorderedEquals(original)); |
| 464 expect(wrapped.union(copy), unorderedEquals(original)); | 477 expect(wrapped.union(copy), unorderedEquals(original)); |
| 465 expect(wrapped.union(new Set.from([42])), | 478 expect(wrapped.union(new Set.from([42])), |
| 466 equals(original.union(new Set.from([42])))); | 479 equals(original.union(new Set.from([42])))); |
| 467 }); | 480 }); |
| 468 | 481 |
| 469 test("$name - difference", () { | 482 test("$name - difference", () { |
| 470 expect(wrapped.difference(new Set()), unorderedEquals(original)); | 483 expect(wrapped.difference(new Set()), unorderedEquals(original)); |
| 471 expect(wrapped.difference(copy), isEmpty); | 484 expect(wrapped.difference(copy), isEmpty); |
| 472 expect(wrapped.difference(new Set.from([42])), | 485 expect(wrapped.difference(new Set.from([42])), |
| 473 equals(original.difference(new Set.from([42])))); | 486 equals(original.difference(new Set.from([42])))); |
| 474 }); | 487 }); |
| 475 } | 488 } |
| 476 | 489 |
| 477 void testNoChangeSet(Set original, Set wrapped, String name) { | 490 void testNoChangeSet(Set original, Set wrapped, String name) { |
| 478 List originalElements = original.toList(); | 491 List originalElements = original.toList(); |
| 479 | 492 |
| 480 testThrows(name, thunk) { | 493 testThrows(name, thunk) { |
| 481 test(name, () { | 494 test(name, () { |
| 482 expect(thunk, throwsUnsupportedError); | 495 expect(thunk, throwsUnsupportedError); |
| 483 // No modifications happened. | 496 // No modifications happened. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 }); | 563 }); |
| 551 | 564 |
| 552 test("$name containsValue", () { | 565 test("$name containsValue", () { |
| 553 expect(wrapped.containsValue(0), equals(original.containsValue(0))); | 566 expect(wrapped.containsValue(0), equals(original.containsValue(0))); |
| 554 expect(wrapped.containsValue(999), equals(original.containsValue(999))); | 567 expect(wrapped.containsValue(999), equals(original.containsValue(999))); |
| 555 }); | 568 }); |
| 556 | 569 |
| 557 test("$name forEach", () { | 570 test("$name forEach", () { |
| 558 int origCnt = 0; | 571 int origCnt = 0; |
| 559 int wrapCnt = 0; | 572 int wrapCnt = 0; |
| 560 wrapped.forEach((k, v) { wrapCnt += 1 << k + 3 * v; }); | 573 wrapped.forEach((k, v) { |
| 561 original.forEach((k, v) { origCnt += 1 << k + 3 * v; }); | 574 wrapCnt += 1 << k + 3 * v; |
| 575 }); |
| 576 original.forEach((k, v) { |
| 577 origCnt += 1 << k + 3 * v; |
| 578 }); |
| 562 expect(wrapCnt, equals(origCnt)); | 579 expect(wrapCnt, equals(origCnt)); |
| 563 }); | 580 }); |
| 564 | 581 |
| 565 test("$name keys", () { | 582 test("$name keys", () { |
| 566 expect(wrapped.keys, orderedEquals(original.keys)); | 583 expect(wrapped.keys, orderedEquals(original.keys)); |
| 567 }); | 584 }); |
| 568 | 585 |
| 569 test("$name values", () { | 586 test("$name values", () { |
| 570 expect(wrapped.values, orderedEquals(original.values)); | 587 expect(wrapped.values, orderedEquals(original.values)); |
| 571 }); | 588 }); |
| 572 } | 589 } |
| 573 | 590 |
| 574 testNoChangeMap(Map original, Map wrapped, String name) { | 591 testNoChangeMap(Map original, Map wrapped, String name) { |
| 575 Map copy = new Map.from(original); | 592 Map copy = new Map.from(original); |
| 576 | 593 |
| 577 testThrows(name, thunk) { | 594 testThrows(name, thunk) { |
| 578 test(name, () { | 595 test(name, () { |
| 579 expect(thunk, throwsUnsupportedError); | 596 expect(thunk, throwsUnsupportedError); |
| 580 // No modifications happened. | 597 // No modifications happened. |
| 581 expect(original, equals(copy)); | 598 expect(original, equals(copy)); |
| 582 }); | 599 }); |
| 583 } | 600 } |
| 584 | 601 |
| 585 testThrows("$name operator[]= throws", () { | 602 testThrows("$name operator[]= throws", () { |
| 586 wrapped[0] = 42; | 603 wrapped[0] = 42; |
| 587 }); | 604 }); |
| 588 | 605 |
| 589 testThrows("$name putIfAbsent throws", () { | 606 testThrows("$name putIfAbsent throws", () { |
| 590 wrapped.putIfAbsent(0, () => 42); | 607 wrapped.putIfAbsent(0, () => 42); |
| 591 }); | 608 }); |
| 592 | 609 |
| 593 testThrows("$name addAll throws", () { | 610 testThrows("$name addAll throws", () { |
| 594 wrapped.addAll(new Map()..[42] = 42); | 611 wrapped.addAll(new Map()..[42] = 42); |
| 595 }); | 612 }); |
| 596 | 613 |
| 597 testThrows("$name addAll empty throws", () { | 614 testThrows("$name addAll empty throws", () { |
| 598 wrapped.addAll(new Map()); | 615 wrapped.addAll(new Map()); |
| 599 }); | 616 }); |
| 600 | 617 |
| 601 testThrows("$name remove throws", () { | 618 testThrows("$name remove throws", () { |
| 602 wrapped.remove(0); | 619 wrapped.remove(0); |
| 603 }); | 620 }); |
| 604 | 621 |
| 605 testThrows("$name clear throws", () { | 622 testThrows("$name clear throws", () { |
| 606 wrapped.clear(); | 623 wrapped.clear(); |
| 607 }); | 624 }); |
| 608 } | 625 } |
| OLD | NEW |