OLD | NEW |
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this | 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in | 2 // source code is governed by a BSD-style license that can be found in |
3 // the LICENSE file. | 3 // the LICENSE file. |
4 | 4 |
5 // File being transformed by the reflectable transformer. | 5 // File being transformed by the reflectable transformer. |
6 // Uses `invoke`. | 6 // Uses `invoke`. |
7 | 7 |
8 library reflectable.test.to_be_transformed.invoke_test; | 8 library reflectable.test.to_be_transformed.invoke_test; |
9 | 9 |
10 import 'package:reflectable/reflectable.dart'; | 10 import 'package:reflectable/reflectable.dart'; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 class MyReflectable extends Reflectable { | 13 class MyReflectable extends Reflectable { |
14 const MyReflectable() : super(invokingCapability); | 14 const MyReflectable() : super(invokingCapability); |
15 } | 15 } |
16 | 16 |
17 const myReflectable = const MyReflectable(); | 17 const myReflectable = const MyReflectable(); |
18 | 18 |
19 @myReflectable | 19 @myReflectable |
20 class A { | 20 class A { |
21 int arg0() => 42; | 21 int arg0() => 42; |
22 int arg1(int x) => x - 42; | 22 int arg1(int x) => x - 42; |
23 int arg1to3(int x, int y, [int z = 0, w]) => x + y + z * 42; | 23 int arg1to3(int x, int y, [int z = 0, w]) => x + y + z * 42; |
24 int argNamed(int x, int y, {int z: 42}) => x + y - z; | 24 int argNamed(int x, int y, |
| 25 {int z: 42}) => x + y - z; |
| 26 int operator+(x) => 42 + x; |
| 27 int operator[](x) => 42 + x; |
| 28 void operator[]=(x, v) => f = x + v; |
| 29 int f = 0; |
25 } | 30 } |
26 | 31 |
27 main() { | 32 main() { |
28 InstanceMirror instanceMirror = myReflectable.reflect(new A()); | 33 A instance = new A(); |
| 34 InstanceMirror instanceMirror = myReflectable.reflect(instance); |
29 test('invoke with no arguments', () { | 35 test('invoke with no arguments', () { |
30 expect(instanceMirror.invoke("arg0", []), 42); | 36 expect(instanceMirror.invoke("arg0", []), 42); |
31 }); | 37 }); |
32 test('invoke with simple argument list, one argument', () { | 38 test('invoke with simple argument list, one argument', () { |
33 expect(instanceMirror.invoke("arg1", [84]), 42); | 39 expect(instanceMirror.invoke("arg1", [84]), 42); |
34 }); | 40 }); |
35 test('invoke with mandatory arguments, omitting optional ones', () { | 41 test('invoke with mandatory arguments, omitting optional ones', () { |
36 expect(instanceMirror.invoke("arg1to3", [40, 2]), 42); | 42 expect(instanceMirror.invoke("arg1to3", [40, 2]), 42); |
37 }); | 43 }); |
38 test('invoke with mandatory arguments, plus some optional ones', () { | 44 test('invoke with mandatory arguments, plus some optional ones', () { |
39 expect(instanceMirror.invoke("arg1to3", [1, -1, 1]), 42); | 45 expect(instanceMirror.invoke("arg1to3", [1, -1, 1]), 42); |
40 }); | 46 }); |
41 test('invoke with mandatory arguments, plus all optional ones', () { | 47 test('invoke with mandatory arguments, plus all optional ones', () { |
42 expect(instanceMirror.invoke("arg1to3", [21, 21, 0, "Ignored"]), 42); | 48 expect(instanceMirror.invoke("arg1to3", [21, 21, 0, "Ignored"]), 42); |
43 }); | 49 }); |
44 test('invoke with mandatory arguments, omitting named ones', () { | 50 test('invoke with mandatory arguments, omitting named ones', () { |
45 expect(instanceMirror.invoke("argNamed", [55, 29]), 42); | 51 expect(instanceMirror.invoke("argNamed", [55, 29]), 42); |
46 }); | 52 }); |
47 test('invoke with mandatory arguments, plus named ones', () { | 53 test('invoke with mandatory arguments, plus named ones', () { |
48 expect(instanceMirror.invoke("argNamed", [21, 21], {#z: 0}), 42); | 54 expect(instanceMirror.invoke("argNamed", [21, 21], {#z: 0}), 42); |
49 }); | 55 }); |
| 56 test('invoke operator +', () { |
| 57 expect(instanceMirror.invoke("+", [42]), 84); |
| 58 }); |
| 59 test('invoke operator []', () { |
| 60 expect(instanceMirror.invoke("[]", [42]), 84); |
| 61 }); |
| 62 test('invoke operator []=', () { |
| 63 instanceMirror.invoke("[]=", [1, 2]); |
| 64 expect(instance.f, 3); |
| 65 }); |
| 66 |
50 } | 67 } |
OLD | NEW |