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

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, 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
« 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_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 expectArgumentError(f) {
40 Expect.throws(f, (e) => e is ArgumentError);
41 }
42
43 main() {
44 InstanceMirror im = reflect(new Class());
45 Expect.equals('A-B-C', im[#method]('A', 'B', 'C').reflectee);
46 Expect.throws(() => im[#method]('A', 'B', 'C', 'D'),
47 (e) => e is NoSuchMethodError,
48 'Wrong arity');
49 Expect.equals(7, im[#inheritedMethod](3, 4).reflectee);
50 expectArgumentError(() => im[#field]);
51 expectArgumentError(() => im[#getter]);
52 expectArgumentError(() => im[#setter]);
53 expectArgumentError(() => im[#doesntExist]);
54 expectArgumentError(() => im[#staticFunction]);
55
56 ClassMirror cm = reflectClass(Class);
57 Expect.equals('A-B-C', cm[#staticFunction]('A', 'B', 'C').reflectee);
58 Expect.throws(() => cm[#staticFunction]('A', 'B', 'C', 'D'),
59 (e) => e is NoSuchMethodError,
60 'Wrong arity');
61 expectArgumentError(() => cm[#staticField]);
62 expectArgumentError(() => cm[#staticGetter]);
63 expectArgumentError(() => cm[#staticSetter]);
64 expectArgumentError(() => cm[#staticDoesntExist]);
65 expectArgumentError(() => cm[#staticFunctionInSuper]);
66 expectArgumentError(() => cm[#method]);
67
68 LibraryMirror lm = cm.owner;
69 Expect.equals('A-B-C', lm[#toplevelFunction]('A', 'B', 'C').reflectee);
70 Expect.throws(() => lm[#toplevelFunction]('A', 'B', 'C', 'D'),
71 (e) => e is NoSuchMethodError,
72 'Wrong arity');
73
74 expectArgumentError(() => lm[#toplevelField]);
75 expectArgumentError(() => lm[#toplevelGetter]);
76 expectArgumentError(() => lm[#toplevelSetter]);
77 expectArgumentError(() => lm[#toplevelDoesntExist]);
78
79 // dart2js might stop testing here.
80
81 Expect.equals('A+B+Z', im[#methodWithNamed]('A', y: 'B').reflectee);
82 Expect.equals('A*B*Z', im[#methodWithOptPos]('A', 'B').reflectee);
83 Expect.throws(() => im[#methodWithNamed]('A', w: 'D'),
84 (e) => e is NoSuchMethodError,
85 'Wrong arity');
86 Expect.throws(() => im[#method](),
87 (e) => e is NoSuchMethodError,
88 'Wrong arity');
89
90 Expect.equals('A+B+Z', cm[#staticFunctionWithNamed]('A', y: 'B').reflectee);
91 Expect.equals('A*B*Z', cm[#staticFunctionWithOptPos]('A', 'B').reflectee);
92 Expect.throws(() => cm[#staticFunctionWithNamed]('A', w: 'D'),
93 (e) => e is NoSuchMethodError,
94 'Wrong arity');
95 Expect.throws(() => cm[#staticFunctionWithOptPos](),
96 (e) => e is NoSuchMethodError,
97 'Wrong arity');
98
99 Expect.equals('A+B+Z', lm[#toplevelFunctionWithNamed]('A', y: 'B').reflectee);
100 Expect.equals('A*B*Z', lm[#toplevelFunctionWithOptPos]('A', 'B').reflectee);
101 Expect.throws(() => lm[#toplevelFunctionWithNamed]('A', w: 'D'),
102 (e) => e is NoSuchMethodError,
103 'Wrong arity');
104 Expect.throws(() => lm[#toplevelFunctionWithOptPos](),
105 (e) => e is NoSuchMethodError,
106 'Wrong arity');
107 }
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