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

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

Issue 11572011: Add more super-invocation InvocationMirror tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test failure to dart2js expectations Created 8 years 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 // InvocationMirror and noSuchMethod testing. 5 // InvocationMirror and noSuchMethod testing.
6 6
7 /** Class with noSuchMethod that returns the mirror */ 7 /** Class with noSuchMethod that returns the mirror */
8 class N { 8 class N {
9 // Storage for the last argument to noSuchMethod. 9 // Storage for the last argument to noSuchMethod.
10 // Needed for setters, which don't evaluate to the return value. 10 // Needed for setters, which don't evaluate to the return value.
11 var last; 11 var last;
12 noSuchMethod(InvocationMirror m) => last = m; 12 noSuchMethod(InvocationMirror m) => last = m;
13 13
14 get wut => this;
15
16 flif(int x) { Expect.fail("never get here"); } 14 flif(int x) { Expect.fail("never get here"); }
17 flaf([int x]) { Expect.fail("never get here"); } 15 flaf([int x]) { Expect.fail("never get here"); }
18 flof({int y}) { Expect.fail("never get here"); } 16 flof({int y}) { Expect.fail("never get here"); }
19 17
18 get wut => this;
20 final int plif = 99; 19 final int plif = 99;
21 int get plaf { Expect.fail("never get here"); return 0; } 20 int get plaf { Expect.fail("never get here"); return 0; }
22 } 21 }
23 22
24 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/ 23 /** As [N] but also implements 'call', so we can call it with wrong arguments.*/
25 class C extends N { 24 class C extends N {
26 call(int x) { Expect.fail("never get here"); } 25 call(int x) { Expect.fail("never get here"); }
27 } 26 }
28 27
29 /** 28 /**
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Expect.isTrue(n.flof is Function); 126 Expect.isTrue(n.flof is Function);
128 127
129 // Writing to read-only fields. 128 // Writing to read-only fields.
130 testInvocationMirror((n..wut = 42).last, "wut=", [42]); 129 testInvocationMirror((n..wut = 42).last, "wut=", [42]);
131 testInvocationMirror((n..plif = 42).last, "plif=", [42]); 130 testInvocationMirror((n..plif = 42).last, "plif=", [42]);
132 testInvocationMirror((n..plaf = 42).last, "plaf=", [42]); 131 testInvocationMirror((n..plaf = 42).last, "plaf=", [42]);
133 132
134 // Trick call to n.call - wut is a getter returning n again. 133 // Trick call to n.call - wut is a getter returning n again.
135 testInvocationMirror(n.wut(42), "call", [42], {}); 134 testInvocationMirror(n.wut(42), "call", [42], {});
136 135
136 // Calling noSuchMethod itself, badly.
137 testInvocationMirror(n.noSuchMethod(), "noSuchMethod", [], {});
138 testInvocationMirror(n.noSuchMethod(37, 42), "noSuchMethod", [37, 42], {});
139 testInvocationMirror(n.noSuchMethod(37, x:42),
140 "noSuchMethod", [37], {"x": 42});
141 testInvocationMirror(n.noSuchMethod(x:42), "noSuchMethod", [], {"x": 42});
142
137 // Closurizing a method means that calling it badly will not hit the 143 // Closurizing a method means that calling it badly will not hit the
138 // original receivers noSuchMethod, only the one inherited from Object 144 // original receivers noSuchMethod, only the one inherited from Object
139 // by the closure object. 145 // by the closure object.
140 Expect.throws(() { var x = n.flif; x(37, 42); }, 146 Expect.throws(() { var x = n.flif; x(37, 42); },
141 (e) => e is NoSuchMethodError); 147 (e) => e is NoSuchMethodError);
142 Expect.throws(() { var x = c.call; x(37, 42); }, 148 Expect.throws(() { var x = c.call; x(37, 42); },
143 (e) => e is NoSuchMethodError); 149 (e) => e is NoSuchMethodError);
144 } 150 }
145 151
152 class M extends N {
153 noSuchMethod(InvocationMirror m) { throw "never get here"; }
154
155 testSuperCalls() {
156 // Missing property/method access.
157 testInvocationMirror(super.bar, 'bar');
158 testInvocationMirror((){super.bar = 42; return last;}(), 'bar=', [42]);
159 testInvocationMirror(super.bar(), 'bar', [], {});
160 testInvocationMirror(super.bar(42), 'bar', [42], {});
161 testInvocationMirror(super.bar(x: 42), 'bar', [], {"x": 42});
162 testInvocationMirror(super.bar(37, x: 42), 'bar', [37], {"x": 42});
163
164 // Missing operator access.
165 testInvocationMirror(super + 4, '+', [4], {});
166 testInvocationMirror(super - 4, '-', [4], {});
167 testInvocationMirror(-super, 'unary-', [], {});
168 testInvocationMirror(super[42], '[]', [42], {});
169 testInvocationMirror((super[37] = 42).last, '[]=', [37, 42], {});
170
171 // Wrong arguments to existing function.
172 testInvocationMirror(super.flif(), "flif", [], {});
173 testInvocationMirror(super.flif(37, 42), "flif", [37, 42], {});
174 testInvocationMirror(super.flif(x: 42), "flif", [], {"x": 42});
175 testInvocationMirror(super.flif(37, x: 42), "flif", [37], {"x": 42});
176 testInvocationMirror((){super.flif = 42; return last;}(), "flif=", [42]);
177
178 testInvocationMirror(super.flaf(37, 42), "flaf", [37, 42], {});
179 testInvocationMirror(super.flaf(x: 42), "flaf", [], {"x": 42});
180 testInvocationMirror(super.flaf(37, x: 42), "flaf", [37], {"x": 42});
181 testInvocationMirror((){super.flaf = 42; return last;}(), "flaf=", [42]);
182
183 testInvocationMirror(super.flof(37, 42), "flof", [37, 42], {});
184 testInvocationMirror(super.flof(x: 42), "flof", [], {"x": 42});
185 testInvocationMirror(super.flof(37, y: 42), "flof", [37], {"y": 42});
186 testInvocationMirror((){super.flof = 42; return last;}(), "flof=", [42]);
187
188 // Reading works.
189 Expect.isTrue(super.flif is Function);
190 Expect.isTrue(super.flaf is Function);
191 Expect.isTrue(super.flof is Function);
192
193 // Writing to read-only fields.
194 testInvocationMirror((){super.wut = 42; return last;}(), "wut=", [42]);
195 testInvocationMirror((){super.plif = 42; return last;}(), "plif=", [42]);
196 testInvocationMirror((){super.plaf = 42; return last;}(), "plaf=", [42]);
197
198 // Calling noSuchMethod itself, badly.
199 testInvocationMirror(super.noSuchMethod(), "noSuchMethod", [], {});
200 testInvocationMirror(super.noSuchMethod(37, 42),
201 "noSuchMethod", [37, 42], {});
202 testInvocationMirror(super.noSuchMethod(37, x:42),
203 "noSuchMethod", [37], {"x": 42});
204 testInvocationMirror(super.noSuchMethod(x:42),
205 "noSuchMethod", [], {"x": 42});
206
207 // Closurizing a method means that calling it badly will not hit the
208 // original receivers noSuchMethod, only the one inherited from Object
209 // by the closure object.
210 Expect.throws(() { var x = super.flif; x(37, 42); },
211 (e) => e is NoSuchMethodError);
212 }
213 }
214
215
216
146 // Test the NoSuchMethodError thrown by different incorrect calls. 217 // Test the NoSuchMethodError thrown by different incorrect calls.
147 testNoSuchMethodErrors() { 218 testNoSuchMethodErrors() {
148 test(Function block) { 219 test(Function block) {
149 Expect.throws(block, (e) => e is NoSuchMethodError); 220 Expect.throws(block, (e) => e is NoSuchMethodError);
150 } 221 }
151 var n = new N(); 222 var n = new N();
152 var o = new Object(); 223 var o = new Object();
153 test(() => o.bar); 224 test(() => o.bar);
154 test(() => o.bar = 42); 225 test(() => o.bar = 42);
155 test(() => o.bar()); 226 test(() => o.bar());
156 test(() => o + 2); 227 test(() => o + 2);
157 test(() => -o); 228 test(() => -o);
158 test(() => o[0]); 229 test(() => o[0]);
159 test(() => o[0] = 42); 230 test(() => o[0] = 42);
160 test(() => o()); 231 test(() => o());
161 test(() => o.toString = 42); 232 test(() => o.toString = 42);
162 test(() => o.toString(42)); 233 test(() => o.toString(42));
163 test(() => o.toString(x: 37)); 234 test(() => o.toString(x: 37));
164 test(() => o.hashCode = 42); 235 test(() => o.hashCode = 42);
165 test(() => o.hashCode()); // Thrown by int.noSuchMethod. 236 test(() => o.hashCode()); // Thrown by int.noSuchMethod.
166 test(n.flif); // Extracted method has no noSuchMethod. 237 test(n.flif); // Extracted method has no noSuchMethod.
167 } 238 }
168 239
169 main() { 240 main() {
170 testInvocationMirrors(); 241 testInvocationMirrors();
171 testNoSuchMethodErrors(); 242 testNoSuchMethodErrors();
243 new M().testSuperCalls();
172 } 244 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/builder.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698