Skip to content

Commit 3dd73c0

Browse files
committed
fix: solving conflicts
2 parents fb67a9c + 95b7bd0 commit 3dd73c0

File tree

2 files changed

+123
-148
lines changed

2 files changed

+123
-148
lines changed

lib/src/matchers.dart

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ import 'package:test/test.dart';
1818
///
1919
/// ```
2020
Matcher isRoute<T extends Object?>({
21-
@Deprecated('Use `whereName` instead') String? named,
2221
Matcher? whereSettings,
2322
Matcher? whereName,
2423
Matcher? whereArguments,
2524
Matcher? whereMaintainState,
2625
Matcher? whereFullscreenDialog,
2726
}) {
28-
// Remove once `named` argument is removed.
29-
if (whereName == null && named != null) {
30-
// Deprecation will be removed with https://github.com/VeryGoodOpenSource/mockingjay/pull/86
31-
// ignore: parameter_assignments
32-
whereName = equals(named);
33-
}
34-
3527
assert(
3628
whereSettings == null || (whereName == null && whereArguments == null),
3729
'Cannot specify both `whereSettings` and `whereName` or `whereArguments`',
@@ -49,11 +41,7 @@ Matcher isRoute<T extends Object?>({
4941
/// Returns a matcher that matches the [RouteSettings] from the given [route].
5042
Matcher equalsSettingsOf(Route<dynamic> route) {
5143
return isA<RouteSettings>()
52-
.having(
53-
(s) => s.name,
54-
'name',
55-
equals(route.settings.name),
56-
)
44+
.having((s) => s.name, 'name', equals(route.settings.name))
5745
.having(
5846
(s) => s.arguments,
5947
'arguments',
@@ -189,19 +177,25 @@ class _RouteMatcher<T> extends Matcher {
189177
if (item is Route) {
190178
final typeMatches = !hasTypeArgument || item is Route<T>;
191179

192-
final settingsMatches = !hasSettingsMatcher ||
180+
final settingsMatches =
181+
!hasSettingsMatcher ||
193182
whereSettings!.matches(item.settings, matchState);
194183
final nameMatches =
195184
!hasNameMatcher || whereName!.matches(item.settings.name, matchState);
196-
final argumentsMatches = !hasArgumentsMatcher ||
185+
final argumentsMatches =
186+
!hasArgumentsMatcher ||
197187
whereArguments!.matches(item.settings.arguments, matchState);
198-
final maintainStateMatches = !hasMaintainStateMatcher ||
188+
final maintainStateMatches =
189+
!hasMaintainStateMatcher ||
199190
(item is ModalRoute &&
200191
whereMaintainState!.matches(item.maintainState, matchState));
201-
final fullscreenDialogMatches = !hasFullscreenDialogMatcher ||
192+
final fullscreenDialogMatches =
193+
!hasFullscreenDialogMatcher ||
202194
(item is PageRoute &&
203-
whereFullscreenDialog!
204-
.matches(item.fullscreenDialog, matchState));
195+
whereFullscreenDialog!.matches(
196+
item.fullscreenDialog,
197+
matchState,
198+
));
205199

206200
return typeMatches &&
207201
settingsMatches &&
@@ -230,16 +224,20 @@ class _RouteMatcher<T> extends Matcher {
230224

231225
final typeMatches = !hasTypeArgument || item is Route<T>;
232226

233-
final settingsMatches = !hasSettingsMatcher ||
227+
final settingsMatches =
228+
!hasSettingsMatcher ||
234229
whereSettings!.matches(item.settings, matchState);
235230
final nameMatches =
236231
!hasNameMatcher || whereName!.matches(item.settings.name, matchState);
237-
final argumentsMatches = !hasArgumentsMatcher ||
232+
final argumentsMatches =
233+
!hasArgumentsMatcher ||
238234
whereArguments!.matches(item.settings.arguments, matchState);
239-
final maintainStateMatches = !hasMaintainStateMatcher ||
235+
final maintainStateMatches =
236+
!hasMaintainStateMatcher ||
240237
(item is ModalRoute &&
241238
whereMaintainState!.matches(item.maintainState, matchState));
242-
final fullscreenDialogMatches = !hasFullscreenDialogMatcher ||
239+
final fullscreenDialogMatches =
240+
!hasFullscreenDialogMatcher ||
243241
(item is PageRoute &&
244242
whereFullscreenDialog!.matches(item.fullscreenDialog, matchState));
245243

@@ -286,25 +284,27 @@ class _RouteMatcher<T> extends Matcher {
286284
mismatchDescriptions.add("the route's `arguments` $mismatch");
287285
}
288286
if (!maintainStateMatches) {
289-
final mismatch = item is! ModalRoute
290-
? 'is not a property on `${item.runtimeType}` and can only be used '
291-
'with `ModalRoute`s'
292-
: whereMaintainState!.describeMismatchAsString(
293-
item.maintainState,
294-
matchState,
295-
verbose: verbose,
296-
);
287+
final mismatch =
288+
item is! ModalRoute
289+
? 'is not a property on `${item.runtimeType}` and can only be used '
290+
'with `ModalRoute`s'
291+
: whereMaintainState!.describeMismatchAsString(
292+
item.maintainState,
293+
matchState,
294+
verbose: verbose,
295+
);
297296
mismatchDescriptions.add('`maintainState` $mismatch');
298297
}
299298
if (!fullscreenDialogMatches) {
300-
final mismatch = item is! PageRoute
301-
? 'is not a property on `${item.runtimeType}` and can only be used '
302-
'with `PageRoute`s'
303-
: whereFullscreenDialog!.describeMismatchAsString(
304-
item.fullscreenDialog,
305-
matchState,
306-
verbose: verbose,
307-
);
299+
final mismatch =
300+
item is! PageRoute
301+
? 'is not a property on `${item.runtimeType}` and can only be used '
302+
'with `PageRoute`s'
303+
: whereFullscreenDialog!.describeMismatchAsString(
304+
item.fullscreenDialog,
305+
matchState,
306+
verbose: verbose,
307+
);
308308
mismatchDescriptions.add('`fullscreenDialog` $mismatch');
309309
}
310310

test/src/matchers_test.dart

Lines changed: 84 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_test/flutter_test.dart';
3-
import 'package:matcher/src/feature_matcher.dart';
43
import 'package:mockingjay/mockingjay.dart';
54

65
class NonModalRoute extends Mock implements TransitionRoute<void> {}
@@ -38,46 +37,25 @@ void main() {
3837
bool fullscreenDialog = false,
3938
}) {
4039
return MaterialPageRoute<T>(
41-
settings: RouteSettings(
42-
name: name,
43-
arguments: arguments,
44-
),
40+
settings: RouteSettings(name: name, arguments: arguments),
4541
maintainState: maintainState,
4642
fullscreenDialog: fullscreenDialog,
4743
builder: (_) => const SizedBox(),
4844
);
4945
}
5046

5147
group('constructor', () {
52-
test('wraps deprecated name value in equals matcher', () {
48+
test('throws AssertionError when both whereSettings '
49+
'and whereName or whereArguments matchers are provided', () {
5350
expect(
54-
// Deprecation will be removed with https://github.com/VeryGoodOpenSource/mockingjay/pull/86
55-
// ignore: deprecated_member_use_from_same_package
56-
isRoute(named: '/test'),
57-
isA<dynamic>().having(
58-
// Deprecation will be removed with https://github.com/VeryGoodOpenSource/mockingjay/pull/86
59-
// ignore: avoid_dynamic_calls
60-
(dynamic m) => m.whereName,
61-
'whereName',
62-
isA<FeatureMatcher<String>>(),
51+
() => isRoute(
52+
whereSettings: isNotNull,
53+
whereName: isNotNull,
54+
whereArguments: isNotNull,
6355
),
56+
throwsAssertionError,
6457
);
6558
});
66-
67-
test(
68-
'throws AssertionError when both whereSettings '
69-
'and whereName or whereArguments matchers are provided',
70-
() {
71-
expect(
72-
() => isRoute(
73-
whereSettings: isNotNull,
74-
whereName: isNotNull,
75-
whereArguments: isNotNull,
76-
),
77-
throwsAssertionError,
78-
);
79-
},
80-
);
8159
});
8260

8361
group('without arguments', () {
@@ -146,43 +124,43 @@ void main() {
146124
expect(
147125
createRoute<dynamic>(name: '/test'),
148126
isRoute(
149-
whereSettings:
150-
isA<RouteSettings>().having((s) => s.name, 'name', '/test'),
127+
whereSettings: isA<RouteSettings>().having(
128+
(s) => s.name,
129+
'name',
130+
'/test',
131+
),
151132
),
152133
);
153134
});
154135

155-
test(
156-
'does not match anything that is not a route '
157-
'with matching settings',
158-
() {
159-
expectToFail(
160-
createRoute<dynamic>(name: '/test'),
161-
isRoute(whereSettings: equalsSettingsOf(createRoute<String>())),
162-
withMessage:
163-
"is a route where `settings` has `name` with value '/test'",
164-
);
165-
expectToFail(
166-
createRoute<dynamic>(name: '/other_name'),
167-
isRoute(
168-
whereSettings: equalsSettingsOf(
169-
createRoute<dynamic>(name: '/test'),
170-
),
136+
test('does not match anything that is not a route '
137+
'with matching settings', () {
138+
expectToFail(
139+
createRoute<dynamic>(name: '/test'),
140+
isRoute(whereSettings: equalsSettingsOf(createRoute<String>())),
141+
withMessage:
142+
"is a route where `settings` has `name` with value '/test'",
143+
);
144+
expectToFail(
145+
createRoute<dynamic>(name: '/other_name'),
146+
isRoute(
147+
whereSettings: equalsSettingsOf(
148+
createRoute<dynamic>(name: '/test'),
171149
),
172-
withMessage: '''
150+
),
151+
withMessage: '''
173152
is a route where `settings` has `name` with value '/other_name' which is different.
174153
Expected: /test
175154
Actual: /other_name ...
176155
^
177156
Differ at offset 1''',
178-
);
179-
expectToFail(
180-
1,
181-
isRoute(whereSettings: equalsSettingsOf(createRoute<dynamic>())),
182-
withMessage: 'is not a route but an instance of `int`',
183-
);
184-
},
185-
);
157+
);
158+
expectToFail(
159+
1,
160+
isRoute(whereSettings: equalsSettingsOf(createRoute<dynamic>())),
161+
withMessage: 'is not a route but an instance of `int`',
162+
);
163+
});
186164
});
187165

188166
group('with whereName argument', () {
@@ -240,13 +218,15 @@ is a route where the route's `name` is different.
240218
expectToFail(
241219
createRoute<dynamic>(arguments: {'a': 1}),
242220
isRoute(whereArguments: equals({'a': 2})),
243-
withMessage: "is a route where the route's `arguments` "
221+
withMessage:
222+
"is a route where the route's `arguments` "
244223
"at location ['a'] is <1> instead of <2>",
245224
);
246225
expectToFail(
247226
createRoute<dynamic>(arguments: {'a': 1}),
248227
isRoute(whereArguments: equals({'b': 1})),
249-
withMessage: "is a route where the route's `arguments` "
228+
withMessage:
229+
"is a route where the route's `arguments` "
250230
"is missing map key 'b'",
251231
);
252232
expectToFail(
@@ -260,36 +240,32 @@ is a route where the route's `name` is different.
260240

261241
group('with whereMaintainState argument', () {
262242
test('matches any route with matching maintainState argument', () {
263-
expect(
243+
expect(createRoute<dynamic>(), isRoute(whereMaintainState: isTrue));
244+
});
245+
246+
test('does not match anything that is not a route with matching '
247+
'maintainState argument', () {
248+
expectToFail(
264249
createRoute<dynamic>(),
250+
isRoute(whereMaintainState: isFalse),
251+
withMessage:
252+
'is a route where `maintainState` '
253+
'is true instead of false',
254+
);
255+
expectToFail(
256+
NonModalRoute(),
257+
isRoute(whereMaintainState: isTrue),
258+
withMessage:
259+
'is a route where `maintainState` '
260+
'is not a property on `NonModalRoute` and can only be used '
261+
'with `ModalRoute`s',
262+
);
263+
expectToFail(
264+
1,
265265
isRoute(whereMaintainState: isTrue),
266+
withMessage: 'is not a route but an instance of `int`',
266267
);
267268
});
268-
269-
test(
270-
'does not match anything that is not a route with matching '
271-
'maintainState argument',
272-
() {
273-
expectToFail(
274-
createRoute<dynamic>(),
275-
isRoute(whereMaintainState: isFalse),
276-
withMessage: 'is a route where `maintainState` '
277-
'is true instead of false',
278-
);
279-
expectToFail(
280-
NonModalRoute(),
281-
isRoute(whereMaintainState: isTrue),
282-
withMessage: 'is a route where `maintainState` '
283-
'is not a property on `NonModalRoute` and can only be used '
284-
'with `ModalRoute`s',
285-
);
286-
expectToFail(
287-
1,
288-
isRoute(whereMaintainState: isTrue),
289-
withMessage: 'is not a route but an instance of `int`',
290-
);
291-
},
292-
);
293269
});
294270

295271
group('with whereFullscreenDialog argument', () {
@@ -300,30 +276,29 @@ is a route where the route's `name` is different.
300276
);
301277
});
302278

303-
test(
304-
'does not match anything that is not a route with matching '
305-
'fullscreenDialog argument',
306-
() {
307-
expectToFail(
308-
createRoute<dynamic>(fullscreenDialog: true),
309-
isRoute(whereFullscreenDialog: isFalse),
310-
withMessage: 'is a route where `fullscreenDialog` '
311-
'is true instead of false',
312-
);
313-
expectToFail(
314-
NonModalRoute(),
315-
isRoute(whereFullscreenDialog: isFalse),
316-
withMessage: 'is a route where `fullscreenDialog` '
317-
'is not a property on `NonModalRoute` and can only be used '
318-
'with `PageRoute`s',
319-
);
320-
expectToFail(
321-
1,
322-
isRoute(whereFullscreenDialog: isTrue),
323-
withMessage: 'is not a route but an instance of `int`',
324-
);
325-
},
326-
);
279+
test('does not match anything that is not a route with matching '
280+
'fullscreenDialog argument', () {
281+
expectToFail(
282+
createRoute<dynamic>(fullscreenDialog: true),
283+
isRoute(whereFullscreenDialog: isFalse),
284+
withMessage:
285+
'is a route where `fullscreenDialog` '
286+
'is true instead of false',
287+
);
288+
expectToFail(
289+
NonModalRoute(),
290+
isRoute(whereFullscreenDialog: isFalse),
291+
withMessage:
292+
'is a route where `fullscreenDialog` '
293+
'is not a property on `NonModalRoute` and can only be used '
294+
'with `PageRoute`s',
295+
);
296+
expectToFail(
297+
1,
298+
isRoute(whereFullscreenDialog: isTrue),
299+
withMessage: 'is not a route but an instance of `int`',
300+
);
301+
});
327302
});
328303

329304
test('returns all relevant mismatches in one log', () {

0 commit comments

Comments
 (0)