@@ -8,44 +8,45 @@ import 'package:test/test.dart' show test, group;
8
8
import 'test_utils.dart' ;
9
9
10
10
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 ());
27
25
28
26
group ('custom `TypeMatcher`' , () {
29
27
// 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' );
34
32
});
35
33
}
36
34
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 ();
39
37
group ('for `$name `' , () {
40
- if (matchingType != null ) {
38
+ if (matchingInstance != null ) {
41
39
test ('succeeds' , () {
42
- shouldPass (matchingType , typeMatcher);
40
+ shouldPass (matchingInstance , typeMatcher);
43
41
});
44
42
}
45
43
46
44
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
+ );
49
50
});
50
51
});
51
52
}
@@ -60,6 +61,6 @@ class _StringMatcher extends TypeMatcher {
60
61
bool matches (item, Map matchState) => item is String ;
61
62
}
62
63
63
- class TestType {
64
- const TestType ();
64
+ class _TestType {
65
+ const _TestType ();
65
66
}
0 commit comments