| Index: packages/quiver/lib/testing/src/equality/equality.dart
|
| diff --git a/packages/quiver/lib/testing/src/equality/equality.dart b/packages/quiver/lib/testing/src/equality/equality.dart
|
| index 2053e57db190c6d4bb02cc6e0f2aac93f9937e91..e67222ab1c524b0f21c19c2287ef3b6ec4a580e9 100644
|
| --- a/packages/quiver/lib/testing/src/equality/equality.dart
|
| +++ b/packages/quiver/lib/testing/src/equality/equality.dart
|
| @@ -14,43 +14,40 @@
|
|
|
| part of quiver.testing.equality;
|
|
|
| -/**
|
| - * Matcher for == and hashCode methods of a class.
|
| - *
|
| - * To use, invoke areEqualityGroups with a list of equality groups where each
|
| - * group contains objects that are supposed to be equal to each other, and
|
| - * objects of different groups are expected to be unequal. For example:
|
| - *
|
| - * expect({
|
| - * 'hello': ["hello", "h" + "ello"],
|
| - * 'world': ["world", "wor" + "ld"],
|
| - * 'three': [2, 1 + 1]
|
| - * }, areEqualityGroups);
|
| - *
|
| - * This tests that:
|
| - *
|
| - * * comparing each object against itself returns true
|
| - * * comparing each object against an instance of an incompatible class
|
| - * returns false
|
| - * * comparing each pair of objects within the same equality group returns
|
| - * true
|
| - * * comparing each pair of objects from different equality groups returns
|
| - * false
|
| - * * the hash codes of any two equal objects are equal
|
| - * * equals implementation is idempotent
|
| - *
|
| - * The format of the Map passed to expect is such that the map keys are used in
|
| - * error messages to identify the group described by the map value.
|
| - *
|
| - * When a test fails, the error message labels the objects involved in
|
| - * the failed comparison as follows:
|
| - *
|
| - * "`[group x, item j]`" refers to the ith item in the xth equality group,
|
| - * where both equality groups and the items within equality groups are
|
| - * numbered starting from 1. When either a constructor argument or an
|
| - * equal object is provided, that becomes group 1.
|
| - *
|
| - */
|
| +/// Matcher for == and hashCode methods of a class.
|
| +///
|
| +/// To use, invoke areEqualityGroups with a list of equality groups where each
|
| +/// group contains objects that are supposed to be equal to each other, and
|
| +/// objects of different groups are expected to be unequal. For example:
|
| +///
|
| +/// expect({
|
| +/// 'hello': ["hello", "h" + "ello"],
|
| +/// 'world': ["world", "wor" + "ld"],
|
| +/// 'three': [2, 1 + 1]
|
| +/// }, areEqualityGroups);
|
| +///
|
| +/// This tests that:
|
| +///
|
| +/// * comparing each object against itself returns true
|
| +/// * comparing each object against an instance of an incompatible class
|
| +/// returns false
|
| +/// * comparing each pair of objects within the same equality group returns
|
| +/// true
|
| +/// * comparing each pair of objects from different equality groups returns
|
| +/// false
|
| +/// * the hash codes of any two equal objects are equal
|
| +/// * equals implementation is idempotent
|
| +///
|
| +/// The format of the Map passed to expect is such that the map keys are used in
|
| +/// error messages to identify the group described by the map value.
|
| +///
|
| +/// When a test fails, the error message labels the objects involved in
|
| +/// the failed comparison as follows:
|
| +///
|
| +/// "`[group x, item j]`" refers to the ith item in the xth equality group,
|
| +/// where both equality groups and the items within equality groups are
|
| +/// numbered starting from 1. When either a constructor argument or an
|
| +/// equal object is provided, that becomes group 1.
|
| const Matcher areEqualityGroups = const _EqualityGroupMatcher();
|
|
|
| const _repetitions = 3;
|
| @@ -64,9 +61,9 @@ class _EqualityGroupMatcher extends Matcher {
|
| description.add('to be equality groups');
|
|
|
| @override
|
| - bool matches(Map<String, List> item, Map matchState) {
|
| + bool matches(item, Map matchState) {
|
| try {
|
| - _verifyEqualityGroups(item, matchState);
|
| + _verifyEqualityGroups(item as Map<String, List>, matchState);
|
| return true;
|
| } on MatchError catch (e) {
|
| matchState[failureReason] = e.toString();
|
| @@ -82,7 +79,7 @@ class _EqualityGroupMatcher extends Matcher {
|
| if (equalityGroups == null) {
|
| throw new MatchError('Equality Group must not be null');
|
| }
|
| - var equalityGroupsCopy = {};
|
| + final equalityGroupsCopy = <String, List>{};
|
| equalityGroups.forEach((String groupName, List group) {
|
| if (groupName == null) {
|
| throw new MatchError('Group name must not be null');
|
| @@ -94,7 +91,7 @@ class _EqualityGroupMatcher extends Matcher {
|
| });
|
|
|
| // Run the test multiple times to ensure deterministic equals
|
| - for (var run in range(_repetitions)) {
|
| + for (var i = 0; i < _repetitions; i++) {
|
| _checkBasicIdentity(equalityGroupsCopy, matchState);
|
| _checkGroupBasedEquality(equalityGroupsCopy);
|
| }
|
|
|