Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 testInvocationMirror(InvocationMirror im, String name, | 34 testInvocationMirror(InvocationMirror im, String name, |
| 35 [List positional, Map named]) { | 35 [List positional, Map named]) { |
| 36 Expect.isTrue(im is InvocationMirror, "is InvocationMirror"); | 36 Expect.isTrue(im is InvocationMirror, "is InvocationMirror"); |
| 37 Expect.equals(name, im.memberName, "name"); | 37 Expect.equals(name, im.memberName, "name"); |
| 38 if (named == null) { | 38 if (named == null) { |
| 39 Expect.isTrue(im.isAccessor, "$name:isAccessor"); | 39 Expect.isTrue(im.isAccessor, "$name:isAccessor"); |
| 40 Expect.isFalse(im.isMethod, "$name:isMethod"); | 40 Expect.isFalse(im.isMethod, "$name:isMethod"); |
| 41 if (positional == null) { | 41 if (positional == null) { |
| 42 Expect.isTrue(im.isGetter, "$name:isGetter"); | 42 Expect.isTrue(im.isGetter, "$name:isGetter"); |
| 43 Expect.isFalse(im.isSetter, "$name:isSetter"); | 43 Expect.isFalse(im.isSetter, "$name:isSetter"); |
| 44 Expect.equals(null, im.positionalArguments, "$name:positional"); | 44 Expect.equals(0, im.positionalArguments.length, "$name:#positional"); |
| 45 Expect.equals(null, im.namedArguments, "$name:named"); | 45 Expect.equals(0, im.namedArguments.length, "$name:#named"); |
|
Lasse Reichstein Nielsen
2013/01/02 09:59:29
This change is incorrect.
The API specification fo
regis
2013/01/02 17:37:21
The Language Spec has refined the description of t
| |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 Expect.isTrue(im.isSetter, "$name:isSetter"); | 48 Expect.isTrue(im.isSetter, "$name:isSetter"); |
| 49 Expect.isFalse(im.isGetter, "$name:isGetter"); | 49 Expect.isFalse(im.isGetter, "$name:isGetter"); |
| 50 Expect.equals(1, im.positionalArguments.length, "$name:#positional"); | 50 Expect.equals(1, im.positionalArguments.length, "$name:#positional"); |
| 51 Expect.equals(positional[0], im.positionalArguments[0], | 51 Expect.equals(positional[0], im.positionalArguments[0], |
| 52 "$name:positional[0]"); | 52 "$name:positional[0]"); |
| 53 Expect.equals(null, im.namedArguments, "$name:named"); | 53 Expect.equals(0, im.namedArguments.length, "$name:#named"); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 Expect.isTrue(im.isMethod, "$name:isMethod"); | 56 Expect.isTrue(im.isMethod, "$name:isMethod"); |
| 57 Expect.isFalse(im.isAccessor, "$name:isAccessor"); | 57 Expect.isFalse(im.isAccessor, "$name:isAccessor"); |
| 58 Expect.isFalse(im.isSetter, "$name:isSetter"); | 58 Expect.isFalse(im.isSetter, "$name:isSetter"); |
| 59 Expect.isFalse(im.isGetter, "$name:isGetter"); | 59 Expect.isFalse(im.isGetter, "$name:isGetter"); |
| 60 | 60 |
| 61 Expect.equals(positional.length, im.positionalArguments.length); | 61 Expect.equals(positional.length, im.positionalArguments.length); |
| 62 for (int i = 0; i < positional.length; i++) { | 62 for (int i = 0; i < positional.length; i++) { |
| 63 Expect.equals(positional[i], im.positionalArguments[i], | 63 Expect.equals(positional[i], im.positionalArguments[i], |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 testInvocationMirror(super.bar(), 'bar', [], {}); | 159 testInvocationMirror(super.bar(), 'bar', [], {}); |
| 160 testInvocationMirror(super.bar(42), 'bar', [42], {}); | 160 testInvocationMirror(super.bar(42), 'bar', [42], {}); |
| 161 testInvocationMirror(super.bar(x: 42), 'bar', [], {"x": 42}); | 161 testInvocationMirror(super.bar(x: 42), 'bar', [], {"x": 42}); |
| 162 testInvocationMirror(super.bar(37, x: 42), 'bar', [37], {"x": 42}); | 162 testInvocationMirror(super.bar(37, x: 42), 'bar', [37], {"x": 42}); |
| 163 | 163 |
| 164 // Missing operator access. | 164 // Missing operator access. |
| 165 testInvocationMirror(super + 4, '+', [4], {}); | 165 testInvocationMirror(super + 4, '+', [4], {}); |
| 166 testInvocationMirror(super - 4, '-', [4], {}); | 166 testInvocationMirror(super - 4, '-', [4], {}); |
| 167 testInvocationMirror(-super, 'unary-', [], {}); | 167 testInvocationMirror(-super, 'unary-', [], {}); |
| 168 testInvocationMirror(super[42], '[]', [42], {}); | 168 testInvocationMirror(super[42], '[]', [42], {}); |
| 169 testInvocationMirror((super[37] = 42).last, '[]=', [37, 42], {}); | 169 testInvocationMirror((){super[37] = 42; return last;}(), '[]=', [37, 42], {} ); |
| 170 | 170 |
| 171 // Wrong arguments to existing function. | 171 // Wrong arguments to existing function. |
| 172 testInvocationMirror(super.flif(), "flif", [], {}); | 172 testInvocationMirror(super.flif(), "flif", [], {}); |
| 173 testInvocationMirror(super.flif(37, 42), "flif", [37, 42], {}); | 173 testInvocationMirror(super.flif(37, 42), "flif", [37, 42], {}); |
| 174 testInvocationMirror(super.flif(x: 42), "flif", [], {"x": 42}); | 174 testInvocationMirror(super.flif(x: 42), "flif", [], {"x": 42}); |
| 175 testInvocationMirror(super.flif(37, x: 42), "flif", [37], {"x": 42}); | 175 testInvocationMirror(super.flif(37, x: 42), "flif", [37], {"x": 42}); |
| 176 testInvocationMirror((){super.flif = 42; return last;}(), "flif=", [42]); | 176 testInvocationMirror((){super.flif = 42; return last;}(), "flif=", [42]); |
| 177 | 177 |
| 178 testInvocationMirror(super.flaf(37, 42), "flaf", [37, 42], {}); | 178 testInvocationMirror(super.flaf(37, 42), "flaf", [37, 42], {}); |
| 179 testInvocationMirror(super.flaf(x: 42), "flaf", [], {"x": 42}); | 179 testInvocationMirror(super.flaf(x: 42), "flaf", [], {"x": 42}); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 test(() => o + 2); | 227 test(() => o + 2); |
| 228 test(() => -o); | 228 test(() => -o); |
| 229 test(() => o[0]); | 229 test(() => o[0]); |
| 230 test(() => o[0] = 42); | 230 test(() => o[0] = 42); |
| 231 test(() => o()); | 231 test(() => o()); |
| 232 test(() => o.toString = 42); | 232 test(() => o.toString = 42); |
| 233 test(() => o.toString(42)); | 233 test(() => o.toString(42)); |
| 234 test(() => o.toString(x: 37)); | 234 test(() => o.toString(x: 37)); |
| 235 test(() => o.hashCode = 42); | 235 test(() => o.hashCode = 42); |
| 236 test(() => o.hashCode()); // Thrown by int.noSuchMethod. | 236 test(() => o.hashCode()); // Thrown by int.noSuchMethod. |
| 237 test(n.flif); // Extracted method has no noSuchMethod. | 237 test(() => (n.flif)()); // Extracted method has no noSuchMethod. |
| 238 } | 238 } |
| 239 | 239 |
| 240 main() { | 240 main() { |
| 241 testInvocationMirrors(); | 241 testInvocationMirrors(); |
| 242 testNoSuchMethodErrors(); | 242 testNoSuchMethodErrors(); |
| 243 new M().testSuperCalls(); | 243 new M().testSuperCalls(); |
| 244 } | 244 } |
| OLD | NEW |