Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: test_reflectable/test/meta_reflectors_user.dart

Issue 1391543003: Creates `reflectors`, as a meta-meta feature that enables dynamic selection of a "mirror system". (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Added lots of LibraryMirror support in order to make reflectors work in transformed code Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file.
4
5 // File being transformed by the reflectable transformer.
6 // Part of the entry point 'reflectors_test.dart'.
7 //
8 // Independence: This library depends on the domain classes `M1`..`M3`,
9 // `A`..`D`, `P`, and it dynamically uses the reflectors, but it does not
10 // statically depend on 'meta_reflectors_definer.dart' nor on
11 // 'meta_reflectors_domain_definer.dart'.
12
13 library test_reflectable.test.meta_reflectors_user;
14
15 import "package:reflectable/reflectable.dart";
16 import "package:unittest/unittest.dart";
17 import "meta_reflectors_scoping.dart";
18 import "meta_reflectors_domain.dart";
19
20 testReflector(Reflectable reflector, String desc) {
21 test("Mixin, $desc", () {
22 ClassMirror aMirror = reflector.reflectType(A);
23 ClassMirror bMirror = reflector.reflectType(B);
24 ClassMirror cMirror = reflector.reflectType(C);
25 ClassMirror dMirror = reflector.reflectType(D);
26 ClassMirror m1Mirror = reflector.reflectType(M1);
27 ClassMirror m2Mirror = reflector.reflectType(M2);
28 ClassMirror m3Mirror = reflector.reflectType(M3);
29 expect(aMirror.mixin, aMirror);
30 expect(bMirror.mixin, bMirror);
31 expect(cMirror.mixin, cMirror);
32 expect(m1Mirror.mixin, m1Mirror);
33 expect(m2Mirror.mixin, m2Mirror);
34 expect(m3Mirror.mixin, m3Mirror);
35 expect(bMirror.superclass.mixin, m1Mirror);
36 expect(cMirror.superclass.superclass.mixin, m2Mirror);
37 expect(cMirror.superclass.mixin, m3Mirror);
38 expect(cMirror.superclass.superclass.superclass, bMirror);
39 expect(dMirror.mixin, m1Mirror);
40 expect(dMirror.superclass.mixin, aMirror);
41 expect(bMirror.superclass.declarations["foo"].owner, m1Mirror);
42 expect(bMirror.superclass.declarations["field"].owner, m1Mirror);
43 expect(bMirror.superclass.declarations["staticBar"], null);
44 expect(bMirror.superclass.hasReflectedType, true);
45 expect(bMirror.superclass.reflectedType, const isInstanceOf<Type>());
46 expect(bMirror.superclass.superclass.reflectedType,
47 const isInstanceOf<Type>());
48 });
49 }
50
51 Matcher throwsANoSuchCapabilityException =
52 throwsA(const isInstanceOf<NoSuchCapabilityError>());
53
54 Iterable<String> getNames(Iterable<Reflectable> reflectables) {
55 return reflectables.map((Reflectable reflector) {
56 String fullString = reflector.toString();
57 return fullString.substring(13, fullString.length - 1);
58 });
59 }
60
61 doit() {
sigurdm 2015/10/09 07:52:04 what is 'it'? maybe call it: 'runTests'
eernst 2015/10/09 10:09:05 Done.
62 test("MetaReflector, set of reflectors", () {
63 List<Reflectable> reflectors = Reflectable.reflectors.toList();
64 expect(
65 getNames(reflectors).toSet(),
66 [
67 "Reflector",
68 "Reflector2",
69 "ReflectorUpwardsClosed",
70 "ReflectorUpwardsClosedToA",
71 "ReflectorUpwardsClosedUntilA",
72 "ScopeMetaReflector"
73 ].toSet());
74 expect(getNames(const ScopeMetaReflector().reflectablesOfScope("polymer")),
75 ["Reflector", "ReflectorUpwardsClosed"].toSet());
76 expect(getNames(const ScopeMetaReflector().reflectablesOfScope("observe")),
77 ["Reflector2", "ReflectorUpwardsClosed"].toSet());
78 });
79
80 const ScopeMetaReflector().reflectablesOfScope("polymer").forEach(
81 (Reflectable reflector) => testReflector(reflector, "$reflector"));
82
83 test("MetaReflector, select by name", () {
84 var reflector2 = Reflectable.reflectors
85 .firstWhere((Reflectable reflector) => "$reflector".contains("2"));
86 ClassMirror bMirror = reflector2.reflectType(B);
87 ClassMirror cMirror = reflector2.reflectType(C);
88 ClassMirror dMirror = reflector2.reflectType(D);
89 ClassMirror m1Mirror = reflector2.reflectType(M1);
90 ClassMirror m2Mirror = reflector2.reflectType(M2);
91 ClassMirror m3Mirror = reflector2.reflectType(M3);
92 expect(bMirror.mixin, bMirror);
93 expect(cMirror.mixin, cMirror);
94 expect(dMirror.mixin, m1Mirror);
95 expect(m1Mirror.mixin, m1Mirror);
96 // Test that metadata is preserved.
97 expect(m1Mirror.metadata, contains(const P()));
98 expect(m2Mirror.mixin, m2Mirror);
99 expect(m3Mirror.mixin, m3Mirror);
100 expect(bMirror.superclass.mixin, m1Mirror);
101 // Test that the mixin-application does not inherit the metadata from its
102 // mixin.
103 expect(bMirror.superclass.metadata, isEmpty);
104 expect(
105 () => bMirror.superclass.superclass, throwsANoSuchCapabilityException);
106 expect(cMirror.superclass.superclass.mixin, m2Mirror);
107 expect(cMirror.superclass.mixin, m3Mirror);
108 expect(cMirror.superclass.superclass.superclass, bMirror);
109 expect(() => dMirror.superclass, throwsANoSuchCapabilityException);
110 });
111
112 test("MetaReflector, select by capability", () {
113 var reflector = Reflectable.reflectors.firstWhere((Reflectable reflector) {
114 return (reflector.capabilities.any((ReflectCapability capability) =>
115 capability is SuperclassQuantifyCapability &&
116 capability.upperBound == A &&
117 !capability.excludeUpperBound));
118 });
119 ClassMirror aMirror = reflector.reflectType(A);
120 ClassMirror bMirror = reflector.reflectType(B);
121 ClassMirror cMirror = reflector.reflectType(C);
122 ClassMirror dMirror = reflector.reflectType(D);
123 expect(() => reflector.reflectType(M1), throwsANoSuchCapabilityException);
124 expect(() => reflector.reflectType(M2), throwsANoSuchCapabilityException);
125 expect(() => reflector.reflectType(M3), throwsANoSuchCapabilityException);
126 expect(() => bMirror.superclass.mixin, throwsANoSuchCapabilityException);
127 expect(bMirror.superclass.superclass, aMirror);
128 expect(() => cMirror.superclass.mixin, throwsANoSuchCapabilityException);
129 expect(() => cMirror.superclass.superclass.mixin,
130 throwsANoSuchCapabilityException);
131 expect(cMirror.superclass.superclass.superclass, bMirror);
132 expect(() => dMirror.mixin, throwsANoSuchCapabilityException);
133 expect(dMirror.superclass, aMirror);
134 });
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698