OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart test program testing that NoSuchMethod is properly called. | 4 // Dart test program testing that NoSuchMethod is properly called. |
5 | 5 |
| 6 class GetName { |
| 7 foo({a, b}) => "foo"; |
| 8 moo({b}) => "moo"; |
| 9 } |
| 10 |
| 11 static String getName(im) => im.invokeOn(new GetName()); |
| 12 |
6 class NoSuchMethodTest { | 13 class NoSuchMethodTest { |
7 | 14 |
8 foo({a : 10, b : 20}) { | 15 foo({a : 10, b : 20}) { |
9 return (10 * a) + b; | 16 return (10 * a) + b; |
10 } | 17 } |
11 | 18 |
12 noSuchMethod(InvocationMirror im) { | 19 noSuchMethod(InvocationMirror im) { |
13 Expect.equals("moo", im.memberName); | 20 Expect.equals("moo", getName(im)); |
14 Expect.equals(0, im.positionalArguments.length); | 21 Expect.equals(0, im.positionalArguments.length); |
15 Expect.equals(1, im.namedArguments.length); | 22 Expect.equals(1, im.namedArguments.length); |
16 return foo(b:im.namedArguments["b"]); | 23 return foo(b:im.namedArguments["b"]); |
17 } | 24 } |
18 | 25 |
19 static testMain() { | 26 static testMain() { |
20 var obj = new NoSuchMethodTest(); | 27 var obj = new NoSuchMethodTest(); |
21 Expect.equals(199, obj.moo(b:99)); // obj.NoSuchMethod called here. | 28 Expect.equals(199, obj.moo(b:99)); // obj.NoSuchMethod called here. |
22 } | 29 } |
23 } | 30 } |
24 | 31 |
25 main() { | 32 main() { |
26 NoSuchMethodTest.testMain(); | 33 NoSuchMethodTest.testMain(); |
27 } | 34 } |
OLD | NEW |