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 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class GetName { | 8 class GetName { |
9 foo({a, b}) => "foo"; | 9 foo({a, b}) => "foo"; |
10 moo({b}) => "moo"; | 10 moo({b}) => "moo"; |
11 } | 11 } |
12 | 12 |
13 String getName(im) => im.invokeOn(new GetName()); | 13 String getName(im) => im.invokeOn(new GetName()); |
14 | 14 |
15 class NoSuchMethodTest { | 15 class NoSuchMethodTest { |
16 | 16 |
17 foo({a : 10, b : 20}) { | 17 foo({a : 10, b : 20}) { |
18 return (10 * a) + b; | 18 return (10 * a) + b; |
19 } | 19 } |
20 | 20 |
21 noSuchMethod(InvocationMirror im) { | 21 noSuchMethod(Invocation im) { |
22 Expect.equals("moo", getName(im)); | 22 Expect.equals("moo", getName(im)); |
23 Expect.equals(0, im.positionalArguments.length); | 23 Expect.equals(0, im.positionalArguments.length); |
24 Expect.equals(1, im.namedArguments.length); | 24 Expect.equals(1, im.namedArguments.length); |
25 return foo(b:im.namedArguments["b"]); | 25 return foo(b:im.namedArguments["b"]); |
26 } | 26 } |
27 | 27 |
28 static testMain() { | 28 static testMain() { |
29 var obj = new NoSuchMethodTest(); | 29 var obj = new NoSuchMethodTest(); |
30 Expect.equals(199, obj.moo(b:99)); // obj.NoSuchMethod called here. | 30 Expect.equals(199, obj.moo(b:99)); // obj.NoSuchMethod called here. |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 main() { | 34 main() { |
35 NoSuchMethodTest.testMain(); | 35 NoSuchMethodTest.testMain(); |
36 } | 36 } |
OLD | NEW |