@@ -2250,7 +2250,7 @@ void main() {
22502250 bool m() => false;
22512251 }
22522252 ''' ),
2253- _containsAllOf ('returnValue: false, ' ),
2253+ _containsAllOf ('returnValue: false' ),
22542254 );
22552255 });
22562256
@@ -2261,7 +2261,7 @@ void main() {
22612261 double m() => 3.14;
22622262 }
22632263 ''' ),
2264- _containsAllOf ('returnValue: 0.0, ' ),
2264+ _containsAllOf ('returnValue: 0.0' ),
22652265 );
22662266 });
22672267
@@ -2272,7 +2272,7 @@ void main() {
22722272 int m() => 7;
22732273 }
22742274 ''' ),
2275- _containsAllOf ('returnValue: 0, ' ),
2275+ _containsAllOf ('returnValue: 0' ),
22762276 );
22772277 });
22782278
@@ -2295,7 +2295,7 @@ void main() {
22952295 List<Foo> m() => [Foo()];
22962296 }
22972297 ''' ),
2298- _containsAllOf ('returnValue: <_i2.Foo>[], ' ),
2298+ _containsAllOf ('returnValue: <_i2.Foo>[]' ),
22992299 );
23002300 });
23012301
@@ -2306,7 +2306,7 @@ void main() {
23062306 Set<Foo> m() => {Foo()};
23072307 }
23082308 ''' ),
2309- _containsAllOf ('returnValue: <_i2.Foo>{}, ' ),
2309+ _containsAllOf ('returnValue: <_i2.Foo>{}' ),
23102310 );
23112311 });
23122312
@@ -2317,7 +2317,7 @@ void main() {
23172317 Map<int, Foo> m() => {7: Foo()};
23182318 }
23192319 ''' ),
2320- _containsAllOf ('returnValue: <int, _i2.Foo>{}, ' ),
2320+ _containsAllOf ('returnValue: <int, _i2.Foo>{}' ),
23212321 );
23222322 });
23232323
@@ -2328,7 +2328,7 @@ void main() {
23282328 Map m();
23292329 }
23302330 ''' ),
2331- _containsAllOf ('returnValue: <dynamic, dynamic>{}, ' ),
2331+ _containsAllOf ('returnValue: <dynamic, dynamic>{}' ),
23322332 );
23332333 });
23342334
@@ -2339,7 +2339,7 @@ void main() {
23392339 Future<bool> m() async => false;
23402340 }
23412341 ''' ),
2342- _containsAllOf ('returnValue: _i3.Future<bool>.value(false), ' ),
2342+ _containsAllOf ('returnValue: _i3.Future<bool>.value(false)' ),
23432343 );
23442344 });
23452345
@@ -2362,7 +2362,7 @@ void main() {
23622362 Stream<int> m();
23632363 }
23642364 ''' ),
2365- _containsAllOf ('returnValue: _i3.Stream<int>.empty(), ' ),
2365+ _containsAllOf ('returnValue: _i3.Stream<int>.empty()' ),
23662366 );
23672367 });
23682368
@@ -2384,7 +2384,7 @@ void main() {
23842384 #m,
23852385 [],
23862386 ),
2387- ), ''' ),
2387+ )''' ),
23882388 );
23892389 });
23902390
@@ -2403,7 +2403,7 @@ void main() {
24032403 #m,
24042404 [],
24052405 ),
2406- ), ''' ),
2406+ )''' ),
24072407 );
24082408 });
24092409
@@ -2418,7 +2418,7 @@ void main() {
24182418 two,
24192419 }
24202420 ''' ),
2421- _containsAllOf ('returnValue: _i2.Bar.one, ' ),
2421+ _containsAllOf ('returnValue: _i2.Bar.one' ),
24222422 );
24232423 });
24242424
@@ -2435,7 +2435,7 @@ void main() {
24352435 returnValue: (
24362436 int __p0, [
24372437 String? __p1,
2438- ]) {}, ''' ),
2438+ ]) {}''' ),
24392439 );
24402440 });
24412441
@@ -2452,7 +2452,7 @@ void main() {
24522452 returnValue: (
24532453 _i2.Foo __p0, {
24542454 bool? b,
2455- }) {}, ''' ),
2455+ }) {}''' ),
24562456 );
24572457 });
24582458
@@ -2469,7 +2469,7 @@ void main() {
24692469 returnValue: (
24702470 _i2.Foo __p0, {
24712471 required bool b,
2472- }) {}, ''' ),
2472+ }) {}''' ),
24732473 );
24742474 });
24752475
@@ -2489,7 +2489,7 @@ void main() {
24892489 #m,
24902490 [],
24912491 ),
2492- ), ''' ),
2492+ )''' ),
24932493 );
24942494 });
24952495
@@ -2510,7 +2510,7 @@ void main() {
25102510 #m,
25112511 [],
25122512 ),
2513- ),
2513+ )
25142514 ''' ),
25152515 );
25162516 });
@@ -2523,7 +2523,7 @@ void main() {
25232523 T? Function<T>(T) m() => (int i, [String s]) {};
25242524 }
25252525 ''' ),
2526- _containsAllOf ('returnValue: <T>(T __p0) => null, ' ),
2526+ _containsAllOf ('returnValue: <T>(T __p0) => null' ),
25272527 );
25282528 });
25292529
@@ -3753,8 +3753,49 @@ void main() {
37533753 });
37543754}
37553755
3756- TypeMatcher <List <int >> _containsAllOf (a, [b]) => decodedMatches (
3757- b == null ? allOf (contains (a)) : allOf (contains (a), contains (b)));
3756+ TypeMatcher <List <int >> _containsAllOf (String a, [String ? b]) =>
3757+ decodedMatches (b == null
3758+ ? _ContainsIgnoringFormattingMatcher (a)
3759+ : allOf (_ContainsIgnoringFormattingMatcher (a),
3760+ _ContainsIgnoringFormattingMatcher (b)));
3761+
3762+ /// Matches a string that contains a given string, ignoring differences related
3763+ /// to formatting: whitespace and trailing commas.
3764+ class _ContainsIgnoringFormattingMatcher extends Matcher {
3765+ /// Matches one or more whitespace characters.
3766+ static final _whitespacePattern = RegExp (r'\s+' );
3767+
3768+ /// Matches a trailing comma preceding a closing bracket character.
3769+ static final _trailingCommaPattern = RegExp (r',\s*([)}\]])' );
3770+
3771+ /// The string that the actual value must contain in order for the match to
3772+ /// succeed.
3773+ final String _expected;
3774+
3775+ _ContainsIgnoringFormattingMatcher (this ._expected);
3776+
3777+ @override
3778+ Description describe (Description description) {
3779+ return description
3780+ .add ('Contains "$_expected " when ignoring source formatting' );
3781+ }
3782+
3783+ @override
3784+ bool matches (item, Map matchState) =>
3785+ _stripFormatting (item.toString ()).contains (_stripFormatting (_expected));
3786+
3787+ /// Removes whitespace and trailing commas.
3788+ ///
3789+ /// Note that the result is not valid code because it means adjacent
3790+ ///.identifiers and operators may be joined in ways that break the semantics.
3791+ /// The goal is not to produce an but valid version of the code, just to
3792+ /// produce a string that will reliably match the actual string when it has
3793+ /// also been stripped the same way.
3794+ String _stripFormatting (String code) => code
3795+ .replaceAll (_whitespacePattern, '' )
3796+ .replaceAllMapped (_trailingCommaPattern, (match) => match[1 ]! )
3797+ .trim ();
3798+ }
37583799
37593800/// Expect that [testBuilder] , given [assets] , in a package which has opted into
37603801/// null safety, throws an [InvalidMockitoAnnotationException] with a message
0 commit comments