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..8ddfcb58cec4681a2540d66133cec3cd0f1f5c22 |
| --- /dev/null |
| +++ b/tests/language/invocation_mirror_indirect_test.dart |
| @@ -0,0 +1,50 @@ |
| +// 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. |
| + |
| +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; |
|
ngeoffray
2012/10/26 08:34:55
spaces between +, and same for other operators in
Johnni Winther
2012/10/26 10:18:01
Done.
|
| + |
| + get mulObject => new Mul(); |
| + |
| + get divObject => new Div(); |
| +} |
| + |
| +class Mul { |
| + int mul(int a, int b, [int c]) { |
| + if (?c) { |
| + return a*b*c; |
| + } |
| + return a*b; |
| + } |
| +} |
| + |
| +class Div { |
| + int div({int num, int denom}) => 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)); |
| +} |