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

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

Issue 25741005: Implement ObjectMirror.[] (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix mistake in merge conflict Created 7 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 | Annotate | Revision Log
« sdk/lib/mirrors/mirrors.dart ('K') | « 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_subscript_test;
6
7 import 'dart:mirrors';
8 import 'package:expect/expect.dart';
9
10 class Super {
11 inheritedMethod(a, b) => a + b;
12 staticFunctionInSuper(x) => x;
13 }
14
15 class Class extends Super {
16 var field = 'f';
17 get getter => 'g';
18 set setter(v) => 's';
19 method(x, y, z) => '$x-$y-$z';
20 methodWithNamed(x, {y, z:'Z'}) => '$x+$y+$z';
21 methodWithOptPos(x, [y, z='Z']) => '$x*$y*$z';
22
23 static var staticField = 'sf';
24 static get staticGetter => 'sg';
25 static set staticSetter(v) => 'ss';
26 static staticFunction(x, y, z) => '$x-$y-$z';
27 static staticFunctionWithNamed(x, {y, z:'Z'}) => '$x+$y+$z';
28 static staticFunctionWithOptPos(x, [y, z='Z']) => '$x*$y*$z';
29
30 }
31
32 var toplevelField ='tf';
33 get toplevelGetter => 'tg';
34 set toplevelSetter(v) => 'ts';
35 toplevelFunction(x, y, z) => '$x-$y-$z';
36 toplevelFunctionWithNamed(x, {y, z:'Z'}) => '$x+$y+$z';
37 toplevelFunctionWithOptPos(x, [y, z='Z']) => '$x*$y*$z';
38
39 main() {
ahe 2013/10/29 10:25:24 Could you add some tests of what happens for im[#m
rmacnak 2013/10/29 18:03:38 Already have im[#doesntExist].
40 InstanceMirror im = reflect(new Class());
41 Expect.equals('A-B-C', im[#method]('A', 'B', 'C').reflectee);
42 Expect.throws(() => im[#method]('A', 'B', 'C', 'D'),
43 (e) => e is NoSuchMethodError,
44 'Wrong arity');
45 Expect.equals(7, im[#inheritedMethod](3, 4).reflectee);
46 Expect.isNull(im[#field]);
47 Expect.isNull(im[#getter]);
48 Expect.isNull(im[#setter]);
49 Expect.isNull(im[#doesntExist]);
50 Expect.isNull(im[#staticFunction]);
51
52 ClassMirror cm = reflectClass(Class);
53 Expect.equals('A-B-C', cm[#staticFunction]('A', 'B', 'C').reflectee);
54 Expect.throws(() => im[#staticFunction]('A', 'B', 'C', 'D'),
55 (e) => e is NoSuchMethodError,
56 'Wrong arity');
57 Expect.isNull(cm[#staticField]);
58 Expect.isNull(cm[#staticGetter]);
59 Expect.isNull(cm[#staticSetter]);
60 Expect.isNull(cm[#staticDoesntExist]);
61 Expect.isNull(cm[#staticFunctionInSuper]);
62 Expect.isNull(cm[#method]);
63
64 LibraryMirror lm = cm.owner;
65 Expect.equals('A-B-C', lm[#toplevelFunction]('A', 'B', 'C').reflectee);
66 Expect.throws(() => im[#toplevelFunction]('A', 'B', 'C', 'D'),
67 (e) => e is NoSuchMethodError,
68 'Wrong arity');
69
70 Expect.isNull(cm[#toplevelField]);
71 Expect.isNull(cm[#toplevelGetter]);
72 Expect.isNull(cm[#toplevelSetter]);
73 Expect.isNull(cm[#toplevelDoesntExist]);
74
75 // dart2js might stop testing here.
76
77 Expect.equals('A+B+Z', im[#methodWithNamed]('A', y: 'B').reflectee);
78 Expect.equals('A*B*Z', im[#methodWithOptPos]('A', 'B').reflectee);
79 Expect.throws(() => im[#methodWithNamed]('A', w: 'D'),
80 (e) => e is NoSuchMethodError,
81 'Wrong arity');
82 Expect.throws(() => im[#method](),
83 (e) => e is NoSuchMethodError,
84 'Wrong arity');
85
86 Expect.equals('A+B+Z', cm[#staticFunctionWithNamed]('A', y: 'B').reflectee);
87 Expect.equals('A*B*Z', cm[#staticFunctionWithOptPos]('A', 'B').reflectee);
88 Expect.throws(() => im[#staticFunctionWithNamed]('A', w: 'D'),
89 (e) => e is NoSuchMethodError,
90 'Wrong arity');
91 Expect.throws(() => im[#staticFunctionWithOptPos](),
92 (e) => e is NoSuchMethodError,
93 'Wrong arity');
94
95 Expect.equals('A+B+Z', lm[#toplevelFunctionWithNamed]('A', y: 'B').reflectee);
96 Expect.equals('A*B*Z', lm[#toplevelFunctionWithOptPos]('A', 'B').reflectee);
97 Expect.throws(() => im[#toplevelFunctionWithNamed]('A', w: 'D'),
98 (e) => e is NoSuchMethodError,
99 'Wrong arity');
100 Expect.throws(() => im[#toplevelFunctionWithOptPos](),
101 (e) => e is NoSuchMethodError,
102 'Wrong arity');
103 }
OLDNEW
« sdk/lib/mirrors/mirrors.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698