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