| 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 })); |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 653 |
| 656 test(".retainWhere", () { | 654 test(".retainWhere", () { |
| 657 map["f"] = "foo"; | 655 map["f"] = "foo"; |
| 658 map["b"] = "bar"; | 656 map["b"] = "bar"; |
| 659 map["q"] = "qoo"; | 657 map["q"] = "qoo"; |
| 660 set.retainWhere((element) => element.endsWith("o")); | 658 set.retainWhere((element) => element.endsWith("o")); |
| 661 expect(map, equals({"f": "foo", "q": "qoo"})); | 659 expect(map, equals({"f": "foo", "q": "qoo"})); |
| 662 }); | 660 }); |
| 663 }); | 661 }); |
| 664 } | 662 } |
| OLD | NEW |