| 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 // Testing Function.apply calls correctly. | 5 // Testing Function.apply calls correctly. |
| 6 // This test is not testing error handling, only that correct parameters | 6 // This test is not testing error handling, only that correct parameters |
| 7 // cause a correct call. | 7 // cause a correct call. |
| 8 | 8 |
| 9 int test0() => 42; | 9 int test0() => 42; |
| 10 int test0a({int a}) => 37 + a; | 10 int test0a({int a}) => 37 + a; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 testList(res, func, list) { | 42 testList(res, func, list) { |
| 43 Expect.equals(res, Function.apply(func, list)); | 43 Expect.equals(res, Function.apply(func, list)); |
| 44 Expect.equals(res, Function.apply(func, list, null)); | 44 Expect.equals(res, Function.apply(func, list, null)); |
| 45 Expect.equals(res, Function.apply(func, list, {})); | 45 Expect.equals(res, Function.apply(func, list, {})); |
| 46 } | 46 } |
| 47 test(res, func, list, map) { | 47 test(res, func, list, map) { |
| 48 Expect.equals(res, Function.apply(func, list, map)); | 48 Expect.equals(res, Function.apply(func, list, map)); |
| 49 } | 49 } |
| 50 testList(42, test0, null); | 50 testList(42, test0, null); |
| 51 testList(42, test0, []]); | 51 testList(42, test0, []); |
| 52 testMap(42, test0a, {"a": 5}); | 52 testMap(42, test0a, {"a": 5}); |
| 53 testList(42, test1, [41]); | 53 testList(42, test1, [41]); |
| 54 test(42, test1a, [20], {"a": 22}); | 54 test(42, test1a, [20], {"a": 22}); |
| 55 testList(42, test2, [20, 22]); | 55 testList(42, test2, [20, 22]); |
| 56 test(42, test2a, [10, 15], {"a" : 17}); | 56 test(42, test2a, [10, 15], {"a" : 17}); |
| 57 | 57 |
| 58 testList(false, testPassed1, null); | 58 testList(false, testPassed1, null); |
| 59 testList(false, testPassed1, []); | 59 testList(false, testPassed1, []); |
| 60 testList(true, testPassed1, [42]); | 60 testList(true, testPassed1, [42]); |
| 61 | 61 |
| 62 testMap(false, testPassedX, null); | 62 testMap(false, testPassedX, null); |
| 63 testMap(false, testPassedX, {}); | 63 testMap(false, testPassedX, {}); |
| 64 testMap(true, testPassedX, {"x": 42}); | 64 testMap(true, testPassedX, {"x": 42}); |
| 65 | 65 |
| 66 // Test that "this" is correct when calling closurized functions. | 66 // Test that "this" is correct when calling closurized functions. |
| 67 var cfoo = new C().foo; | 67 var cfoo = new C().foo; |
| 68 testList(42, cfoo, [32]); | 68 testList(42, cfoo, [32]); |
| 69 | 69 |
| 70 // Test that apply works even with a different name. | 70 // Test that apply works even with a different name. |
| 71 var app = confuse(); | 71 var app = confuse(); |
| 72 Expect.equals(42, app(test2, [22, 20])); | 72 Expect.equals(42, app(test2, [22, 20])); |
| 73 | 73 |
| 74 // Test that apply can itself be applied. | 74 // Test that apply can itself be applied. |
| 75 Expect.equals(42, Function.apply(Function.apply, [test2, [17, 25]])); | 75 Expect.equals(42, Function.apply(Function.apply, [test2, [17, 25]])); |
| 76 | 76 |
| 77 // Test that apply works on callable objects. | 77 // Test that apply works on callable objects. |
| 78 testList(42, new Callable(), [13, 29]); | 78 testList(42, new Callable(), [13, 29]); |
| 79 } | 79 } |
| OLD | NEW |