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

Side by Side Diff: tests/lib/mirrors/class_declarations_test.dart

Issue 36023003: Add LibraryMirror.declarations and ClassMirror.declarations to the API and both implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: typevars are not static Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.declarations_test;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10 import 'stringify.dart';
11 import 'declarations_model.dart' as declarations_model;
12
13 Set<DeclarationMirror> inheritedDeclarations(ClassMirror cm) {
14 var decls = new Set<DeclarationMirror>();
15 while (cm != null) {
16 decls.addAll(cm.declarations.values);
17 cm = cm.superclass;
18 }
19 return decls;
20 }
21
22 main() {
23 ClassMirror cm = reflectClass(declarations_model.Class);
24
25 Expect.setEquals(
26 ['Variable(s(_instanceVariable) in s(Class), private)',
27 'Variable(s(_staticVariable) in s(Class), private, static)',
28 'Variable(s(instanceVariable) in s(Class))',
29 'Variable(s(staticVariable) in s(Class), static)'],
30 cm.declarations.values.where((dm) => dm is VariableMirror).map(stringify),
31 'variables');
32
33 Expect.setEquals(
34 ['Method(s(_instanceGetter) in s(Class), private, getter)',
35 'Method(s(_staticGetter) in s(Class), private, static, getter)',
36 'Method(s(instanceGetter) in s(Class), getter)',
37 'Method(s(staticGetter) in s(Class), static, getter)'],
38 cm.declarations.values.where((dm) => dm is MethodMirror && dm.isGetter).map( stringify),
Johnni Winther 2013/10/25 06:10:02 Long line.
39 'getters');
40
41 Expect.setEquals(
42 ['Method(s(_instanceSetter=) in s(Class), private, setter)',
43 'Method(s(_staticSetter=) in s(Class), private, static, setter)',
44 'Method(s(instanceSetter=) in s(Class), setter)',
45 'Method(s(staticSetter=) in s(Class), static, setter)'],
46 cm.declarations.values.where((dm) => dm is MethodMirror && dm.isSetter).map( stringify),
Johnni Winther 2013/10/25 06:10:02 Long line.
47 'setters');
48
49 // dart2js stops testing here.
50 return; /// 01: ok
51
52 Expect.setEquals(
53 ['Method(s(+) in s(Class))',
54 'Method(s(_instanceMethod) in s(Class), private)',
55 'Method(s(_staticMethod) in s(Class), private, static)',
56 'Method(s(abstractMethod) in s(Class), abstract)',
57 'Method(s(instanceMethod) in s(Class))',
58 'Method(s(staticMethod) in s(Class), static)'],
59 cm.declarations.values.where((dm) => dm is MethodMirror && dm.isRegularMetho d).map(stringify),
Johnni Winther 2013/10/25 06:10:02 Long line.
60 'regular methods');
61
62 Expect.setEquals(
63 ['Method(s(Class._generativeConstructor) in s(Class), private, constructor)',
64 'Method(s(Class._normalFactory) in s(Class), private, static, constructor)',
65 'Method(s(Class._redirectingConstructor) in s(Class), private, constructor)' ,
Johnni Winther 2013/10/25 06:10:02 Long line.
66 'Method(s(Class._redirectingFactory) in s(Class), private, static, construct or)',
Johnni Winther 2013/10/25 06:10:02 Long line.
67 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
68 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
69 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
70 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)'],
71 cm.declarations.values.where((dm) => dm is MethodMirror && dm.isConstructor) .map(stringify),
Johnni Winther 2013/10/25 06:10:02 Long line.
72 'constructors and factories');
73
74 Expect.setEquals(
75 ['Method(s(Class._normalFactory) in s(Class), private, static, constructor)',
76 'Method(s(Class._redirectingFactory) in s(Class), private, static, construct or)',
Johnni Winther 2013/10/25 06:10:02 Long line.
77 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
78 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)',
79 'Method(s(_staticGetter) in s(Class), private, static, getter)',
80 'Method(s(_staticMethod) in s(Class), private, static)',
81 'Method(s(_staticSetter=) in s(Class), private, static, setter)',
82 'Variable(s(_staticVariable) in s(Class), private, static)',
83 'Method(s(staticGetter) in s(Class), static, getter)',
84 'Method(s(staticMethod) in s(Class), static)',
85 'Method(s(staticSetter=) in s(Class), static, setter)',
86 'Variable(s(staticVariable) in s(Class), static)'],
87 cm.declarations.values.where((dm) => dm.isStatic).map(stringify),
88 'statics');
89
90 Expect.setEquals(
91 ['Method(s(+) in s(Class))',
92 'TypeVariable(s(C) in s(Class), upperBound = Class(s(Object) in s(dart.core) , top-level))',
Johnni Winther 2013/10/25 06:10:02 Long line.
93 'Method(s(Class._generativeConstructor) in s(Class), private, constructor)',
94 'Method(s(Class._redirectingConstructor) in s(Class), private, constructor)' ,
Johnni Winther 2013/10/25 06:10:02 Long line.
95 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
96 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
97 'Method(s(_instanceGetter) in s(Class), private, getter)',
98 'Method(s(_instanceMethod) in s(Class), private)',
99 'Method(s(_instanceSetter=) in s(Class), private, setter)',
100 'Variable(s(_instanceVariable) in s(Class), private)',
101 'Method(s(abstractMethod) in s(Class), abstract)',
102 'Method(s(instanceGetter) in s(Class), getter)',
103 'Method(s(instanceMethod) in s(Class))',
104 'Method(s(instanceSetter=) in s(Class), setter)',
105 'Variable(s(instanceVariable) in s(Class))'],
106 cm.declarations.values.where((dm) => !dm.isStatic).map(stringify),
107 'non-statics');
108
109 Expect.setEquals(
110 ['Method(s(+) in s(Class))',
111 'TypeVariable(s(C) in s(Class), upperBound = Class(s(Object) in s(dart.core) , top-level))',
Johnni Winther 2013/10/25 06:10:02 Long line.
112 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
113 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
114 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
115 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)',
116 'Method(s(abstractMethod) in s(Class), abstract)',
117 'Method(s(instanceGetter) in s(Class), getter)',
118 'Method(s(instanceMethod) in s(Class))',
119 'Method(s(instanceSetter=) in s(Class), setter)',
120 'Variable(s(instanceVariable) in s(Class))',
121 'Method(s(staticGetter) in s(Class), static, getter)',
122 'Method(s(staticMethod) in s(Class), static)',
123 'Method(s(staticSetter=) in s(Class), static, setter)',
124 'Variable(s(staticVariable) in s(Class), static)'],
125 cm.declarations.values.where((dm) => !dm.isPrivate).map(stringify),
126 'public');
127
128 Expect.setEquals(
129 ['Method(s(*) in s(Mixin))',
130 'Method(s(+) in s(Class))',
131 'Method(s(-) in s(Superclass))',
132 'Method(s(==) in s(Object))',
133 'TypeVariable(s(C) in s(Class), upperBound = Class(s(Object) in s(dart.core) , top-level))',
Johnni Winther 2013/10/25 06:10:02 Long line ... and several below.
134 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
135 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
136 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
137 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)',
138 'Method(s(Object) in s(Object), constructor)',
139 'TypeVariable(s(S) in s(Superclass), upperBound = Class(s(Object) in s(dart. core), top-level))',
140 'Method(s(Superclass.inheritedGenerativeConstructor) in s(Superclass), const ructor)',
141 'Method(s(Superclass.inheritedNormalFactory) in s(Superclass), static, const ructor)',
142 'Method(s(Superclass.inheritedRedirectingConstructor) in s(Superclass), cons tructor)',
143 'Method(s(Superclass.inheritedRedirectingFactory) in s(Superclass), static, constructor)',
144 'Method(s(abstractMethod) in s(Class), abstract)',
145 'Method(s(hashCode) in s(Object), getter)',
146 'Method(s(inheritedInstanceGetter) in s(Superclass), getter)',
147 'Method(s(inheritedInstanceMethod) in s(Superclass))',
148 'Method(s(inheritedInstanceSetter=) in s(Superclass), setter)',
149 'Variable(s(inheritedInstanceVariable) in s(Superclass))',
150 'Method(s(inheritedStaticGetter) in s(Superclass), static, getter)',
151 'Method(s(inheritedStaticMethod) in s(Superclass), static)',
152 'Method(s(inheritedStaticSetter=) in s(Superclass), static, setter)',
153 'Variable(s(inheritedStaticVariable) in s(Superclass), static)',
154 'Method(s(instanceGetter) in s(Class), getter)',
155 'Method(s(instanceMethod) in s(Class))',
156 'Method(s(instanceSetter=) in s(Class), setter)',
157 'Variable(s(instanceVariable) in s(Class))',
158 'Method(s(mixinInstanceGetter) in s(Mixin), getter)',
159 'Method(s(mixinInstanceMethod) in s(Mixin))',
160 'Method(s(mixinInstanceSetter=) in s(Mixin), setter)',
161 'Variable(s(mixinInstanceVariable) in s(Mixin))',
162 'Method(s(noSuchMethod) in s(Object))',
163 'Method(s(runtimeType) in s(Object), getter)',
164 'Method(s(staticGetter) in s(Class), static, getter)',
165 'Method(s(staticMethod) in s(Class), static)',
166 'Method(s(staticSetter=) in s(Class), static, setter)',
167 'Variable(s(staticVariable) in s(Class), static)',
168 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin.inheritedGenerativeConstructor) in s(test.declarations_model.Superclass with test.declarations_model.Mixin), constructor)',
169 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin.inheritedRedirectingConstructor) in s(test.declarations_model.Superclass wit h test.declarations_model.Mixin), constructor)',
170 'Method(s(toString) in s(Object))'],
171 inheritedDeclarations(cm).where((dm) => !dm.isPrivate).map(stringify),
172 'transitive public');
173 // The public members of Object should be the same in all implementations, so
174 // we don't exclude Object here.
175
176 Expect.setEquals(
177 ['Method(s(+) in s(Class))',
178 'TypeVariable(s(C) in s(Class), upperBound = Class(s(Object) in s(dart.core) , top-level))',
179 'Method(s(Class._generativeConstructor) in s(Class), private, constructor)',
180 'Method(s(Class._normalFactory) in s(Class), private, static, constructor)',
181 'Method(s(Class._redirectingConstructor) in s(Class), private, constructor)' ,
182 'Method(s(Class._redirectingFactory) in s(Class), private, static, construct or)',
183 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
184 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
185 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
186 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)',
187 'Method(s(_instanceGetter) in s(Class), private, getter)',
188 'Method(s(_instanceMethod) in s(Class), private)',
189 'Method(s(_instanceSetter=) in s(Class), private, setter)',
190 'Variable(s(_instanceVariable) in s(Class), private)',
191 'Method(s(_staticGetter) in s(Class), private, static, getter)',
192 'Method(s(_staticMethod) in s(Class), private, static)',
193 'Method(s(_staticSetter=) in s(Class), private, static, setter)',
194 'Variable(s(_staticVariable) in s(Class), private, static)',
195 'Method(s(abstractMethod) in s(Class), abstract)',
196 'Method(s(instanceGetter) in s(Class), getter)',
197 'Method(s(instanceMethod) in s(Class))',
198 'Method(s(instanceSetter=) in s(Class), setter)',
199 'Variable(s(instanceVariable) in s(Class))',
200 'Method(s(staticGetter) in s(Class), static, getter)',
201 'Method(s(staticMethod) in s(Class), static)',
202 'Method(s(staticSetter=) in s(Class), static, setter)',
203 'Variable(s(staticVariable) in s(Class), static)'],
204 cm.declarations.values.map(stringify),
205 'declarations');
206
207 Expect.setEquals(
208 ['Method(s(*) in s(Mixin))',
209 'Method(s(+) in s(Class))',
210 'Method(s(-) in s(Superclass))',
211 'TypeVariable(s(C) in s(Class), upperBound = Class(s(Object) in s(dart.core) , top-level))',
212 'Method(s(Class._generativeConstructor) in s(Class), private, constructor)',
213 'Method(s(Class._normalFactory) in s(Class), private, static, constructor)',
214 'Method(s(Class._redirectingConstructor) in s(Class), private, constructor)' ,
215 'Method(s(Class._redirectingFactory) in s(Class), private, static, construct or)',
216 'Method(s(Class.generativeConstructor) in s(Class), constructor)',
217 'Method(s(Class.normalFactory) in s(Class), static, constructor)',
218 'Method(s(Class.redirectingConstructor) in s(Class), constructor)',
219 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)',
220 'TypeVariable(s(S) in s(Superclass), upperBound = Class(s(Object) in s(dart. core), top-level))',
221 'Method(s(Superclass._inheritedGenerativeConstructor) in s(Superclass), priv ate, constructor)',
222 'Method(s(Superclass._inheritedNormalFactory) in s(Superclass), private, sta tic, constructor)',
223 'Method(s(Superclass._inheritedRedirectingConstructor) in s(Superclass), pri vate, constructor)',
224 'Method(s(Superclass._inheritedRedirectingFactory) in s(Superclass), private , static, constructor)',
225 'Method(s(Superclass.inheritedGenerativeConstructor) in s(Superclass), const ructor)',
226 'Method(s(Superclass.inheritedNormalFactory) in s(Superclass), static, const ructor)',
227 'Method(s(Superclass.inheritedRedirectingConstructor) in s(Superclass), cons tructor)',
228 'Method(s(Superclass.inheritedRedirectingFactory) in s(Superclass), static, constructor)',
229 'Method(s(_inheritedInstanceGetter) in s(Superclass), private, getter)',
230 'Method(s(_inheritedInstanceMethod) in s(Superclass), private)',
231 'Method(s(_inheritedInstanceSetter=) in s(Superclass), private, setter)',
232 'Variable(s(_inheritedInstanceVariable) in s(Superclass), private)',
233 'Method(s(_inheritedStaticGetter) in s(Superclass), private, static, getter) ',
234 'Method(s(_inheritedStaticMethod) in s(Superclass), private, static)',
235 'Method(s(_inheritedStaticSetter=) in s(Superclass), private, static, setter )',
236 'Variable(s(_inheritedStaticVariable) in s(Superclass), private, static)',
237 'Method(s(_instanceGetter) in s(Class), private, getter)',
238 'Method(s(_instanceMethod) in s(Class), private)',
239 'Method(s(_instanceSetter=) in s(Class), private, setter)',
240 'Variable(s(_instanceVariable) in s(Class), private)',
241 'Method(s(_mixinInstanceGetter) in s(Mixin), private, getter)',
242 'Method(s(_mixinInstanceMethod) in s(Mixin), private)',
243 'Method(s(_mixinInstanceSetter=) in s(Mixin), private, setter)',
244 'Variable(s(_mixinInstanceVariable) in s(Mixin), private)',
245 'Method(s(_staticGetter) in s(Class), private, static, getter)',
246 'Method(s(_staticMethod) in s(Class), private, static)',
247 'Method(s(_staticSetter=) in s(Class), private, static, setter)',
248 'Variable(s(_staticVariable) in s(Class), private, static)',
249 'Method(s(abstractMethod) in s(Class), abstract)',
250 'Method(s(inheritedInstanceGetter) in s(Superclass), getter)',
251 'Method(s(inheritedInstanceMethod) in s(Superclass))',
252 'Method(s(inheritedInstanceSetter=) in s(Superclass), setter)',
253 'Variable(s(inheritedInstanceVariable) in s(Superclass))',
254 'Method(s(inheritedStaticGetter) in s(Superclass), static, getter)',
255 'Method(s(inheritedStaticMethod) in s(Superclass), static)',
256 'Method(s(inheritedStaticSetter=) in s(Superclass), static, setter)',
257 'Variable(s(inheritedStaticVariable) in s(Superclass), static)',
258 'Method(s(instanceGetter) in s(Class), getter)',
259 'Method(s(instanceMethod) in s(Class))',
260 'Method(s(instanceSetter=) in s(Class), setter)',
261 'Variable(s(instanceVariable) in s(Class))',
262 'Method(s(mixinInstanceGetter) in s(Mixin), getter)',
263 'Method(s(mixinInstanceMethod) in s(Mixin))',
264 'Method(s(mixinInstanceSetter=) in s(Mixin), setter)',
265 'Variable(s(mixinInstanceVariable) in s(Mixin))',
266 'Method(s(staticGetter) in s(Class), static, getter)',
267 'Method(s(staticMethod) in s(Class), static)',
268 'Method(s(staticSetter=) in s(Class), static, setter)',
269 'Variable(s(staticVariable) in s(Class), static)',
270 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin._inheritedGenerativeConstructor) in s(test.declarations_model.Superclass wit h test.declarations_model.Mixin), private, constructor)',
271 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin._inheritedRedirectingConstructor) in s(test.declarations_model.Superclass wi th test.declarations_model.Mixin), private, constructor)',
272 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin.inheritedGenerativeConstructor) in s(test.declarations_model.Superclass with test.declarations_model.Mixin), constructor)',
273 'Method(s(test.declarations_model.Superclass with test.declarations_model.Mi xin.inheritedRedirectingConstructor) in s(test.declarations_model.Superclass wit h test.declarations_model.Mixin), constructor)'],
274 inheritedDeclarations(cm).difference(reflectClass(Object).declarations.value s.toSet()).map(stringify),
275 'transitive less Object');
276 // The private members of Object may vary across implementation, so we exclude the
277 // declarations of Object in this test case.
278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698