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

Side by Side Diff: dart/tests/language/invocation_mirror_test.dart

Issue 14049009: Rename Invocation to InvocationMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged Created 7 years, 8 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 // InvocationMirror and noSuchMethod testing. 7 // Invocation and noSuchMethod testing.
8 8
9 /** Class with noSuchMethod that returns the mirror */ 9 /** Class with noSuchMethod that returns the mirror */
10 class N { 10 class N {
11 // Storage for the last argument to noSuchMethod. 11 // Storage for the last argument to noSuchMethod.
12 // Needed for setters, which don't evaluate to the return value. 12 // Needed for setters, which don't evaluate to the return value.
13 var last; 13 var last;
14 noSuchMethod(InvocationMirror m) => last = m; 14 noSuchMethod(Invocation m) => last = m;
15 15
16 flif(int x) { Expect.fail("never get here"); } 16 flif(int x) { Expect.fail("never get here"); }
17 flaf([int x]) { Expect.fail("never get here"); } 17 flaf([int x]) { Expect.fail("never get here"); }
18 flof({int y}) { Expect.fail("never get here"); } 18 flof({int y}) { Expect.fail("never get here"); }
19 19
20 get wut => this; 20 get wut => this;
21 final int plif = 99; 21 final int plif = 99;
22 int get plaf { Expect.fail("never get here"); return 0; } 22 int get plaf { Expect.fail("never get here"); return 0; }
23 } 23 }
24 24
25 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/ 25 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/
26 class C extends N { 26 class C extends N {
27 call(int x) { Expect.fail("never get here"); } 27 call(int x) { Expect.fail("never get here"); }
28 } 28 }
29 29
30 /** 30 /**
31 * Checks the data of an InvocationMirror. 31 * Checks the data of an Invocation.
32 * 32 *
33 * Call without optionals for getters, with only positional for setters, 33 * Call without optionals for getters, with only positional for setters,
34 * and with both optionals for everything else. 34 * and with both optionals for everything else.
35 */ 35 */
36 testInvocationMirror(InvocationMirror im, String name, 36 testInvocationMirror(Invocation im, String name,
37 [List positional, Map named]) { 37 [List positional, Map named]) {
38 Expect.isTrue(im is InvocationMirror, "is InvocationMirror"); 38 Expect.isTrue(im is Invocation, "is Invocation");
39 Expect.equals(name, im.memberName, "name"); 39 Expect.equals(name, im.memberName, "name");
40 if (named == null) { 40 if (named == null) {
41 Expect.isTrue(im.isAccessor, "$name:isAccessor"); 41 Expect.isTrue(im.isAccessor, "$name:isAccessor");
42 Expect.isFalse(im.isMethod, "$name:isMethod"); 42 Expect.isFalse(im.isMethod, "$name:isMethod");
43 if (positional == null) { 43 if (positional == null) {
44 Expect.isTrue(im.isGetter, "$name:isGetter"); 44 Expect.isTrue(im.isGetter, "$name:isGetter");
45 Expect.isFalse(im.isSetter, "$name:isSetter"); 45 Expect.isFalse(im.isSetter, "$name:isSetter");
46 Expect.equals(0, im.positionalArguments.length, "$name:#positional"); 46 Expect.equals(0, im.positionalArguments.length, "$name:#positional");
47 Expect.equals(0, im.namedArguments.length, "$name:#named"); 47 Expect.equals(0, im.namedArguments.length, "$name:#named");
48 return; 48 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Closurizing a method means that calling it badly will not hit the 145 // Closurizing a method means that calling it badly will not hit the
146 // original receivers noSuchMethod, only the one inherited from Object 146 // original receivers noSuchMethod, only the one inherited from Object
147 // by the closure object. 147 // by the closure object.
148 Expect.throws(() { var x = n.flif; x(37, 42); }, 148 Expect.throws(() { var x = n.flif; x(37, 42); },
149 (e) => e is NoSuchMethodError); 149 (e) => e is NoSuchMethodError);
150 Expect.throws(() { var x = c.call; x(37, 42); }, 150 Expect.throws(() { var x = c.call; x(37, 42); },
151 (e) => e is NoSuchMethodError); 151 (e) => e is NoSuchMethodError);
152 } 152 }
153 153
154 class M extends N { 154 class M extends N {
155 noSuchMethod(InvocationMirror m) { throw "never get here"; } 155 noSuchMethod(Invocation m) { throw "never get here"; }
156 156
157 testSuperCalls() { 157 testSuperCalls() {
158 // Missing property/method access. 158 // Missing property/method access.
159 testInvocationMirror(super.bar, 'bar'); 159 testInvocationMirror(super.bar, 'bar');
160 testInvocationMirror((){super.bar = 42; return last;}(), 'bar=', [42]); 160 testInvocationMirror((){super.bar = 42; return last;}(), 'bar=', [42]);
161 testInvocationMirror(super.bar(), 'bar', [], {}); 161 testInvocationMirror(super.bar(), 'bar', [], {});
162 testInvocationMirror(super.bar(42), 'bar', [42], {}); 162 testInvocationMirror(super.bar(42), 'bar', [42], {});
163 testInvocationMirror(super.bar(x: 42), 'bar', [], {"x": 42}); 163 testInvocationMirror(super.bar(x: 42), 'bar', [], {"x": 42});
164 testInvocationMirror(super.bar(37, x: 42), 'bar', [37], {"x": 42}); 164 testInvocationMirror(super.bar(37, x: 42), 'bar', [37], {"x": 42});
165 165
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 test(() => o.hashCode = 42); 237 test(() => o.hashCode = 42);
238 test(() => o.hashCode()); // Thrown by int.noSuchMethod. 238 test(() => o.hashCode()); // Thrown by int.noSuchMethod.
239 test(() => (n.flif)()); // Extracted method has no noSuchMethod. 239 test(() => (n.flif)()); // Extracted method has no noSuchMethod.
240 } 240 }
241 241
242 main() { 242 main() {
243 testInvocationMirrors(); 243 testInvocationMirrors();
244 testNoSuchMethodErrors(); 244 testNoSuchMethodErrors();
245 new M().testSuperCalls(); 245 new M().testSuperCalls();
246 } 246 }
OLDNEW
« no previous file with comments | « dart/tests/language/invocation_mirror_invoke_on_test.dart ('k') | dart/tests/language/no_such_method2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698