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

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

Issue 23604003: Support named and optional positional arguments in reflective invocation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix wrong variable in async unwrap error message Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.invoke_named_test;
6
7 import 'dart:mirrors';
8
9 import 'package:expect/expect.dart';
10 import 'invoke_test.dart';
11
12 class C {
13 a(a, {b:'B', c}) => "$a-$b-$c";
14 b({a:'A', b, c}) => "$a-$b-$c";
15 c(a, [b, c='C']) => "$a-$b-$c";
16 d([a, b='B', c='C']) => "$a-$b-$c";
17 e(a, b, c) => "$a-$b-$c";
18 }
19
20 class D {
21 static a(a, {b:'B', c}) => "$a-$b-$c";
22 static b({a:'A', b, c}) => "$a-$b-$c";
23 static c(a, [b, c='C']) => "$a-$b-$c";
24 static d([a, b='B', c='C']) => "$a-$b-$c";
25 static e(a, b, c) => "$a-$b-$c";
26 }
27
28 class E {
29 var field;
30 E(a, {b:'B', c}) : this.field = "$a-$b-$c";
31 E.b({a:'A', b, c}) : this.field = "$a-$b-$c";
32 E.c(a, [b, c='C']) : this.field = "$a-$b-$c";
33 E.d([a, b='B', c='C']) : this.field = "$a-$b-$c";
34 E.e(a, b, c) : this.field = "$a-$b-$c";
35 }
36
37 a(a, {b:'B', c}) => "$a-$b-$c";
38 b({a:'A', b, c}) => "$a-$b-$c";
39 c(a, [b, c='C']) => "$a-$b-$c";
40 d([a, b='B', c='C']) => "$a-$b-$c";
41 e(a, b, c) => "$a-$b-$c";
42
43 testSyncInvoke(ObjectMirror om) {
44 InstanceMirror result;
45
46 result = om.invoke(const Symbol('a'), ['X']);
47 Expect.equals('X-B-null', result.reflectee);
48 result = om.invoke(const Symbol('a'), ['X'], {const Symbol('b') : 'Y'});
49 Expect.equals('X-Y-null', result.reflectee);
50 result = om.invoke(const Symbol('a'), ['X'], {const Symbol('c') : 'Z', const S ymbol('b') : 'Y'});
51 Expect.equals('X-Y-Z', result.reflectee);
52 Expect.throws(() => om.invoke(const Symbol('a'), []),
53 isNoSuchMethodError,
54 'Insufficient positional arguments');
55 Expect.throws(() => om.invoke(const Symbol('a'), ['X', 'Y']),
56 isNoSuchMethodError,
57 'Extra positional arguments');
58 Expect.throws(() => om.invoke(const Symbol('a'), ['X'], {const Symbol('undef') : 'Y'}),
59 isNoSuchMethodError,
60 'Unmatched named argument');
61
62 result = om.invoke(const Symbol('b'), []);
63 Expect.equals('A-null-null', result.reflectee);
64 result = om.invoke(const Symbol('b'), [], {const Symbol('a') : 'X'});
65 Expect.equals('X-null-null', result.reflectee);
66 result = om.invoke(const Symbol('b'), [], {const Symbol('b') :'Y', const Symbo l('c') :'Z', const Symbol('a') :'X'});
67 Expect.equals('X-Y-Z', result.reflectee);
68 Expect.throws(() => om.invoke(const Symbol('b'), ['X']),
69 isNoSuchMethodError,
70 'Extra positional arguments');
71 Expect.throws(() => om.invoke(const Symbol('b'), ['X'], {const Symbol('undef') : 'Y'}),
72 isNoSuchMethodError,
73 'Unmatched named argument');
74
75 result = om.invoke(const Symbol('c'), ['X']);
76 Expect.equals('X-null-C', result.reflectee);
77 result = om.invoke(const Symbol('c'), ['X', 'Y']);
78 Expect.equals('X-Y-C', result.reflectee);
79 result = om.invoke(const Symbol('c'), ['X', 'Y', 'Z']);
80 Expect.equals('X-Y-Z', result.reflectee);
81 Expect.throws(() => om.invoke(const Symbol('c'), []),
82 isNoSuchMethodError,
83 'Insufficient positional arguments');
84 Expect.throws(() => om.invoke(const Symbol('c'), ['X', 'Y', 'Z', 'W']),
85 isNoSuchMethodError,
86 'Extra positional arguments');
87 Expect.throws(() => om.invoke(const Symbol('c'), ['X'], {const Symbol('undef') : 'Y'}),
88 isNoSuchMethodError,
89 'Unmatched named argument');
90
91 result = om.invoke(const Symbol('d'), []);
92 Expect.equals('null-B-C', result.reflectee);
93 result = om.invoke(const Symbol('d'), ['X']);
94 Expect.equals('X-B-C', result.reflectee);
95 result = om.invoke(const Symbol('d'), ['X', 'Y']);
96 Expect.equals('X-Y-C', result.reflectee);
97 result = om.invoke(const Symbol('d'), ['X', 'Y', 'Z']);
98 Expect.equals('X-Y-Z', result.reflectee);
99 Expect.throws(() => om.invoke(const Symbol('d'), ['X', 'Y', 'Z', 'W']),
100 isNoSuchMethodError,
101 'Extra positional arguments');
102 Expect.throws(() => om.invoke(const Symbol('d'), ['X'], {const Symbol('undef') : 'Y'}),
103 isNoSuchMethodError,
104 'Unmatched named argument');
105
106 result = om.invoke(const Symbol('e'), ['X', 'Y', 'Z']);
107 Expect.equals('X-Y-Z', result.reflectee);
108 Expect.throws(() => om.invoke(const Symbol('e'), ['X']),
109 isNoSuchMethodError,
110 'Insufficient positional arguments');
111 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
112 isNoSuchMethodError,
113 'Extra positional arguments');
114 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef') : 'Y'}),
115 isNoSuchMethodError,
116 'Unmatched named argument');
117 }
118
119 testAsyncInvoke(ObjectMirror om) {
120 Future<InstanceMirror> future;
121
122 future = om.invokeAsync(const Symbol('a'), ['X']);
123 expectValueThen(future, (result) {
124 Expect.equals('X-B-null', result.reflectee);
125 });
126 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('b') : 'Y'});
127 expectValueThen(future, (result) {
128 Expect.equals('X-Y-null', result.reflectee);
129 });
130 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('c') : 'Z', co nst Symbol('b') : 'Y'});
131 expectValueThen(future, (result) {
132 Expect.equals('X-Y-Z', result.reflectee);
133 });
134 future = om.invokeAsync(const Symbol('a'), []);
135 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
136 future = om.invokeAsync(const Symbol('a'), ['X', 'Y']);
137 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
138 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('undef') : 'Y' });
139 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
140
141
142 future = om.invokeAsync(const Symbol('b'), []);
143 expectValueThen(future, (result) {
144 Expect.equals('A-null-null', result.reflectee);
145 });
146 future = om.invokeAsync(const Symbol('b'), [], {const Symbol('a') : 'X'});
147 expectValueThen(future, (result) {
148 Expect.equals('X-null-null', result.reflectee);
149 });
150 future = om.invokeAsync(const Symbol('b'), [], {const Symbol('b') :'Y', const Symbol('c') :'Z', const Symbol('a') :'X'});
151 expectValueThen(future, (result) {
152 Expect.equals('X-Y-Z', result.reflectee);
153 });
154 future = om.invokeAsync(const Symbol('b'), ['X']);
155 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
156 future = om.invokeAsync(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'} );
157 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
158
159
160 future = om.invokeAsync(const Symbol('c'), ['X']);
161 expectValueThen(future, (result) {
162 Expect.equals('X-null-C', result.reflectee);
163 });
164 future = om.invokeAsync(const Symbol('c'), ['X', 'Y']);
165 expectValueThen(future, (result) {
166 Expect.equals('X-Y-C', result.reflectee);
167 });
168 future = om.invokeAsync(const Symbol('c'), ['X', 'Y', 'Z']);
169 expectValueThen(future, (result) {
170 Expect.equals('X-Y-Z', result.reflectee);
171 });
172 future = om.invokeAsync(const Symbol('c'), []);
173 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
174 future = om.invokeAsync(const Symbol('c'), ['X', 'Y', 'Z', 'W']);
175 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
176 future = om.invokeAsync(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'} );
177 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
178
179
180 future = om.invokeAsync(const Symbol('d'), []);
181 expectValueThen(future, (result) {
182 Expect.equals('null-B-C', result.reflectee);
183 });
184 future = om.invokeAsync(const Symbol('d'), ['X']);
185 expectValueThen(future, (result) {
186 Expect.equals('X-B-C', result.reflectee);
187 });
188 future = om.invokeAsync(const Symbol('d'), ['X', 'Y']);
189 expectValueThen(future, (result) {
190 Expect.equals('X-Y-C', result.reflectee);
191 });
192 future = om.invokeAsync(const Symbol('d'), ['X', 'Y', 'Z']);
193 expectValueThen(future, (result) {
194 Expect.equals('X-Y-Z', result.reflectee);
195 });
196 future = om.invokeAsync(const Symbol('d'), ['X', 'Y', 'Z', 'W']);
197 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
198 future = om.invokeAsync(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'} );
199 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
200
201
202 future = om.invokeAsync(const Symbol('e'), ['X', 'Y', 'Z']);
203 expectValueThen(future, (result) {
204 Expect.equals('X-Y-Z', result.reflectee);
205 });
206 future = om.invokeAsync(const Symbol('e'), ['X']);
207 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
208 future = om.invokeAsync(const Symbol('e'), ['X', 'Y', 'Z', 'W']);
209 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
210 future = om.invokeAsync(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'} );
211 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
212 }
213
214 testSyncNewInstance() {
215 ClassMirror cm = reflectClass(E);
216 InstanceMirror result;
217
218 result = cm.newInstance(const Symbol(''), ['X']);
219 Expect.equals('X-B-null', result.reflectee.field);
220 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'});
221 Expect.equals('X-Y-null', result.reflectee.field);
222 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con st Symbol('b') : 'Y'});
223 Expect.equals('X-Y-Z', result.reflectee.field);
224 Expect.throws(() => cm.newInstance(const Symbol(''), []),
225 isNoSuchMethodError,
226 'Insufficient positional arguments');
227 Expect.throws(() => cm.newInstance(const Symbol(''), ['X', 'Y']),
228 isNoSuchMethodError,
229 'Extra positional arguments');
230 Expect.throws(() => cm.newInstance(const Symbol(''), ['X'], {const Symbol('und ef') : 'Y'}),
231 isNoSuchMethodError,
232 'Unmatched named argument');
233
234 result = cm.newInstance(const Symbol('b'), []);
235 Expect.equals('A-null-null', result.reflectee.field);
236 result = cm.newInstance(const Symbol('b'), [], {const Symbol('a') : 'X'});
237 Expect.equals('X-null-null', result.reflectee.field);
238 result = cm.newInstance(const Symbol('b'), [], {const Symbol('b') :'Y', const Symbol('c') :'Z', const Symbol('a') :'X'});
239 Expect.equals('X-Y-Z', result.reflectee.field);
240 Expect.throws(() => cm.newInstance(const Symbol('b'), ['X']),
241 isNoSuchMethodError,
242 'Extra positional arguments');
243 Expect.throws(() => cm.newInstance(const Symbol('b'), ['X'], {const Symbol('un def'): 'Y'}),
244 isNoSuchMethodError,
245 'Unmatched named argument');
246
247 result = cm.newInstance(const Symbol('c'), ['X']);
248 Expect.equals('X-null-C', result.reflectee.field);
249 result = cm.newInstance(const Symbol('c'), ['X', 'Y']);
250 Expect.equals('X-Y-C', result.reflectee.field);
251 result = cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z']);
252 Expect.equals('X-Y-Z', result.reflectee.field);
253 Expect.throws(() => cm.newInstance(const Symbol('c'), []),
254 isNoSuchMethodError,
255 'Insufficient positional arguments');
256 Expect.throws(() => cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z', 'W']),
257 isNoSuchMethodError,
258 'Extra positional arguments');
259 Expect.throws(() => cm.newInstance(const Symbol('c'), ['X'], {const Symbol('un def'): 'Y'}),
260 isNoSuchMethodError,
261 'Unmatched named argument');
262
263 result = cm.newInstance(const Symbol('d'), []);
264 Expect.equals('null-B-C', result.reflectee.field);
265 result = cm.newInstance(const Symbol('d'), ['X']);
266 Expect.equals('X-B-C', result.reflectee.field);
267 result = cm.newInstance(const Symbol('d'), ['X', 'Y']);
268 Expect.equals('X-Y-C', result.reflectee.field);
269 result = cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z']);
270 Expect.equals('X-Y-Z', result.reflectee.field);
271 Expect.throws(() => cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z', 'W']),
272 isNoSuchMethodError,
273 'Extra positional arguments');
274 Expect.throws(() => cm.newInstance(const Symbol('d'), ['X'], {const Symbol('un def'): 'Y'}),
275 isNoSuchMethodError,
276 'Unmatched named argument');
277
278 result = cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z']);
279 Expect.equals('X-Y-Z', result.reflectee.field);
280 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X']),
281 isNoSuchMethodError,
282 'Insufficient positional arguments');
283 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
284 isNoSuchMethodError,
285 'Extra positional arguments');
286 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un def'): 'Y'}),
287 isNoSuchMethodError,
288 'Unmatched named argument');
289 }
290
291 testAsyncNewInstance() {
292 ClassMirror cm = reflectClass(E);
293 Future<InstanceMirror> future;
294
295 future = cm.newInstanceAsync(const Symbol(''), ['X']);
296 expectValueThen(future, (result) {
297 Expect.equals('X-B-null', result.reflectee.field);
298 });
299 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('b') : 'Y' });
300 expectValueThen(future, (result) {
301 Expect.equals('X-Y-null', result.reflectee.field);
302 });
303 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('c') : 'Z' , const Symbol('b') : 'Y'});
304 expectValueThen(future, (result) {
305 Expect.equals('X-Y-Z', result.reflectee.field);
306 });
307 future = cm.newInstanceAsync(const Symbol(''), []);
308 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
309 future = cm.newInstanceAsync(const Symbol(''), ['X', 'Y']);
310 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
311 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('undef') : 'Y'});
312 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
313
314
315 future = cm.newInstanceAsync(const Symbol('b'), []);
316 expectValueThen(future, (result) {
317 Expect.equals('A-null-null', result.reflectee.field);
318 });
319 future = cm.newInstanceAsync(const Symbol('b'), [], {const Symbol('a') : 'X'}) ;
320 expectValueThen(future, (result) {
321 Expect.equals('X-null-null', result.reflectee.field);
322 });
323 future = cm.newInstanceAsync(const Symbol('b'), [], {const Symbol('b') :'Y', c onst Symbol('c') :'Z', const Symbol('a') :'X'});
324 expectValueThen(future, (result) {
325 Expect.equals('X-Y-Z', result.reflectee.field);
326 });
327 future = cm.newInstanceAsync(const Symbol('b'), ['X']);
328 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
329 future = cm.newInstanceAsync(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'});
330 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
331
332
333 future = cm.newInstanceAsync(const Symbol('c'), ['X']);
334 expectValueThen(future, (result) {
335 Expect.equals('X-null-C', result.reflectee.field);
336 });
337 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y']);
338 expectValueThen(future, (result) {
339 Expect.equals('X-Y-C', result.reflectee.field);
340 });
341 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y', 'Z']);
342 expectValueThen(future, (result) {
343 Expect.equals('X-Y-Z', result.reflectee.field);
344 });
345 future = cm.newInstanceAsync(const Symbol('c'), []);
346 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
347 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y', 'Z', 'W']);
348 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
349 future = cm.newInstanceAsync(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'});
350 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
351
352
353 future = cm.newInstanceAsync(const Symbol('d'), []);
354 expectValueThen(future, (result) {
355 Expect.equals('null-B-C', result.reflectee.field);
356 });
357 future = cm.newInstanceAsync(const Symbol('d'), ['X']);
358 expectValueThen(future, (result) {
359 Expect.equals('X-B-C', result.reflectee.field);
360 });
361 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y']);
362 expectValueThen(future, (result) {
363 Expect.equals('X-Y-C', result.reflectee.field);
364 });
365 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y', 'Z']);
366 expectValueThen(future, (result) {
367 Expect.equals('X-Y-Z', result.reflectee.field);
368 });
369 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y', 'Z', 'W']);
370 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
371 future = cm.newInstanceAsync(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'});
372 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
373
374
375 future = cm.newInstanceAsync(const Symbol('e'), ['X', 'Y', 'Z']);
376 expectValueThen(future, (result) {
377 Expect.equals('X-Y-Z', result.reflectee.field);
378 });
379 future = cm.newInstanceAsync(const Symbol('e'), ['X']);
380 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
381 future = cm.newInstanceAsync(const Symbol('e'), ['X', 'Y', 'Z', 'W']);
382 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
383 future = cm.newInstanceAsync(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'});
384 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
385 }
386
387 testSyncApply() {
388 ClosureMirror cm;
389 InstanceMirror result;
390
391 cm = reflect(a);
392 result = cm.apply(['X']);
393 Expect.equals('X-B-null', result.reflectee);
394 result = cm.apply(['X'], {const Symbol('b') : 'Y'});
395 Expect.equals('X-Y-null', result.reflectee);
396 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'});
397 Expect.equals('X-Y-Z', result.reflectee);
398 Expect.throws(() => cm.apply([]),
399 isNoSuchMethodError,
400 'Insufficient positional arguments');
401 Expect.throws(() => cm.apply(['X', 'Y']),
402 isNoSuchMethodError,
403 'Extra positional arguments');
404 Expect.throws(() => cm.apply(['X'], {const Symbol('undef') : 'Y'}),
405 isNoSuchMethodError,
406 'Unmatched named argument');
407
408 cm = reflect(b);
409 result = cm.apply([]);
410 Expect.equals('A-null-null', result.reflectee);
411 result = cm.apply([], {const Symbol('a') : 'X'});
412 Expect.equals('X-null-null', result.reflectee);
413 result = cm.apply([], {const Symbol('b') :'Y', const Symbol('c') :'Z', const S ymbol('a') :'X'});
414 Expect.equals('X-Y-Z', result.reflectee);
415 Expect.throws(() => cm.apply(['X']),
416 isNoSuchMethodError,
417 'Extra positional arguments');
418 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
419 isNoSuchMethodError,
420 'Unmatched named argument');
421
422 cm = reflect(c);
423 result = cm.apply(['X']);
424 Expect.equals('X-null-C', result.reflectee);
425 result = cm.apply(['X', 'Y']);
426 Expect.equals('X-Y-C', result.reflectee);
427 result = cm.apply(['X', 'Y', 'Z']);
428 Expect.equals('X-Y-Z', result.reflectee);
429 Expect.throws(() => cm.apply([]),
430 isNoSuchMethodError,
431 'Insufficient positional arguments');
432 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']),
433 isNoSuchMethodError,
434 'Extra positional arguments');
435 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
436 isNoSuchMethodError,
437 'Unmatched named argument');
438
439 cm = reflect(d);
440 result = cm.apply([]);
441 Expect.equals('null-B-C', result.reflectee);
442 result = cm.apply(['X']);
443 Expect.equals('X-B-C', result.reflectee);
444 result = cm.apply(['X', 'Y']);
445 Expect.equals('X-Y-C', result.reflectee);
446 result = cm.apply(['X', 'Y', 'Z']);
447 Expect.equals('X-Y-Z', result.reflectee);
448 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']),
449 isNoSuchMethodError,
450 'Extra positional arguments');
451 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
452 isNoSuchMethodError,
453 'Unmatched named argument');
454
455 cm = reflect(e);
456 result = cm.apply(['X', 'Y', 'Z']);
457 Expect.equals('X-Y-Z', result.reflectee);
458 Expect.throws(() => cm.apply(['X']),
459 isNoSuchMethodError,
460 'Insufficient positional arguments');
461 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']),
462 isNoSuchMethodError,
463 'Extra positional arguments');
464 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
465 isNoSuchMethodError,
466 'Unmatched named argument');
467 }
468
469 testAsyncApply() {
470 ClosureMirror cm;
471 Future<InstanceMirror> future;
472
473 cm = reflect(a);
474 future = cm.applyAsync(['X']);
475 expectValueThen(future, (result) {
476 Expect.equals('X-B-null', result.reflectee);
477 });
478 future = cm.applyAsync(['X'], {const Symbol('b') : 'Y'});
479 expectValueThen(future, (result) {
480 Expect.equals('X-Y-null', result.reflectee);
481 });
482 future = cm.applyAsync(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y '});
483 expectValueThen(future, (result) {
484 Expect.equals('X-Y-Z', result.reflectee);
485 });
486 future = cm.applyAsync([]);
487 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
488 future = cm.applyAsync(['X', 'Y']);
489 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
490 future = cm.applyAsync(['X'], {const Symbol('undef') : 'Y'});
491 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
492
493
494 cm = reflect(b);
495 future = cm.applyAsync([]);
496 expectValueThen(future, (result) {
497 Expect.equals('A-null-null', result.reflectee);
498 });
499 future = cm.applyAsync([], {const Symbol('a') : 'X'});
500 expectValueThen(future, (result) {
501 Expect.equals('X-null-null', result.reflectee);
502 });
503 future = cm.applyAsync([], {const Symbol('b') :'Y', const Symbol('c') :'Z', co nst Symbol('a') :'X'});
504 expectValueThen(future, (result) {
505 Expect.equals('X-Y-Z', result.reflectee);
506 });
507 future = cm.applyAsync(['X']);
508 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
509 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
510 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
511
512
513 cm = reflect(c);
514 future = cm.applyAsync(['X']);
515 expectValueThen(future, (result) {
516 Expect.equals('X-null-C', result.reflectee);
517 });
518 future = cm.applyAsync(['X', 'Y']);
519 expectValueThen(future, (result) {
520 Expect.equals('X-Y-C', result.reflectee);
521 });
522 future = cm.applyAsync(['X', 'Y', 'Z']);
523 expectValueThen(future, (result) {
524 Expect.equals('X-Y-Z', result.reflectee);
525 });
526 future = cm.applyAsync([]);
527 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
528 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
529 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
530 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
531 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
532
533
534 cm = reflect(d);
535 future = cm.applyAsync([]);
536 expectValueThen(future, (result) {
537 Expect.equals('null-B-C', result.reflectee);
538 });
539 future = cm.applyAsync(['X']);
540 expectValueThen(future, (result) {
541 Expect.equals('X-B-C', result.reflectee);
542 });
543 future = cm.applyAsync(['X', 'Y']);
544 expectValueThen(future, (result) {
545 Expect.equals('X-Y-C', result.reflectee);
546 });
547 future = cm.applyAsync(['X', 'Y', 'Z']);
548 expectValueThen(future, (result) {
549 Expect.equals('X-Y-Z', result.reflectee);
550 });
551 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
552 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
553 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
554 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
555
556
557 cm = reflect(e);
558 future = cm.applyAsync(['X', 'Y', 'Z']);
559 expectValueThen(future, (result) {
560 Expect.equals('X-Y-Z', result.reflectee);
561 });
562 future = cm.applyAsync(['X']);
563 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
564 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
565 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
566 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
567 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
568 }
569
570 main() {
571 testSyncInvoke(reflect(new C())); // InstanceMirror
572 testSyncInvoke(reflectClass(D)); // ClassMirror
573 testSyncInvoke(reflectClass(D).owner); // LibraryMirror
574
575 testAsyncInvoke(reflect(new C())); // InstanceMirror
576 testAsyncInvoke(reflectClass(D)); // ClassMirror
577 testAsyncInvoke(reflectClass(D).owner); // LibraryMirror
578
579 testSyncNewInstance();
580 testAsyncNewInstance();
581
582 testSyncApply();
583 testAsyncApply();
584 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698