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

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, 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
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 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'invoke_test.dart'; 10 import 'invoke_test.dart';
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 isNoSuchMethodError, 109 isNoSuchMethodError,
110 'Insufficient positional arguments'); 110 'Insufficient positional arguments');
111 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']), 111 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
112 isNoSuchMethodError, 112 isNoSuchMethodError,
113 'Extra positional arguments'); 113 'Extra positional arguments');
114 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef') : 'Y'}), 114 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef') : 'Y'}),
115 isNoSuchMethodError, 115 isNoSuchMethodError,
116 'Unmatched named argument'); 116 'Unmatched named argument');
117 } 117 }
118 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() { 119 testSyncNewInstance() {
215 ClassMirror cm = reflectClass(E); 120 ClassMirror cm = reflectClass(E);
216 InstanceMirror result; 121 InstanceMirror result;
217 122
218 result = cm.newInstance(const Symbol(''), ['X']); 123 result = cm.newInstance(const Symbol(''), ['X']);
219 Expect.equals('X-B-null', result.reflectee.field); 124 Expect.equals('X-B-null', result.reflectee.field);
220 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'}); 125 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'});
221 Expect.equals('X-Y-null', result.reflectee.field); 126 Expect.equals('X-Y-null', result.reflectee.field);
222 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con st Symbol('b') : 'Y'}); 127 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con st Symbol('b') : 'Y'});
223 Expect.equals('X-Y-Z', result.reflectee.field); 128 Expect.equals('X-Y-Z', result.reflectee.field);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 isNoSuchMethodError, 186 isNoSuchMethodError,
282 'Insufficient positional arguments'); 187 'Insufficient positional arguments');
283 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']), 188 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']),
284 isNoSuchMethodError, 189 isNoSuchMethodError,
285 'Extra positional arguments'); 190 'Extra positional arguments');
286 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un def'): 'Y'}), 191 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un def'): 'Y'}),
287 isNoSuchMethodError, 192 isNoSuchMethodError,
288 'Unmatched named argument'); 193 'Unmatched named argument');
289 } 194 }
290 195
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() { 196 testSyncApply() {
388 ClosureMirror cm; 197 ClosureMirror cm;
389 InstanceMirror result; 198 InstanceMirror result;
390 199
391 cm = reflect(a); 200 cm = reflect(a);
392 result = cm.apply(['X']); 201 result = cm.apply(['X']);
393 Expect.equals('X-B-null', result.reflectee); 202 Expect.equals('X-B-null', result.reflectee);
394 result = cm.apply(['X'], {const Symbol('b') : 'Y'}); 203 result = cm.apply(['X'], {const Symbol('b') : 'Y'});
395 Expect.equals('X-Y-null', result.reflectee); 204 Expect.equals('X-Y-null', result.reflectee);
396 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'}); 205 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'});
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 isNoSuchMethodError, 268 isNoSuchMethodError,
460 'Insufficient positional arguments'); 269 'Insufficient positional arguments');
461 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), 270 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']),
462 isNoSuchMethodError, 271 isNoSuchMethodError,
463 'Extra positional arguments'); 272 'Extra positional arguments');
464 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), 273 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}),
465 isNoSuchMethodError, 274 isNoSuchMethodError,
466 'Unmatched named argument'); 275 'Unmatched named argument');
467 } 276 }
468 277
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() { 278 main() {
571 testSyncInvoke(reflect(new C())); // InstanceMirror 279 testSyncInvoke(reflect(new C())); // InstanceMirror
572 testSyncInvoke(reflectClass(D)); // ClassMirror 280 testSyncInvoke(reflectClass(D)); // ClassMirror
573 testSyncInvoke(reflectClass(D).owner); // LibraryMirror 281 testSyncInvoke(reflectClass(D).owner); // LibraryMirror
574 282
575 testAsyncInvoke(reflect(new C())); // InstanceMirror
576 testAsyncInvoke(reflectClass(D)); // ClassMirror
577 testAsyncInvoke(reflectClass(D).owner); // LibraryMirror
578
579 testSyncNewInstance(); 283 testSyncNewInstance();
580 testAsyncNewInstance();
581 284
582 testSyncApply(); 285 testSyncApply();
583 testAsyncApply();
584 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698