Chromium Code Reviews| 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..22663f068f17e4ef916289e009da7ab655889c0b |
| --- /dev/null |
| +++ b/tests/language/invocation_mirror_test.dart |
| @@ -0,0 +1,51 @@ |
| +// 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); |
| + } else if (invocation.memberName == 'div') { |
|
bakster
2012/10/24 13:43:04
Inconsistent use of else parts. I suggest:
if (
Johnni Winther
2012/10/25 13:34:56
Done.
|
| + 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) { |
|
bakster
2012/10/24 13:43:04
Remove else parts
Johnni Winther
2012/10/25 13:34:56
Done.
|
| + return a*b*c; |
| + } else { |
| + return a*b; |
| + } |
| + } |
| +} |
| + |
| +class Div { |
| + int div({int num, int denom}) { |
|
bakster
2012/10/24 13:43:04
Use => for short hand function syntax.
Johnni Winther
2012/10/25 13:34:56
Done.
|
| + 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)); |
| +} |