| 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 /// Tests wrapper utilities. | 5 /// Tests wrapper utilities. |
| 6 | 6 |
| 7 import "dart:collection"; | 7 import "dart:collection"; |
| 8 import "package:collection/collection.dart"; | 8 import "package:collection/collection.dart"; |
| 9 import "package:test/test.dart"; | 9 import "package:test/test.dart"; |
| 10 | 10 |
| 11 // Test that any member access/call on the wrapper object is equal to | 11 // Test that any member access/call on the wrapper object is equal to |
| 12 // an expected access on the wrapped object. | 12 // an expected access on the wrapped object. |
| 13 // This is implemented by capturing accesses using noSuchMethod and comparing | 13 // This is implemented by capturing accesses using noSuchMethod and comparing |
| 14 // them to expected accesses captured previously. | 14 // them to expected accesses captured previously. |
| 15 | 15 |
| 16 // Compare two Invocations for having equal type and arguments. | 16 // Compare two Invocations for having equal type and arguments. |
| 17 void testInvocations(Invocation i1, Invocation i2) { | 17 void testInvocations(Invocation i1, Invocation i2) { |
| 18 String name = "${i1.memberName}"; | 18 String name = "${i1.memberName}"; |
| 19 expect(i1.isGetter, equals(i2.isGetter), reason: name); | 19 expect(i1.isGetter, equals(i2.isGetter), reason: name); |
| 20 expect(i1.isSetter, equals(i2.isSetter), reason: name); | 20 expect(i1.isSetter, equals(i2.isSetter), reason: name); |
| 21 expect(i1.memberName, equals(i2.memberName), reason: name); | 21 expect(i1.memberName, equals(i2.memberName), reason: name); |
| 22 expect(i1.positionalArguments, equals(i2.positionalArguments), reason: name); | 22 expect(i1.positionalArguments, equals(i2.positionalArguments), reason: name); |
| 23 expect(i1.namedArguments, equals(i2.namedArguments), reason: name); | 23 expect(i1.namedArguments, equals(i2.namedArguments), reason: name); |
| 24 } | 24 } |
| 25 | 25 |
| 26 /** | 26 /// Utility class to record a member access and a member access on a wrapped |
| 27 * Utility class to record a member access and a member access on a wrapped | 27 /// object, and compare them for equality. |
| 28 * object, and compare them for equality. | |
| 29 */ | |
| 30 abstract class Expector { | 28 abstract class Expector { |
| 31 getWrappedObject(action(Invocation i)); | 29 getWrappedObject(action(Invocation i)); |
| 32 // Hack to test assignment ([]=) because it doesn't return the result | 30 // Hack to test assignment ([]=) because it doesn't return the result |
| 33 // of the member call. Instead use (expect..[4]=5).equal[4]=5 where | 31 // of the member call. Instead use (expect..[4]=5).equal[4]=5 where |
| 34 // you would normally use expect[4].equals[4] for non-assignments. | 32 // you would normally use expect[4].equals[4] for non-assignments. |
| 35 var equals; | 33 var equals; |
| 36 | 34 |
| 37 noSuchMethod(Invocation m) => new _Equals(equals = getWrappedObject((m2) { | 35 noSuchMethod(Invocation m) => new _Equals(equals = getWrappedObject((m2) { |
| 38 testInvocations(m, m2); | 36 testInvocations(m, m2); |
| 39 })); | 37 })); |
| 40 | 38 |
| 41 toString() => new _Equals(equals = getWrappedObject((m2) { | 39 // dartanalyzer complains if this method is named `toString()`, since, if it |
| 42 testInvocations(TO_STRING_INVOCATION, m2); | 40 // truly overrides Object's `toString()`, it should return a String. |
| 43 })); | 41 asString() => new _Equals(equals = getWrappedObject((m2) { |
| 42 testInvocations(TO_STRING_INVOCATION, m2); |
| 43 })); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // An object with a field called "equals", only introduced into the | 46 // An object with a field called "equals", only introduced into the |
| 47 // flow to allow writing expect.xxx.equals.xxx. | 47 // flow to allow writing expect.xxx.equals.xxx. |
| 48 class _Equals { | 48 class _Equals { |
| 49 final equals; | 49 final equals; |
| 50 _Equals(this.equals); | 50 _Equals(this.equals); |
| 51 } | 51 } |
| 52 | 52 |
| 53 class SyntheticInvocation implements Invocation { | 53 class SyntheticInvocation implements Invocation { |
| 54 static const int METHOD = 0x00; | 54 static const int METHOD = 0x00; |
| 55 static const int GETTER = 0x01; | 55 static const int GETTER = 0x01; |
| 56 static const int SETTER = 0x02; | 56 static const int SETTER = 0x02; |
| 57 final Symbol memberName; | 57 final Symbol memberName; |
| 58 final List positionalArguments; | 58 final List positionalArguments; |
| 59 final Map namedArguments; | 59 final Map<Symbol, dynamic> namedArguments; |
| 60 final int _type; | 60 final int _type; |
| 61 const SyntheticInvocation(this.memberName, | 61 const SyntheticInvocation(this.memberName, this.positionalArguments, |
| 62 this.positionalArguments, | 62 this.namedArguments, this._type); |
| 63 this.namedArguments, | 63 |
| 64 this._type); | 64 List<Type> get typeArguments => const <Type>[]; |
| 65 |
| 65 bool get isMethod => _type == METHOD; | 66 bool get isMethod => _type == METHOD; |
| 66 | 67 |
| 67 bool get isGetter => _type == GETTER; | 68 bool get isGetter => _type == GETTER; |
| 68 | 69 |
| 69 bool get isSetter => _type == SETTER; | 70 bool get isSetter => _type == SETTER; |
| 70 | 71 |
| 71 bool get isAccessor => isGetter || isSetter; | 72 bool get isAccessor => isGetter || isSetter; |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Parameterization of noSuchMethod. | 75 // Parameterization of noSuchMethod. |
| 75 class NSM { | 76 class NSM { |
| 76 Function _action; | 77 Function _action; |
| 77 NSM(this._action); | 78 NSM(this._action); |
| 78 noSuchMethod(Invocation i) => _action(i); | 79 noSuchMethod(Invocation i) => _action(i); |
| 79 } | 80 } |
| 80 | 81 |
| 81 const TO_STRING_INVOCATION = const SyntheticInvocation( | 82 const TO_STRING_INVOCATION = const SyntheticInvocation( |
| 82 #toString, const[], const{}, SyntheticInvocation.METHOD); | 83 #toString, const [], const {}, SyntheticInvocation.METHOD); |
| 83 | 84 |
| 84 // LikeNSM, but has types Iterable, Set and List to allow it as | 85 // LikeNSM, but has types Iterable, Set and List to allow it as |
| 85 // argument to DelegatingIterable/Set/List. | 86 // argument to DelegatingIterable/Set/List. |
| 86 class IterableNSM extends NSM implements Iterable, Set, List, Queue { | 87 class IterableNSM extends NSM implements Iterable, Set, List, Queue { |
| 87 IterableNSM(action(Invocation i)) : super(action); | 88 IterableNSM(action(Invocation i)) : super(action); |
| 88 noSuchMethod(Invocation i) => super.noSuchMethod(i); // Silence warnings | |
| 89 toString() => super.noSuchMethod(TO_STRING_INVOCATION); | 89 toString() => super.noSuchMethod(TO_STRING_INVOCATION); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Expector that wraps in DelegatingIterable. | 92 // Expector that wraps in DelegatingIterable. |
| 93 class IterableExpector extends Expector { | 93 class IterableExpector extends Expector { |
| 94 getWrappedObject(void action(Invocation i)) { | 94 getWrappedObject(void action(Invocation i)) { |
| 95 return new DelegatingIterable(new IterableNSM(action)); | 95 return new DelegatingIterable(new IterableNSM(action)); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 // Expector that wraps in DelegatingSet. | 113 // Expector that wraps in DelegatingSet. |
| 114 class QueueExpector extends Expector { | 114 class QueueExpector extends Expector { |
| 115 getWrappedObject(void action(Invocation i)) { | 115 getWrappedObject(void action(Invocation i)) { |
| 116 return new DelegatingQueue(new IterableNSM(action)); | 116 return new DelegatingQueue(new IterableNSM(action)); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Like NSM but implements Map to allow as argument for DelegatingMap. | 120 // Like NSM but implements Map to allow as argument for DelegatingMap. |
| 121 class MapNSM extends NSM implements Map { | 121 class MapNSM extends NSM implements Map { |
| 122 MapNSM(action(Invocation i)) : super(action); | 122 MapNSM(action(Invocation i)) : super(action); |
| 123 noSuchMethod(Invocation i) => super.noSuchMethod(i); | |
| 124 toString() => super.noSuchMethod(TO_STRING_INVOCATION); | 123 toString() => super.noSuchMethod(TO_STRING_INVOCATION); |
| 125 } | 124 } |
| 126 | 125 |
| 127 // Expector that wraps in DelegatingMap. | 126 // Expector that wraps in DelegatingMap. |
| 128 class MapExpector extends Expector { | 127 class MapExpector extends Expector { |
| 129 getWrappedObject(void action(Invocation i)) { | 128 getWrappedObject(void action(Invocation i)) { |
| 130 return new DelegatingMap(new MapNSM(action)); | 129 return new DelegatingMap(new MapNSM(action)); |
| 131 } | 130 } |
| 132 } | 131 } |
| 133 | 132 |
| 134 // Utility values to use as arguments in calls. | 133 // Utility values to use as arguments in calls. |
| 135 func0() {} | 134 func0() {} |
| 136 func1(x) {} | 135 func1(x) {} |
| 137 func2(x, y) {} | 136 func2(x, y) {} |
| 138 var val = new Object(); | 137 var val = new Object(); |
| 139 | 138 |
| 140 void main() { | 139 void main() { |
| 141 testIterable(var expect) { | 140 testIterable(var expect) { |
| 142 expect.any(func1).equals.any(func1); | 141 expect.any(func1).equals.any(func1); |
| 143 expect.contains(val).equals.contains(val); | 142 expect.contains(val).equals.contains(val); |
| 144 expect.elementAt(0).equals.elementAt(0); | 143 expect.elementAt(0).equals.elementAt(0); |
| 145 expect.every(func1).equals.every(func1); | 144 expect.every(func1).equals.every(func1); |
| 146 expect.expand(func1).equals.expand(func1); | 145 expect.expand(func1).equals.expand(func1); |
| 147 expect.first.equals.first; | 146 expect.first.equals.first; |
| 148 // Default values of the Iterable interface will be added in the | 147 // Default values of the Iterable interface will be added in the |
| 149 // second call to firstWhere, so we must record them in our | 148 // second call to firstWhere, so we must record them in our |
| 150 // expectation (which doesn't have the interface implemented or | 149 // expectation (which doesn't have the interface implemented or |
| 151 // its default values). | 150 // its default values). |
| 152 expect.firstWhere(func1, orElse: null).equals.firstWhere(func1); | 151 expect.firstWhere(func1, orElse: null).equals.firstWhere(func1); |
| 153 expect.firstWhere(func1, orElse: func0).equals. | 152 expect |
| 154 firstWhere(func1, orElse: func0); | 153 .firstWhere(func1, orElse: func0) |
| 154 .equals |
| 155 .firstWhere(func1, orElse: func0); |
| 155 expect.fold(null, func2).equals.fold(null, func2); | 156 expect.fold(null, func2).equals.fold(null, func2); |
| 156 expect.forEach(func1).equals.forEach(func1); | 157 expect.forEach(func1).equals.forEach(func1); |
| 157 expect.isEmpty.equals.isEmpty; | 158 expect.isEmpty.equals.isEmpty; |
| 158 expect.isNotEmpty.equals.isNotEmpty; | 159 expect.isNotEmpty.equals.isNotEmpty; |
| 159 expect.iterator.equals.iterator; | 160 expect.iterator.equals.iterator; |
| 160 expect.join('').equals.join(); | 161 expect.join('').equals.join(); |
| 161 expect.join("X").equals.join("X"); | 162 expect.join("X").equals.join("X"); |
| 162 expect.last.equals.last; | 163 expect.last.equals.last; |
| 163 expect.lastWhere(func1, orElse: null).equals.lastWhere(func1); | 164 expect.lastWhere(func1, orElse: null).equals.lastWhere(func1); |
| 164 expect.lastWhere(func1, orElse: func0).equals. | 165 expect |
| 165 lastWhere(func1, orElse: func0); | 166 .lastWhere(func1, orElse: func0) |
| 167 .equals |
| 168 .lastWhere(func1, orElse: func0); |
| 166 expect.length.equals.length; | 169 expect.length.equals.length; |
| 167 expect.map(func1).equals.map(func1); | 170 expect.map(func1).equals.map(func1); |
| 168 expect.reduce(func2).equals.reduce(func2); | 171 expect.reduce(func2).equals.reduce(func2); |
| 169 expect.single.equals.single; | 172 expect.single.equals.single; |
| 170 expect.singleWhere(func1).equals.singleWhere(func1); | 173 expect.singleWhere(func1).equals.singleWhere(func1); |
| 171 expect.skip(5).equals.skip(5); | 174 expect.skip(5).equals.skip(5); |
| 172 expect.skipWhile(func1).equals.skipWhile(func1); | 175 expect.skipWhile(func1).equals.skipWhile(func1); |
| 173 expect.take(5).equals.take(5); | 176 expect.take(5).equals.take(5); |
| 174 expect.takeWhile(func1).equals.takeWhile(func1); | 177 expect.takeWhile(func1).equals.takeWhile(func1); |
| 175 expect.toList(growable: true).equals.toList(); | 178 expect.toList(growable: true).equals.toList(); |
| 176 expect.toList(growable: true).equals.toList(growable: true); | 179 expect.toList(growable: true).equals.toList(growable: true); |
| 177 expect.toList(growable: false).equals.toList(growable: false); | 180 expect.toList(growable: false).equals.toList(growable: false); |
| 178 expect.toSet().equals.toSet(); | 181 expect.toSet().equals.toSet(); |
| 179 expect.toString().equals.toString(); | 182 expect.asString().equals.toString(); |
| 180 expect.where(func1).equals.where(func1); | 183 expect.where(func1).equals.where(func1); |
| 181 } | 184 } |
| 182 | 185 |
| 183 void testList(var expect) { | 186 void testList(var expect) { |
| 184 testIterable(expect); | 187 testIterable(expect); |
| 185 | 188 |
| 186 expect[4].equals[4]; | 189 expect[4].equals[4]; |
| 187 (expect..[4] = 5).equals[4] = 5; | 190 (expect..[4] = 5).equals[4] = 5; |
| 188 | 191 |
| 189 expect.add(val).equals.add(val); | 192 expect.add(val).equals.add(val); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 expect.containsKey(val).equals.containsKey(val); | 258 expect.containsKey(val).equals.containsKey(val); |
| 256 expect.containsValue(val).equals.containsValue(val); | 259 expect.containsValue(val).equals.containsValue(val); |
| 257 expect.forEach(func2).equals.forEach(func2); | 260 expect.forEach(func2).equals.forEach(func2); |
| 258 expect.isEmpty.equals.isEmpty; | 261 expect.isEmpty.equals.isEmpty; |
| 259 expect.isNotEmpty.equals.isNotEmpty; | 262 expect.isNotEmpty.equals.isNotEmpty; |
| 260 expect.keys.equals.keys; | 263 expect.keys.equals.keys; |
| 261 expect.length.equals.length; | 264 expect.length.equals.length; |
| 262 expect.putIfAbsent(val, func0).equals.putIfAbsent(val, func0); | 265 expect.putIfAbsent(val, func0).equals.putIfAbsent(val, func0); |
| 263 expect.remove(val).equals.remove(val); | 266 expect.remove(val).equals.remove(val); |
| 264 expect.values.equals.values; | 267 expect.values.equals.values; |
| 265 expect.toString().equals.toString(); | 268 expect.asString().equals.toString(); |
| 266 } | 269 } |
| 267 | 270 |
| 268 // Runs tests of Set behavior. | 271 // Runs tests of Set behavior. |
| 269 // | 272 // |
| 270 // [setUpSet] should return a set with two elements: "foo" and "bar". | 273 // [setUpSet] should return a set with two elements: "foo" and "bar". |
| 271 void testTwoElementSet(Set<String> setUpSet()) { | 274 void testTwoElementSet(Set<String> setUpSet()) { |
| 272 group("with two elements", () { | 275 group("with two elements", () { |
| 273 var set; | 276 var set; |
| 274 setUp(() => set = setUpSet()); | 277 setUp(() => set = setUpSet()); |
| 275 | 278 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 test(".join", () { | 334 test(".join", () { |
| 332 expect(set.join(", "), equals("foo, bar")); | 335 expect(set.join(", "), equals("foo, bar")); |
| 333 }); | 336 }); |
| 334 | 337 |
| 335 test(".last", () { | 338 test(".last", () { |
| 336 expect(set.last, equals("bar")); | 339 expect(set.last, equals("bar")); |
| 337 }); | 340 }); |
| 338 | 341 |
| 339 test(".lastWhere", () { | 342 test(".lastWhere", () { |
| 340 expect(set.lastWhere((element) => element is String), equals("bar")); | 343 expect(set.lastWhere((element) => element is String), equals("bar")); |
| 341 expect(set.lastWhere((element) => element.startsWith("f")), | 344 expect( |
| 342 equals("foo")); | 345 set.lastWhere((element) => element.startsWith("f")), equals("foo")); |
| 343 expect(() => set.lastWhere((element) => element is int), | 346 expect( |
| 344 throwsStateError); | 347 () => set.lastWhere((element) => element is int), throwsStateError); |
| 345 expect(set.lastWhere((element) => element is int, orElse: () => "baz"), | 348 expect(set.lastWhere((element) => element is int, orElse: () => "baz"), |
| 346 equals("baz")); | 349 equals("baz")); |
| 347 }); | 350 }); |
| 348 | 351 |
| 349 test(".map", () { | 352 test(".map", () { |
| 350 expect(set.map((element) => element.substring(1)), | 353 expect( |
| 351 equals(["oo", "ar"])); | 354 set.map((element) => element.substring(1)), equals(["oo", "ar"])); |
| 352 }); | 355 }); |
| 353 | 356 |
| 354 test(".reduce", () { | 357 test(".reduce", () { |
| 355 expect(set.reduce((previous, element) => previous + element), | 358 expect(set.reduce((previous, element) => previous + element), |
| 356 equals("foobar")); | 359 equals("foobar")); |
| 357 }); | 360 }); |
| 358 | 361 |
| 359 test(".singleWhere", () { | 362 test(".singleWhere", () { |
| 360 expect(() => set.singleWhere((element) => element == "baz"), | 363 expect(() => set.singleWhere((element) => element == "baz"), |
| 361 throwsStateError); | 364 throwsStateError); |
| 362 expect(set.singleWhere((element) => element == "foo"), | 365 expect(set.singleWhere((element) => element == "foo"), "foo"); |
| 363 "foo"); | |
| 364 expect(() => set.singleWhere((element) => element is String), | 366 expect(() => set.singleWhere((element) => element is String), |
| 365 throwsStateError); | 367 throwsStateError); |
| 366 }); | 368 }); |
| 367 | 369 |
| 368 test(".skip", () { | 370 test(".skip", () { |
| 369 expect(set.skip(0), equals(["foo", "bar"])); | 371 expect(set.skip(0), equals(["foo", "bar"])); |
| 370 expect(set.skip(1), equals(["bar"])); | 372 expect(set.skip(1), equals(["bar"])); |
| 371 expect(set.skip(2), equals([])); | 373 expect(set.skip(2), equals([])); |
| 372 }); | 374 }); |
| 373 | 375 |
| 374 test(".skipWhile", () { | 376 test(".skipWhile", () { |
| 375 expect(set.skipWhile((element) => element.startsWith("f")), | 377 expect(set.skipWhile((element) => element.startsWith("f")), |
| 376 equals(["bar"])); | 378 equals(["bar"])); |
| 377 expect(set.skipWhile((element) => element.startsWith("z")), | 379 expect(set.skipWhile((element) => element.startsWith("z")), |
| 378 equals(["foo", "bar"])); | 380 equals(["foo", "bar"])); |
| 379 expect(set.skipWhile((element) => element is String), | 381 expect(set.skipWhile((element) => element is String), equals([])); |
| 380 equals([])); | |
| 381 }); | 382 }); |
| 382 | 383 |
| 383 test(".take", () { | 384 test(".take", () { |
| 384 expect(set.take(0), equals([])); | 385 expect(set.take(0), equals([])); |
| 385 expect(set.take(1), equals(["foo"])); | 386 expect(set.take(1), equals(["foo"])); |
| 386 expect(set.take(2), equals(["foo", "bar"])); | 387 expect(set.take(2), equals(["foo", "bar"])); |
| 387 }); | 388 }); |
| 388 | 389 |
| 389 test(".takeWhile", () { | 390 test(".takeWhile", () { |
| 390 expect(set.takeWhile((element) => element.startsWith("f")), | 391 expect(set.takeWhile((element) => element.startsWith("f")), |
| 391 equals(["foo"])); | 392 equals(["foo"])); |
| 392 expect(set.takeWhile((element) => element.startsWith("z")), | 393 expect(set.takeWhile((element) => element.startsWith("z")), equals([])); |
| 393 equals([])); | |
| 394 expect(set.takeWhile((element) => element is String), | 394 expect(set.takeWhile((element) => element is String), |
| 395 equals(["foo", "bar"])); | 395 equals(["foo", "bar"])); |
| 396 }); | 396 }); |
| 397 | 397 |
| 398 test(".toList", () { | 398 test(".toList", () { |
| 399 expect(set.toList(), equals(["foo", "bar"])); | 399 expect(set.toList(), equals(["foo", "bar"])); |
| 400 expect(() => set.toList(growable: false).add("baz"), | 400 expect(() => set.toList(growable: false).add("baz"), |
| 401 throwsUnsupportedError); | 401 throwsUnsupportedError); |
| 402 expect(set.toList()..add("baz"), equals(["foo", "bar", "baz"])); | 402 expect(set.toList()..add("baz"), equals(["foo", "bar", "baz"])); |
| 403 }); | 403 }); |
| 404 | 404 |
| 405 test(".toSet", () { | 405 test(".toSet", () { |
| 406 expect(set.toSet(), equals(new Set.from(["foo", "bar"]))); | 406 expect(set.toSet(), equals(new Set.from(["foo", "bar"]))); |
| 407 }); | 407 }); |
| 408 | 408 |
| 409 test(".where", () { | 409 test(".where", () { |
| 410 expect(set.where((element) => element.startsWith("f")), | 410 expect( |
| 411 equals(["foo"])); | 411 set.where((element) => element.startsWith("f")), equals(["foo"])); |
| 412 expect(set.where((element) => element.startsWith("z")), equals([])); | 412 expect(set.where((element) => element.startsWith("z")), equals([])); |
| 413 expect(set.where((element) => element is String), | 413 expect( |
| 414 equals(["foo", "bar"])); | 414 set.where((element) => element is String), equals(["foo", "bar"])); |
| 415 }); | 415 }); |
| 416 | 416 |
| 417 test(".containsAll", () { | 417 test(".containsAll", () { |
| 418 expect(set.containsAll(["foo", "bar"]), isTrue); | 418 expect(set.containsAll(["foo", "bar"]), isTrue); |
| 419 expect(set.containsAll(["foo"]), isTrue); | 419 expect(set.containsAll(["foo"]), isTrue); |
| 420 expect(set.containsAll(["foo", "bar", "qux"]), isFalse); | 420 expect(set.containsAll(["foo", "bar", "qux"]), isFalse); |
| 421 }); | 421 }); |
| 422 | 422 |
| 423 test(".difference", () { | 423 test(".difference", () { |
| 424 expect(set.difference(new Set.from(["foo", "baz"])), | 424 expect(set.difference(new Set.from(["foo", "baz"])), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 expect(() => set.clear(), throwsUnsupportedError); | 524 expect(() => set.clear(), throwsUnsupportedError); |
| 525 }); | 525 }); |
| 526 }); | 526 }); |
| 527 | 527 |
| 528 group("MapValueSet", () { | 528 group("MapValueSet", () { |
| 529 var map; | 529 var map; |
| 530 var set; | 530 var set; |
| 531 | 531 |
| 532 setUp(() { | 532 setUp(() { |
| 533 map = new Map<String, String>(); | 533 map = new Map<String, String>(); |
| 534 set = new MapValueSet<String, String>(map, | 534 set = new MapValueSet<String, String>( |
| 535 (string) => string.substring(0, 1)); | 535 map, (string) => string.substring(0, 1)); |
| 536 }); | 536 }); |
| 537 | 537 |
| 538 testTwoElementSet(() { | 538 testTwoElementSet(() { |
| 539 map["f"] = "foo"; | 539 map["f"] = "foo"; |
| 540 map["b"] = "bar"; | 540 map["b"] = "bar"; |
| 541 return set; | 541 return set; |
| 542 }); | 542 }); |
| 543 | 543 |
| 544 test(".single", () { | 544 test(".single", () { |
| 545 expect(() => set.single, throwsStateError); | 545 expect(() => set.single, throwsStateError); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 map["q"] = "qux"; | 636 map["q"] = "qux"; |
| 637 set.retainAll(["fblthp", "qux"]); | 637 set.retainAll(["fblthp", "qux"]); |
| 638 expect(map, equals({"f": "foo", "q": "qux"})); | 638 expect(map, equals({"f": "foo", "q": "qux"})); |
| 639 }); | 639 }); |
| 640 | 640 |
| 641 test(".retainAll respects an unusual notion of equality", () { | 641 test(".retainAll respects an unusual notion of equality", () { |
| 642 map = new HashMap<String, String>( | 642 map = new HashMap<String, String>( |
| 643 equals: (value1, value2) => | 643 equals: (value1, value2) => |
| 644 value1.toLowerCase() == value2.toLowerCase(), | 644 value1.toLowerCase() == value2.toLowerCase(), |
| 645 hashCode: (value) => value.toLowerCase().hashCode); | 645 hashCode: (value) => value.toLowerCase().hashCode); |
| 646 set = new MapValueSet<String, String>(map, | 646 set = new MapValueSet<String, String>( |
| 647 (string) => string.substring(0, 1)); | 647 map, (string) => string.substring(0, 1)); |
| 648 | 648 |
| 649 map["f"] = "foo"; | 649 map["f"] = "foo"; |
| 650 map["B"] = "bar"; | 650 map["B"] = "bar"; |
| 651 map["Q"] = "qux"; | 651 map["Q"] = "qux"; |
| 652 set.retainAll(["fblthp", "qux"]); | 652 set.retainAll(["fblthp", "qux"]); |
| 653 expect(map, equals({"f": "foo", "Q": "qux"})); | 653 expect(map, equals({"f": "foo", "Q": "qux"})); |
| 654 }); | 654 }); |
| 655 | 655 |
| 656 test(".retainWhere", () { | 656 test(".retainWhere", () { |
| 657 map["f"] = "foo"; | 657 map["f"] = "foo"; |
| 658 map["b"] = "bar"; | 658 map["b"] = "bar"; |
| 659 map["q"] = "qoo"; | 659 map["q"] = "qoo"; |
| 660 set.retainWhere((element) => element.endsWith("o")); | 660 set.retainWhere((element) => element.endsWith("o")); |
| 661 expect(map, equals({"f": "foo", "q": "qoo"})); | 661 expect(map, equals({"f": "foo", "q": "qoo"})); |
| 662 }); | 662 }); |
| 663 }); | 663 }); |
| 664 } | 664 } |
| OLD | NEW |