-
Notifications
You must be signed in to change notification settings - Fork 56
/
global_quantify_test.dart
67 lines (55 loc) · 1.84 KB
/
global_quantify_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in
// the LICENSE file.
library test_reflectable.test.global_quantify_test;
@GlobalQuantifyCapability(
r'^test_reflectable.test.global_quantify_test.(A|B)$', reflector)
@GlobalQuantifyMetaCapability(Mark, reflector)
import 'package:reflectable/reflectable.dart';
import 'package:test/test.dart';
import 'global_quantify_test.reflectable.dart';
class Reflector extends Reflectable {
const Reflector()
: super(typeCapability, const InstanceInvokeCapability('foo'));
}
const reflector = Reflector();
class Mark {
const Mark();
}
class A {
int foo() => 42;
}
class B {
int foo() => 43;
}
class C {
int foo() => 44;
}
@Mark()
class D {
int foo() => 45;
}
Matcher throwsNoSuchCapabilityError =
throwsA(const TypeMatcher<NoSuchCapabilityError>());
void main() {
initializeReflectable();
test('GlobalQuantifyCapability', () {
expect(reflector.canReflectType(A), true);
expect(reflector.canReflect(A()), true);
expect(reflector.reflectType(A), const TypeMatcher<ClassMirror>());
expect(reflector.reflect(A()).invoke('foo', []), 42);
expect(reflector.canReflectType(B), true);
expect(reflector.canReflect(B()), true);
expect(reflector.reflectType(B), const TypeMatcher<ClassMirror>());
expect(reflector.reflect(B()).invoke('foo', []), 43);
expect(reflector.canReflectType(C), false);
expect(reflector.canReflect(C()), false);
expect(() => reflector.reflectType(C), throwsNoSuchCapabilityError);
expect(() => reflector.reflect(C()), throwsNoSuchCapabilityError);
});
test('GlobalQuantifyMetaCapability', () {
expect(reflector.canReflectType(D), true);
expect(reflector.canReflect(D()), true);
expect(reflector.reflect(D()).invoke('foo', []), 45);
});
}