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

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: 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
« tests/lib/lib.status ('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() {
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 stops testing here.
76 return; /// 01: ok
77
78 Expect.equals('A+B+Z', im[#methodWithNamed]('A', y: 'B').reflectee);
79 Expect.equals('A*B*Z', im[#methodWithOptPos]('A', 'B').reflectee);
80 Expect.throws(() => im[#methodWithNamed]('A', w: 'D'),
81 (e) => e is NoSuchMethodError,
82 'Wrong arity');
83 Expect.throws(() => im[#method](),
84 (e) => e is NoSuchMethodError,
85 'Wrong arity');
86
87 Expect.equals('A+B+Z', cm[#staticFunctionWithNamed]('A', y: 'B').reflectee);
88 Expect.equals('A*B*Z', cm[#staticFunctionWithOptPos]('A', 'B').reflectee);
89 Expect.throws(() => im[#staticFunctionWithNamed]('A', w: 'D'),
90 (e) => e is NoSuchMethodError,
91 'Wrong arity');
92 Expect.throws(() => im[#staticFunctionWithOptPos](),
93 (e) => e is NoSuchMethodError,
94 'Wrong arity');
95
96 Expect.equals('A+B+Z', lm[#toplevelFunctionWithNamed]('A', y: 'B').reflectee);
97 Expect.equals('A*B*Z', lm[#toplevelFunctionWithOptPos]('A', 'B').reflectee);
98 Expect.throws(() => im[#toplevelFunctionWithNamed]('A', w: 'D'),
99 (e) => e is NoSuchMethodError,
100 'Wrong arity');
101 Expect.throws(() => im[#toplevelFunctionWithOptPos](),
102 (e) => e is NoSuchMethodError,
103 'Wrong arity');
104 }
OLDNEW
« tests/lib/lib.status ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698