Chromium Code Reviews| Index: tests/language/invocation_mirror_indirect_test.dart |
| diff --git a/tests/language/invocation_mirror_indirect_test.dart b/tests/language/invocation_mirror_indirect_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a2ec21743fe0bb4e9321bf1142f36a4642ad5f47 |
| --- /dev/null |
| +++ b/tests/language/invocation_mirror_indirect_test.dart |
| @@ -0,0 +1,53 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Test indirect use of InvocationMirror.invokeOn and Function.apply in |
| +// noSuchMethod. |
| + |
|
bakster
2012/10/24 13:43:04
My comments from tests/language/invocation_mirror
Johnni Winther
2012/10/25 13:34:56
Done.
|
| +class PlusMinus { |
| + noSuchMethod(var invocation) { |
| + var invok = invocation.invokeOn; |
| + var funcApp = Function.apply; |
| + if (invocation.memberName == 'mul') { |
| + return invok(mulObject); |
| + } else if (invocation.memberName == 'div') { |
| + return invok(divObject); |
| + } |
| + return funcApp(plus, |
| + invocation.positionalArguments, |
| + invocation.namedArguments); |
| + } |
| + |
| + int plus(int a, int b) => a+b; |
| + |
| + get mulObject => new Mul(); |
| + |
| + get divObject => new Div(); |
| +} |
| + |
| +class Mul { |
| + int mul(int a, int b, [int c]) { |
| + if (?c) { |
| + return a*b*c; |
| + } else { |
| + return a*b; |
| + } |
| + } |
| +} |
| + |
| +class Div { |
| + int div({int num, int denom}) { |
| + return num/denom; |
| + } |
| +} |
| + |
| +void main() { |
| + var pm = new PlusMinus(); |
| + Expect.equals(7, pm.plus(2, 5)); |
| + Expect.equals(5, pm.minus(2, 3)); // Calls plus. |
| + Expect.equals(6, pm.mul(2, 3)); |
| + Expect.equals(24, pm.mul(2, 3, 4)); |
| + Expect.equals(5, pm.div(num:10, denom:2)); |
| + Expect.equals(5, pm.div(denom:2, num:10)); |
| +} |