@@ -2250,7 +2250,7 @@ void main() {
2250
2250
bool m() => false;
2251
2251
}
2252
2252
''' ),
2253
- _containsAllOf ('returnValue: false, ' ),
2253
+ _containsAllOf ('returnValue: false' ),
2254
2254
);
2255
2255
});
2256
2256
@@ -2261,7 +2261,7 @@ void main() {
2261
2261
double m() => 3.14;
2262
2262
}
2263
2263
''' ),
2264
- _containsAllOf ('returnValue: 0.0, ' ),
2264
+ _containsAllOf ('returnValue: 0.0' ),
2265
2265
);
2266
2266
});
2267
2267
@@ -2272,7 +2272,7 @@ void main() {
2272
2272
int m() => 7;
2273
2273
}
2274
2274
''' ),
2275
- _containsAllOf ('returnValue: 0, ' ),
2275
+ _containsAllOf ('returnValue: 0' ),
2276
2276
);
2277
2277
});
2278
2278
@@ -2295,7 +2295,7 @@ void main() {
2295
2295
List<Foo> m() => [Foo()];
2296
2296
}
2297
2297
''' ),
2298
- _containsAllOf ('returnValue: <_i2.Foo>[], ' ),
2298
+ _containsAllOf ('returnValue: <_i2.Foo>[]' ),
2299
2299
);
2300
2300
});
2301
2301
@@ -2306,7 +2306,7 @@ void main() {
2306
2306
Set<Foo> m() => {Foo()};
2307
2307
}
2308
2308
''' ),
2309
- _containsAllOf ('returnValue: <_i2.Foo>{}, ' ),
2309
+ _containsAllOf ('returnValue: <_i2.Foo>{}' ),
2310
2310
);
2311
2311
});
2312
2312
@@ -2317,7 +2317,7 @@ void main() {
2317
2317
Map<int, Foo> m() => {7: Foo()};
2318
2318
}
2319
2319
''' ),
2320
- _containsAllOf ('returnValue: <int, _i2.Foo>{}, ' ),
2320
+ _containsAllOf ('returnValue: <int, _i2.Foo>{}' ),
2321
2321
);
2322
2322
});
2323
2323
@@ -2328,7 +2328,7 @@ void main() {
2328
2328
Map m();
2329
2329
}
2330
2330
''' ),
2331
- _containsAllOf ('returnValue: <dynamic, dynamic>{}, ' ),
2331
+ _containsAllOf ('returnValue: <dynamic, dynamic>{}' ),
2332
2332
);
2333
2333
});
2334
2334
@@ -2339,7 +2339,7 @@ void main() {
2339
2339
Future<bool> m() async => false;
2340
2340
}
2341
2341
''' ),
2342
- _containsAllOf ('returnValue: _i3.Future<bool>.value(false), ' ),
2342
+ _containsAllOf ('returnValue: _i3.Future<bool>.value(false)' ),
2343
2343
);
2344
2344
});
2345
2345
@@ -2362,7 +2362,7 @@ void main() {
2362
2362
Stream<int> m();
2363
2363
}
2364
2364
''' ),
2365
- _containsAllOf ('returnValue: _i3.Stream<int>.empty(), ' ),
2365
+ _containsAllOf ('returnValue: _i3.Stream<int>.empty()' ),
2366
2366
);
2367
2367
});
2368
2368
@@ -2384,7 +2384,7 @@ void main() {
2384
2384
#m,
2385
2385
[],
2386
2386
),
2387
- ), ''' ),
2387
+ )''' ),
2388
2388
);
2389
2389
});
2390
2390
@@ -2403,7 +2403,7 @@ void main() {
2403
2403
#m,
2404
2404
[],
2405
2405
),
2406
- ), ''' ),
2406
+ )''' ),
2407
2407
);
2408
2408
});
2409
2409
@@ -2418,7 +2418,7 @@ void main() {
2418
2418
two,
2419
2419
}
2420
2420
''' ),
2421
- _containsAllOf ('returnValue: _i2.Bar.one, ' ),
2421
+ _containsAllOf ('returnValue: _i2.Bar.one' ),
2422
2422
);
2423
2423
});
2424
2424
@@ -2435,7 +2435,7 @@ void main() {
2435
2435
returnValue: (
2436
2436
int __p0, [
2437
2437
String? __p1,
2438
- ]) {}, ''' ),
2438
+ ]) {}''' ),
2439
2439
);
2440
2440
});
2441
2441
@@ -2452,7 +2452,7 @@ void main() {
2452
2452
returnValue: (
2453
2453
_i2.Foo __p0, {
2454
2454
bool? b,
2455
- }) {}, ''' ),
2455
+ }) {}''' ),
2456
2456
);
2457
2457
});
2458
2458
@@ -2469,7 +2469,7 @@ void main() {
2469
2469
returnValue: (
2470
2470
_i2.Foo __p0, {
2471
2471
required bool b,
2472
- }) {}, ''' ),
2472
+ }) {}''' ),
2473
2473
);
2474
2474
});
2475
2475
@@ -2489,7 +2489,7 @@ void main() {
2489
2489
#m,
2490
2490
[],
2491
2491
),
2492
- ), ''' ),
2492
+ )''' ),
2493
2493
);
2494
2494
});
2495
2495
@@ -2510,7 +2510,7 @@ void main() {
2510
2510
#m,
2511
2511
[],
2512
2512
),
2513
- ),
2513
+ )
2514
2514
''' ),
2515
2515
);
2516
2516
});
@@ -2523,7 +2523,7 @@ void main() {
2523
2523
T? Function<T>(T) m() => (int i, [String s]) {};
2524
2524
}
2525
2525
''' ),
2526
- _containsAllOf ('returnValue: <T>(T __p0) => null, ' ),
2526
+ _containsAllOf ('returnValue: <T>(T __p0) => null' ),
2527
2527
);
2528
2528
});
2529
2529
@@ -3753,8 +3753,49 @@ void main() {
3753
3753
});
3754
3754
}
3755
3755
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
+ }
3758
3799
3759
3800
/// Expect that [testBuilder] , given [assets] , in a package which has opted into
3760
3801
/// null safety, throws an [InvalidMockitoAnnotationException] with a message
0 commit comments