OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 | |
7 apply(Function function, List positional, Map<Symbol, dynamic> named) { | |
8 return Function.apply(function, positional, named); | |
9 } | |
10 | |
11 void throwsNSME(function, positional, named) { | |
12 Expect.throws( | |
13 () => apply(function, positional, named), (e) => e is NoSuchMethodError); | |
14 } | |
15 | |
16 main() { | |
17 var c1 = () => 'c1'; | |
18 var c2 = (a) => 'c2 $a'; | |
19 var c3 = ([a = 1]) => 'c3 $a'; | |
20 var c4 = ({a: 1}) => 'c4 $a'; | |
21 var c5 = ({a: 1, b: 2}) => 'c5 $a $b'; | |
22 var c6 = ({b: 1, a: 2}) => 'c6 $a $b'; | |
23 var c7 = (x, {b: 1, a: 2}) => 'c7 $x $a $b'; | |
24 var c8 = (x, y, [a = 2, b = 3]) => 'c8 $x $y $a $b'; | |
25 | |
26 Expect.equals('c1', apply(c1, null, null)); | |
27 Expect.equals('c1', apply(c1, [], null)); | |
28 Expect.equals('c1', apply(c1, [], {})); | |
29 Expect.equals('c1', apply(c1, null, {})); | |
30 throwsNSME(c1, [1], null); | |
31 throwsNSME(c1, [1], {#a: 2}); | |
32 throwsNSME(c1, null, {#a: 2}); | |
33 | |
34 Expect.equals('c2 1', apply(c2, [1], null)); | |
35 Expect.equals('c2 1', apply(c2, [1], {})); | |
36 throwsNSME(c2, null, null); | |
37 throwsNSME(c2, [], null); | |
38 throwsNSME(c2, null, {}); | |
39 throwsNSME(c2, null, {#a: 1}); | |
40 throwsNSME(c2, [2], {#a: 1}); | |
41 | |
42 Expect.equals('c3 1', apply(c3, null, null)); | |
43 Expect.equals('c3 1', apply(c3, [], null)); | |
44 Expect.equals('c3 2', apply(c3, [2], {})); | |
45 throwsNSME(c3, [1, 2], null); | |
46 throwsNSME(c3, null, {#a: 1}); | |
47 | |
48 Expect.equals('c4 1', apply(c4, [], null)); | |
49 Expect.equals('c4 2', apply(c4, [], {#a: 2})); | |
50 Expect.equals('c4 1', apply(c4, null, null)); | |
51 Expect.equals('c4 1', apply(c4, [], {})); | |
52 throwsNSME(c4, [1], {#a: 1}); | |
53 throwsNSME(c4, [1], {}); | |
54 throwsNSME(c4, [], {#a: 1, #b: 2}); | |
55 | |
56 Expect.equals('c5 1 2', apply(c5, [], null)); | |
57 Expect.equals('c5 3 2', apply(c5, [], {#a: 3})); | |
58 Expect.equals('c5 1 2', apply(c5, null, null)); | |
59 Expect.equals('c5 1 2', apply(c5, [], {})); | |
60 Expect.equals('c5 3 4', apply(c5, [], {#a: 3, #b: 4})); | |
61 Expect.equals('c5 4 3', apply(c5, [], {#b: 3, #a: 4})); | |
62 Expect.equals('c5 1 3', apply(c5, [], {#b: 3})); | |
63 throwsNSME(c5, [1], {#a: 1}); | |
64 throwsNSME(c5, [1], {}); | |
65 throwsNSME(c5, [], {#a: 1, #b: 2, #c: 3}); | |
66 | |
67 Expect.equals('c6 2 1', apply(c6, [], null)); | |
68 Expect.equals('c6 3 1', apply(c6, [], {#a: 3})); | |
69 Expect.equals('c6 2 1', apply(c6, null, null)); | |
70 Expect.equals('c6 2 1', apply(c6, [], {})); | |
71 Expect.equals('c6 3 4', apply(c6, [], {#a: 3, #b: 4})); | |
72 Expect.equals('c6 4 3', apply(c6, [], {#b: 3, #a: 4})); | |
73 Expect.equals('c6 2 3', apply(c6, [], {#b: 3})); | |
74 throwsNSME(c6, [1], {#a: 1}); | |
75 throwsNSME(c6, [1], {}); | |
76 throwsNSME(c6, [], {#a: 1, #b: 2, #c: 3}); | |
77 | |
78 Expect.equals('c7 7 2 1', apply(c7, [7], null)); | |
79 Expect.equals('c7 7 3 1', apply(c7, [7], {#a: 3})); | |
80 Expect.equals('c7 7 2 1', apply(c7, [7], {})); | |
81 Expect.equals('c7 7 3 4', apply(c7, [7], {#a: 3, #b: 4})); | |
82 Expect.equals('c7 7 4 3', apply(c7, [7], {#b: 3, #a: 4})); | |
83 Expect.equals('c7 7 2 3', apply(c7, [7], {#b: 3})); | |
84 throwsNSME(c7, [], {#a: 1}); | |
85 throwsNSME(c7, [], {}); | |
86 throwsNSME(c7, [7], {#a: 1, #b: 2, #c: 3}); | |
87 | |
88 Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], null)); | |
89 Expect.equals('c8 7 8 2 3', apply(c8, [7, 8], {})); | |
90 Expect.equals('c8 7 8 3 3', apply(c8, [7, 8, 3], null)); | |
91 Expect.equals('c8 7 8 3 4', apply(c8, [7, 8, 3, 4], null)); | |
92 throwsNSME(c8, [], null); | |
93 throwsNSME(c8, [], {}); | |
94 throwsNSME(c8, [1], null); | |
95 throwsNSME(c8, [7, 8, 9, 10, 11], null); | |
96 } | |
OLD | NEW |