Skip to content

Commit b6da667

Browse files
authored
Cleanup test/type_matcher_test (flutter#128)
1 parent 5ae5fa1 commit b6da667

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

test/type_matcher_test.dart

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,45 @@ import 'package:test/test.dart' show test, group;
88
import 'test_utils.dart';
99

1010
void main() {
11-
_test('Map', isMap, {});
12-
_test('List', isList, []);
13-
_test('ArgumentError', isArgumentError, ArgumentError());
14-
_test('CastError', isCastError, CastError());
15-
_test('Exception', isException, const FormatException());
16-
_test('FormatException', isFormatException, const FormatException());
17-
_test('StateError', isStateError, StateError('oops'));
18-
_test('RangeError', isRangeError, RangeError('oops'));
19-
_test('UnimplementedError', isUnimplementedError, UnimplementedError('oops'));
20-
_test('UnsupportedError', isUnsupportedError, UnsupportedError('oops'));
21-
_test('ConcurrentModificationError', isConcurrentModificationError,
22-
ConcurrentModificationError());
23-
_test('CyclicInitializationError', isCyclicInitializationError,
24-
CyclicInitializationError());
25-
_test('NoSuchMethodError', isNoSuchMethodError, null);
26-
_test('NullThrownError', isNullThrownError, NullThrownError());
11+
_test(isMap, {}, name: 'Map');
12+
_test(isList, [], name: 'List');
13+
_test(isArgumentError, ArgumentError());
14+
_test(isCastError, CastError());
15+
_test<Exception>(isException, const FormatException());
16+
_test(isFormatException, const FormatException());
17+
_test(isStateError, StateError('oops'));
18+
_test(isRangeError, RangeError('oops'));
19+
_test(isUnimplementedError, UnimplementedError('oops'));
20+
_test(isUnsupportedError, UnsupportedError('oops'));
21+
_test(isConcurrentModificationError, ConcurrentModificationError());
22+
_test(isCyclicInitializationError, CyclicInitializationError());
23+
_test<NoSuchMethodError>(isNoSuchMethodError, null);
24+
_test(isNullThrownError, NullThrownError());
2725

2826
group('custom `TypeMatcher`', () {
2927
// ignore: deprecated_member_use_from_same_package
30-
_test('String', const isInstanceOf<String>(), 'hello');
31-
_test('String', const _StringMatcher(), 'hello');
32-
_test('String', const TypeMatcher<String>(), 'hello');
33-
_test('String', isA<String>(), 'hello');
28+
_test(const isInstanceOf<String>(), 'hello');
29+
_test(const _StringMatcher(), 'hello');
30+
_test(const TypeMatcher<String>(), 'hello');
31+
_test(isA<String>(), 'hello');
3432
});
3533
}
3634

37-
// TODO: drop `name` and use a type argument – once Dart2 semantics are enabled
38-
void _test(String name, Matcher typeMatcher, Object matchingType) {
35+
void _test<T>(Matcher typeMatcher, T matchingInstance, {String name}) {
36+
name ??= T.toString();
3937
group('for `$name`', () {
40-
if (matchingType != null) {
38+
if (matchingInstance != null) {
4139
test('succeeds', () {
42-
shouldPass(matchingType, typeMatcher);
40+
shouldPass(matchingInstance, typeMatcher);
4341
});
4442
}
4543

4644
test('fails', () {
47-
shouldFail(const TestType(), typeMatcher,
48-
"Expected: <Instance of '$name'> Actual: <Instance of 'TestType'>");
45+
shouldFail(
46+
const _TestType(),
47+
typeMatcher,
48+
"Expected: <Instance of '$name'> Actual: <Instance of '_TestType'>",
49+
);
4950
});
5051
});
5152
}
@@ -60,6 +61,6 @@ class _StringMatcher extends TypeMatcher {
6061
bool matches(item, Map matchState) => item is String;
6162
}
6263

63-
class TestType {
64-
const TestType();
64+
class _TestType {
65+
const _TestType();
6566
}

0 commit comments

Comments
 (0)