OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "symbol_map_helper.dart"; | 6 import "symbol_map_helper.dart"; |
7 | 7 |
8 // Testing Function.apply calls correctly. | 8 // Testing Function.apply calls correctly. |
9 // This test is not testing error handling, only that correct parameters | 9 // This test is not testing error handling, only that correct parameters |
10 // cause a correct call. | 10 // cause a correct call. |
(...skipping 17 matching lines...) Expand all Loading... |
28 @NoInline() | 28 @NoInline() |
29 @AssumeDynamic() | 29 @AssumeDynamic() |
30 confuse(x) => x; | 30 confuse(x) => x; |
31 | 31 |
32 main() { | 32 main() { |
33 testMap(res, func, map) { | 33 testMap(res, func, map) { |
34 map = symbolMapToStringMap(map); | 34 map = symbolMapToStringMap(map); |
35 Expect.equals(res, Function.apply(func, null, map)); | 35 Expect.equals(res, Function.apply(func, null, map)); |
36 Expect.equals(res, Function.apply(func, [], map)); | 36 Expect.equals(res, Function.apply(func, [], map)); |
37 } | 37 } |
| 38 |
38 testList(res, func, list) { | 39 testList(res, func, list) { |
39 Expect.equals(res, Function.apply(func, list)); | 40 Expect.equals(res, Function.apply(func, list)); |
40 Expect.equals(res, Function.apply(func, list, null)); | 41 Expect.equals(res, Function.apply(func, list, null)); |
41 Expect.equals(res, Function.apply(func, list, new Map<Symbol, dynamic>())); | 42 Expect.equals(res, Function.apply(func, list, new Map<Symbol, dynamic>())); |
42 } | 43 } |
| 44 |
43 test(res, func, list, map) { | 45 test(res, func, list, map) { |
44 map = symbolMapToStringMap(map); | 46 map = symbolMapToStringMap(map); |
45 Expect.equals(res, Function.apply(func, list, map)); | 47 Expect.equals(res, Function.apply(func, list, map)); |
46 } | 48 } |
| 49 |
47 testList(42, test0, null); | 50 testList(42, test0, null); |
48 testList(42, test0, []); | 51 testList(42, test0, []); |
49 testMap(42, test0a, {"a": 5}); | 52 testMap(42, test0a, {"a": 5}); |
50 testList(42, test1, [41]); | 53 testList(42, test1, [41]); |
51 test(42, test1a, [20], {"a": 22}); | 54 test(42, test1a, [20], {"a": 22}); |
52 testList(42, test2, [20, 22]); | 55 testList(42, test2, [20, 22]); |
53 test(42, test2a, [10, 15], {"a" : 17}); | 56 test(42, test2a, [10, 15], {"a": 17}); |
54 | 57 |
55 // Test that "this" is correct when calling closurized functions. | 58 // Test that "this" is correct when calling closurized functions. |
56 var cfoo = new C().foo; | 59 var cfoo = new C().foo; |
57 testList(42, cfoo, [32]); | 60 testList(42, cfoo, [32]); |
58 | 61 |
59 // Test that apply works even with a different name. | 62 // Test that apply works even with a different name. |
60 var app = confuse(Function.apply); | 63 var app = confuse(Function.apply); |
61 Expect.equals(42, app(test2, [22, 20])); | 64 Expect.equals(42, app(test2, [22, 20])); |
62 | 65 |
63 // Test that apply can itself be applied. | 66 // Test that apply can itself be applied. |
64 Expect.equals(42, Function.apply(Function.apply, [test2, [17, 25]])); | 67 Expect.equals( |
| 68 42, |
| 69 Function.apply(Function.apply, [ |
| 70 test2, |
| 71 [17, 25] |
| 72 ])); |
65 | 73 |
66 // Test that apply works on callable objects. | 74 // Test that apply works on callable objects. |
67 testList(42, new Callable(), [13, 29]); | 75 testList(42, new Callable(), [13, 29]); |
68 } | 76 } |
OLD | NEW |