@@ -9,8 +9,12 @@ import 'package:matcher/matcher.dart';
9
9
/// Returns a matcher that matches if the value is structurally equal to
10
10
/// [expected] .
11
11
///
12
+ /// When [onlyCheckComparable] fields that are not comparable are ignored for
13
+ /// the equality check.
14
+ ///
12
15
/// Improves on a simple equality test by offering a detailed mismatch message.
13
- Matcher equalsBuilt (Built expected) => _BuiltValueMatcher (expected);
16
+ Matcher equalsBuilt (Built expected, {bool onlyCheckComparable = false }) =>
17
+ _BuiltValueMatcher (expected, onlyCheckComparable);
14
18
15
19
/// Matcher for [Built] instances.
16
20
///
@@ -19,8 +23,10 @@ Matcher equalsBuilt(Built expected) => _BuiltValueMatcher(expected);
19
23
class _BuiltValueMatcher implements Matcher {
20
24
final Built _expected;
21
25
final Matcher _delegate;
26
+ final bool _onlyCheckComparable;
22
27
23
- _BuiltValueMatcher (this ._expected) : _delegate = equals (_toMap (_expected));
28
+ _BuiltValueMatcher (this ._expected, this ._onlyCheckComparable)
29
+ : _delegate = equals (_toMap (_expected));
24
30
25
31
@override
26
32
Description describe (Description description) =>
@@ -41,6 +47,8 @@ class _BuiltValueMatcher implements Matcher {
41
47
bool matches (dynamic item, Map matchState) {
42
48
if (_expected.runtimeType != item.runtimeType) return false ;
43
49
50
+ if (_onlyCheckComparable && _expected == item) return true ;
51
+
44
52
return _delegate.matches (_toMap (item), matchState);
45
53
}
46
54
}
0 commit comments