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

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

Issue 23460050: Mirror removals: async invoke, mirrorSystemOf(port), Mirror.mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.invoke_named_test; 5 library test.invoke_named_test;
6 6
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 8
9 import 'dart:async' show Future; 9 import 'dart:async' show Future;
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 isNoSuchMethodError, 114 isNoSuchMethodError,
115 'Insufficient positional arguments'); 115 'Insufficient positional arguments');
116 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']), 116 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
117 isNoSuchMethodError, 117 isNoSuchMethodError,
118 'Extra positional arguments'); 118 'Extra positional arguments');
119 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef') : 'Y'}), 119 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef') : 'Y'}),
120 isNoSuchMethodError, 120 isNoSuchMethodError,
121 'Unmatched named argument'); 121 'Unmatched named argument');
122 } 122 }
123 123
124 testAsyncInvoke(ObjectMirror om) {
125 Future<InstanceMirror> future;
126
127 future = om.invokeAsync(const Symbol('a'), ['X']);
128 expectValueThen(future, (result) {
129 Expect.equals('X-B-null', result.reflectee);
130 });
131 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('b') : 'Y'});
132 expectValueThen(future, (result) {
133 Expect.equals('X-Y-null', result.reflectee);
134 });
135 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('c') : 'Z', co nst Symbol('b') : 'Y'});
136 expectValueThen(future, (result) {
137 Expect.equals('X-Y-Z', result.reflectee);
138 });
139 future = om.invokeAsync(const Symbol('a'), []);
140 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
141 future = om.invokeAsync(const Symbol('a'), ['X', 'Y']);
142 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
143 future = om.invokeAsync(const Symbol('a'), ['X'], {const Symbol('undef') : 'Y' });
144 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
145
146
147 future = om.invokeAsync(const Symbol('b'), []);
148 expectValueThen(future, (result) {
149 Expect.equals('A-null-null', result.reflectee);
150 });
151 future = om.invokeAsync(const Symbol('b'), [], {const Symbol('a') : 'X'});
152 expectValueThen(future, (result) {
153 Expect.equals('X-null-null', result.reflectee);
154 });
155 future = om.invokeAsync(const Symbol('b'), [], {const Symbol('b') :'Y', const Symbol('c') :'Z', const Symbol('a') :'X'});
156 expectValueThen(future, (result) {
157 Expect.equals('X-Y-Z', result.reflectee);
158 });
159 future = om.invokeAsync(const Symbol('b'), ['X']);
160 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
161 future = om.invokeAsync(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'} );
162 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
163
164 future = om.invokeAsync(const Symbol('c'), ['X']);
165 expectValueThen(future, (result) {
166 Expect.equals('X-null-C', result.reflectee);
167 });
168 future = om.invokeAsync(const Symbol('c'), ['X', 'Y']);
169 expectValueThen(future, (result) {
170 Expect.equals('X-Y-C', result.reflectee);
171 });
172 future = om.invokeAsync(const Symbol('c'), ['X', 'Y', 'Z']);
173 expectValueThen(future, (result) {
174 Expect.equals('X-Y-Z', result.reflectee);
175 });
176 future = om.invokeAsync(const Symbol('c'), []);
177 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
178 future = om.invokeAsync(const Symbol('c'), ['X', 'Y', 'Z', 'W']);
179 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
180 future = om.invokeAsync(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'} );
181 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
182
183
184 future = om.invokeAsync(const Symbol('d'), []);
185 expectValueThen(future, (result) {
186 Expect.equals('null-B-C', result.reflectee);
187 });
188 future = om.invokeAsync(const Symbol('d'), ['X']);
189 expectValueThen(future, (result) {
190 Expect.equals('X-B-C', result.reflectee);
191 });
192 future = om.invokeAsync(const Symbol('d'), ['X', 'Y']);
193 expectValueThen(future, (result) {
194 Expect.equals('X-Y-C', result.reflectee);
195 });
196 future = om.invokeAsync(const Symbol('d'), ['X', 'Y', 'Z']);
197 expectValueThen(future, (result) {
198 Expect.equals('X-Y-Z', result.reflectee);
199 });
200 future = om.invokeAsync(const Symbol('d'), ['X', 'Y', 'Z', 'W']);
201 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
202 future = om.invokeAsync(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'} );
203 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
204
205 future = om.invokeAsync(const Symbol('e'), ['X', 'Y', 'Z']);
206 expectValueThen(future, (result) {
207 Expect.equals('X-Y-Z', result.reflectee);
208 });
209 future = om.invokeAsync(const Symbol('e'), ['X']);
210 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
211 future = om.invokeAsync(const Symbol('e'), ['X', 'Y', 'Z', 'W']);
212 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
213 future = om.invokeAsync(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'} );
214 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
215 }
216
217 testSyncNewInstance() { 124 testSyncNewInstance() {
218 ClassMirror cm = reflectClass(E); 125 ClassMirror cm = reflectClass(E);
219 InstanceMirror result; 126 InstanceMirror result;
220 127
221 result = cm.newInstance(const Symbol(''), ['X']); 128 result = cm.newInstance(const Symbol(''), ['X']);
222 Expect.equals('X-B-null', result.reflectee.field); 129 Expect.equals('X-B-null', result.reflectee.field);
223 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'}); 130 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'});
224 Expect.equals('X-Y-null', result.reflectee.field); 131 Expect.equals('X-Y-null', result.reflectee.field);
225 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con st Symbol('b') : 'Y'}); 132 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con st Symbol('b') : 'Y'});
226 Expect.equals('X-Y-Z', result.reflectee.field); 133 Expect.equals('X-Y-Z', result.reflectee.field);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 isNoSuchMethodError, 191 isNoSuchMethodError,
285 'Insufficient positional arguments'); 192 'Insufficient positional arguments');
286 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']), 193 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
287 isNoSuchMethodError, 194 isNoSuchMethodError,
288 'Extra positional arguments'); 195 'Extra positional arguments');
289 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un def'): 'Y'}), 196 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un def'): 'Y'}),
290 isNoSuchMethodError, 197 isNoSuchMethodError,
291 'Unmatched named argument'); 198 'Unmatched named argument');
292 } 199 }
293 200
294 testAsyncNewInstance() {
295 ClassMirror cm = reflectClass(E);
296 Future<InstanceMirror> future;
297
298 future = cm.newInstanceAsync(const Symbol(''), ['X']);
299 expectValueThen(future, (result) {
300 Expect.equals('X-B-null', result.reflectee.field);
301 });
302 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('b') : 'Y' });
303 expectValueThen(future, (result) {
304 Expect.equals('X-Y-null', result.reflectee.field);
305 });
306 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('c') : 'Z' , const Symbol('b') : 'Y'});
307 expectValueThen(future, (result) {
308 Expect.equals('X-Y-Z', result.reflectee.field);
309 });
310 future = cm.newInstanceAsync(const Symbol(''), []);
311 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
312 future = cm.newInstanceAsync(const Symbol(''), ['X', 'Y']);
313 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
314 future = cm.newInstanceAsync(const Symbol(''), ['X'], {const Symbol('undef') : 'Y'});
315 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
316
317
318 future = cm.newInstanceAsync(const Symbol('b'), []);
319 expectValueThen(future, (result) {
320 Expect.equals('A-null-null', result.reflectee.field);
321 });
322 future = cm.newInstanceAsync(const Symbol('b'), [], {const Symbol('a') : 'X'}) ;
323 expectValueThen(future, (result) {
324 Expect.equals('X-null-null', result.reflectee.field);
325 });
326 future = cm.newInstanceAsync(const Symbol('b'), [], {const Symbol('b') :'Y', c onst Symbol('c') :'Z', const Symbol('a') :'X'});
327 expectValueThen(future, (result) {
328 Expect.equals('X-Y-Z', result.reflectee.field);
329 });
330 future = cm.newInstanceAsync(const Symbol('b'), ['X']);
331 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
332 future = cm.newInstanceAsync(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'});
333 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
334
335
336 future = cm.newInstanceAsync(const Symbol('c'), ['X']);
337 expectValueThen(future, (result) {
338 Expect.equals('X-null-C', result.reflectee.field);
339 });
340 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y']);
341 expectValueThen(future, (result) {
342 Expect.equals('X-Y-C', result.reflectee.field);
343 });
344 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y', 'Z']);
345 expectValueThen(future, (result) {
346 Expect.equals('X-Y-Z', result.reflectee.field);
347 });
348 future = cm.newInstanceAsync(const Symbol('c'), []);
349 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
350 future = cm.newInstanceAsync(const Symbol('c'), ['X', 'Y', 'Z', 'W']);
351 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
352 future = cm.newInstanceAsync(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'});
353 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
354
355
356 future = cm.newInstanceAsync(const Symbol('d'), []);
357 expectValueThen(future, (result) {
358 Expect.equals('null-B-C', result.reflectee.field);
359 });
360 future = cm.newInstanceAsync(const Symbol('d'), ['X']);
361 expectValueThen(future, (result) {
362 Expect.equals('X-B-C', result.reflectee.field);
363 });
364 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y']);
365 expectValueThen(future, (result) {
366 Expect.equals('X-Y-C', result.reflectee.field);
367 });
368 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y', 'Z']);
369 expectValueThen(future, (result) {
370 Expect.equals('X-Y-Z', result.reflectee.field);
371 });
372 future = cm.newInstanceAsync(const Symbol('d'), ['X', 'Y', 'Z', 'W']);
373 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
374 future = cm.newInstanceAsync(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'});
375 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
376
377
378 future = cm.newInstanceAsync(const Symbol('e'), ['X', 'Y', 'Z']);
379 expectValueThen(future, (result) {
380 Expect.equals('X-Y-Z', result.reflectee.field);
381 });
382 future = cm.newInstanceAsync(const Symbol('e'), ['X']);
383 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
384 future = cm.newInstanceAsync(const Symbol('e'), ['X', 'Y', 'Z', 'W']);
385 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
386 future = cm.newInstanceAsync(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'});
387 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
388 }
389
390 testSyncApply() { 201 testSyncApply() {
391 ClosureMirror cm; 202 ClosureMirror cm;
392 InstanceMirror result; 203 InstanceMirror result;
393 204
394 cm = reflect(a); 205 cm = reflect(a);
395 result = cm.apply(['X']); 206 result = cm.apply(['X']);
396 Expect.equals('X-B-null', result.reflectee); 207 Expect.equals('X-B-null', result.reflectee);
397 result = cm.apply(['X'], {const Symbol('b') : 'Y'}); 208 result = cm.apply(['X'], {const Symbol('b') : 'Y'});
398 Expect.equals('X-Y-null', result.reflectee); 209 Expect.equals('X-Y-null', result.reflectee);
399 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'}); 210 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'});
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 isNoSuchMethodError, 273 isNoSuchMethodError,
463 'Insufficient positional arguments'); 274 'Insufficient positional arguments');
464 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), 275 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']),
465 isNoSuchMethodError, 276 isNoSuchMethodError,
466 'Extra positional arguments'); 277 'Extra positional arguments');
467 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), 278 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
468 isNoSuchMethodError, 279 isNoSuchMethodError,
469 'Unmatched named argument'); 280 'Unmatched named argument');
470 } 281 }
471 282
472 testAsyncApply() {
473 ClosureMirror cm;
474 Future<InstanceMirror> future;
475
476 cm = reflect(a);
477 future = cm.applyAsync(['X']);
478 expectValueThen(future, (result) {
479 Expect.equals('X-B-null', result.reflectee);
480 });
481 future = cm.applyAsync(['X'], {const Symbol('b') : 'Y'});
482 expectValueThen(future, (result) {
483 Expect.equals('X-Y-null', result.reflectee);
484 });
485 future = cm.applyAsync(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y '});
486 expectValueThen(future, (result) {
487 Expect.equals('X-Y-Z', result.reflectee);
488 });
489 future = cm.applyAsync([]);
490 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
491 future = cm.applyAsync(['X', 'Y']);
492 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
493 future = cm.applyAsync(['X'], {const Symbol('undef') : 'Y'});
494 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
495
496
497 cm = reflect(b);
498 future = cm.applyAsync([]);
499 expectValueThen(future, (result) {
500 Expect.equals('A-null-null', result.reflectee);
501 });
502 future = cm.applyAsync([], {const Symbol('a') : 'X'});
503 expectValueThen(future, (result) {
504 Expect.equals('X-null-null', result.reflectee);
505 });
506 future = cm.applyAsync([], {const Symbol('b') :'Y', const Symbol('c') :'Z', co nst Symbol('a') :'X'});
507 expectValueThen(future, (result) {
508 Expect.equals('X-Y-Z', result.reflectee);
509 });
510 future = cm.applyAsync(['X']);
511 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
512 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
513 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
514
515
516 cm = reflect(c);
517 future = cm.applyAsync(['X']);
518 expectValueThen(future, (result) {
519 Expect.equals('X-null-C', result.reflectee);
520 });
521 future = cm.applyAsync(['X', 'Y']);
522 expectValueThen(future, (result) {
523 Expect.equals('X-Y-C', result.reflectee);
524 });
525 future = cm.applyAsync(['X', 'Y', 'Z']);
526 expectValueThen(future, (result) {
527 Expect.equals('X-Y-Z', result.reflectee);
528 });
529 future = cm.applyAsync([]);
530 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
531 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
532 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
533 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
534 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
535
536
537 cm = reflect(d);
538 future = cm.applyAsync([]);
539 expectValueThen(future, (result) {
540 Expect.equals('null-B-C', result.reflectee);
541 });
542 future = cm.applyAsync(['X']);
543 expectValueThen(future, (result) {
544 Expect.equals('X-B-C', result.reflectee);
545 });
546 future = cm.applyAsync(['X', 'Y']);
547 expectValueThen(future, (result) {
548 Expect.equals('X-Y-C', result.reflectee);
549 });
550 future = cm.applyAsync(['X', 'Y', 'Z']);
551 expectValueThen(future, (result) {
552 Expect.equals('X-Y-Z', result.reflectee);
553 });
554 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
555 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
556 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
557 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
558
559
560 cm = reflect(e);
561 future = cm.applyAsync(['X', 'Y', 'Z']);
562 expectValueThen(future, (result) {
563 Expect.equals('X-Y-Z', result.reflectee);
564 });
565 future = cm.applyAsync(['X']);
566 expectError(future, isNoSuchMethodError, 'Insufficient positional arguments');
567 future = cm.applyAsync(['X', 'Y', 'Z', 'W']);
568 expectError(future, isNoSuchMethodError, 'Extra positional arguments');
569 future = cm.applyAsync(['X'], {const Symbol('undef'): 'Y'});
570 expectError(future, isNoSuchMethodError, 'Unmatched named argument');
571 }
572
573 main() { 283 main() {
574 isDart2js = true; /// 01: ok 284 isDart2js = true; /// 01: ok
575 285
576 testSyncInvoke(reflect(new C())); // InstanceMirror 286 testSyncInvoke(reflect(new C())); // InstanceMirror
577 if (!isDart2js) testSyncInvoke(reflectClass(D)); // ClassMirror
578 LibraryMirror lib = reflectClass(D).owner;
579 if (!isDart2js) testSyncInvoke(lib); // LibraryMirror
580
581 testAsyncInvoke(reflect(new C())); // InstanceMirror
582 287
583 if (isDart2js) return; 288 if (isDart2js) return;
584 289
585 testAsyncInvoke(reflectClass(D)); // ClassMirror 290 testSyncInvoke(reflectClass(D)); // ClassMirror
586 testAsyncInvoke(lib); // LibraryMirror 291 LibraryMirror lib = reflectClass(D).owner;
292 testSyncInvoke(lib); // LibraryMirror
587 293
588 testSyncNewInstance(); 294 testSyncNewInstance();
589 testAsyncNewInstance();
590 295
591 testSyncApply(); 296 testSyncApply();
592 testAsyncApply();
593 } 297 }
OLDNEW
« no previous file with comments | « tests/lib/mirrors/invoke_closurization_test.dart ('k') | tests/lib/mirrors/invoke_private_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698