| Index: tests/language/invocation_mirror_test.dart
|
| diff --git a/tests/language/invocation_mirror_test.dart b/tests/language/invocation_mirror_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..85b06c3faf3d96d2282731fa281f8cf51bb51fab
|
| --- /dev/null
|
| +++ b/tests/language/invocation_mirror_test.dart
|
| @@ -0,0 +1,45 @@
|
| +// 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 direct use of InvocationMirror.invokeOn and Function.apply in
|
| +// noSuchMethod.
|
| +
|
| +class PlusMinus {
|
| + noSuchMethod(InvocationMirror invocation) {
|
| + if (invocation.memberName == 'mul') return invocation.invokeOn(mulObject);
|
| + if (invocation.memberName == 'div') return invocation.invokeOn(divObject);
|
| + return Function.apply(plus,
|
| + invocation.positionalArguments,
|
| + invocation.namedArguments);
|
| + }
|
| +
|
| + int plus(int a, int b) => a + b;
|
| +
|
| + Mul get mulObject => new Mul();
|
| +
|
| + Div 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));
|
| +}
|
|
|