OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library test.invoke_named_test; | 5 library test.invoke_named_test; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 | 8 |
9 import 'dart:async' show Future; | 9 import 'dart:async' show Future; |
10 | 10 |
11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
12 import 'invoke_test.dart'; | 12 import 'invoke_test.dart'; |
13 | 13 |
14 // TODO(ahe): Remove this variable (http://dartbug.com/12863). | 14 // TODO(ahe): Remove this variable (http://dartbug.com/12863). |
15 bool isDart2js = false; | 15 bool isDart2js = false; |
16 | 16 |
17 class C { | 17 class C { |
18 a(a, {b: 'B', c}) => "$a-$b-$c"; | 18 a(a, {b:'B', c}) => "$a-$b-$c"; |
19 b({a: 'A', b, c}) => "$a-$b-$c"; | 19 b({a:'A', b, c}) => "$a-$b-$c"; |
20 c(a, [b, c = 'C']) => "$a-$b-$c"; | 20 c(a, [b, c='C']) => "$a-$b-$c"; |
21 d([a, b = 'B', c = 'C']) => "$a-$b-$c"; | 21 d([a, b='B', c='C']) => "$a-$b-$c"; |
22 e(a, b, c) => "$a-$b-$c"; | 22 e(a, b, c) => "$a-$b-$c"; |
23 } | 23 } |
24 | 24 |
25 class D { | 25 class D { |
26 static a(a, {b: 'B', c}) => "$a-$b-$c"; | 26 static a(a, {b:'B', c}) => "$a-$b-$c"; |
27 static b({a: 'A', b, c}) => "$a-$b-$c"; | 27 static b({a:'A', b, c}) => "$a-$b-$c"; |
28 static c(a, [b, c = 'C']) => "$a-$b-$c"; | 28 static c(a, [b, c='C']) => "$a-$b-$c"; |
29 static d([a, b = 'B', c = 'C']) => "$a-$b-$c"; | 29 static d([a, b='B', c='C']) => "$a-$b-$c"; |
30 static e(a, b, c) => "$a-$b-$c"; | 30 static e(a, b, c) => "$a-$b-$c"; |
31 } | 31 } |
32 | 32 |
33 class E { | 33 class E { |
34 var field; | 34 var field; |
35 E(a, {b: 'B', c}) : this.field = "$a-$b-$c"; | 35 E(a, {b:'B', c}) : this.field = "$a-$b-$c"; |
36 E.b({a: 'A', b, c}) : this.field = "$a-$b-$c"; | 36 E.b({a:'A', b, c}) : this.field = "$a-$b-$c"; |
37 E.c(a, [b, c = 'C']) : this.field = "$a-$b-$c"; | 37 E.c(a, [b, c='C']) : this.field = "$a-$b-$c"; |
38 E.d([a, b = 'B', c = 'C']) : this.field = "$a-$b-$c"; | 38 E.d([a, b='B', c='C']) : this.field = "$a-$b-$c"; |
39 E.e(a, b, c) : this.field = "$a-$b-$c"; | 39 E.e(a, b, c) : this.field = "$a-$b-$c"; |
40 } | 40 } |
41 | 41 |
42 a(a, {b: 'B', c}) => "$a-$b-$c"; | 42 a(a, {b:'B', c}) => "$a-$b-$c"; |
43 b({a: 'A', b, c}) => "$a-$b-$c"; | 43 b({a:'A', b, c}) => "$a-$b-$c"; |
44 c(a, [b, c = 'C']) => "$a-$b-$c"; | 44 c(a, [b, c='C']) => "$a-$b-$c"; |
45 d([a, b = 'B', c = 'C']) => "$a-$b-$c"; | 45 d([a, b='B', c='C']) => "$a-$b-$c"; |
46 e(a, b, c) => "$a-$b-$c"; | 46 e(a, b, c) => "$a-$b-$c"; |
47 | 47 |
48 testSyncInvoke(ObjectMirror om) { | 48 testSyncInvoke(ObjectMirror om) { |
49 InstanceMirror result; | 49 InstanceMirror result; |
50 | 50 |
51 result = om.invoke(const Symbol('a'), ['X']); | 51 result = om.invoke(const Symbol('a'), ['X']); |
52 Expect.equals('X-B-null', result.reflectee); | 52 Expect.equals('X-B-null', result.reflectee); |
53 result = om.invoke(const Symbol('a'), ['X'], {const Symbol('b'): 'Y'}); | 53 result = om.invoke(const Symbol('a'), ['X'], {const Symbol('b') : 'Y'}); |
54 Expect.equals('X-Y-null', result.reflectee); | 54 Expect.equals('X-Y-null', result.reflectee); |
55 result = om.invoke(const Symbol('a'), ['X'], | 55 result = om.invoke(const Symbol('a'), ['X'], {const Symbol('c') : 'Z', const S
ymbol('b') : 'Y'}); |
56 {const Symbol('c'): 'Z', const Symbol('b'): 'Y'}); | |
57 Expect.equals('X-Y-Z', result.reflectee); | 56 Expect.equals('X-Y-Z', result.reflectee); |
58 Expect.throws(() => om.invoke(const Symbol('a'), []), isNoSuchMethodError, | 57 Expect.throws(() => om.invoke(const Symbol('a'), []), |
59 'Insufficient positional arguments'); | 58 isNoSuchMethodError, |
| 59 'Insufficient positional arguments'); |
60 Expect.throws(() => om.invoke(const Symbol('a'), ['X', 'Y']), | 60 Expect.throws(() => om.invoke(const Symbol('a'), ['X', 'Y']), |
61 isNoSuchMethodError, 'Extra positional arguments'); | 61 isNoSuchMethodError, |
62 Expect.throws( | 62 'Extra positional arguments'); |
63 () => om.invoke(const Symbol('a'), ['X'], {const Symbol('undef'): 'Y'}), | 63 Expect.throws(() => om.invoke(const Symbol('a'), ['X'], {const Symbol('undef')
: 'Y'}), |
64 isNoSuchMethodError, | 64 isNoSuchMethodError, |
65 'Unmatched named argument'); | 65 'Unmatched named argument'); |
66 | 66 |
67 result = om.invoke(const Symbol('b'), []); | 67 result = om.invoke(const Symbol('b'), []); |
68 Expect.equals('A-null-null', result.reflectee); | 68 Expect.equals('A-null-null', result.reflectee); |
69 result = om.invoke(const Symbol('b'), [], {const Symbol('a'): 'X'}); | 69 result = om.invoke(const Symbol('b'), [], {const Symbol('a') : 'X'}); |
70 Expect.equals('X-null-null', result.reflectee); | 70 Expect.equals('X-null-null', result.reflectee); |
71 result = om.invoke(const Symbol('b'), [], | 71 result = om.invoke(const Symbol('b'), [], {const Symbol('b') :'Y', const Symbo
l('c') :'Z', const Symbol('a') :'X'}); |
72 {const Symbol('b'): 'Y', const Symbol('c'): 'Z', const Symbol('a'): 'X'}); | |
73 Expect.equals('X-Y-Z', result.reflectee); | 72 Expect.equals('X-Y-Z', result.reflectee); |
74 Expect.throws(() => om.invoke(const Symbol('b'), ['X']), isNoSuchMethodError, | 73 Expect.throws(() => om.invoke(const Symbol('b'), ['X']), |
75 'Extra positional arguments'); | 74 isNoSuchMethodError, |
76 Expect.throws( | 75 'Extra positional arguments'); |
77 () => om.invoke(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'}), | 76 Expect.throws(() => om.invoke(const Symbol('b'), ['X'], {const Symbol('undef')
: 'Y'}), |
78 isNoSuchMethodError, | 77 isNoSuchMethodError, |
79 'Unmatched named argument'); | 78 'Unmatched named argument'); |
80 | 79 |
81 result = om.invoke(const Symbol('c'), ['X']); | 80 result = om.invoke(const Symbol('c'), ['X']); |
82 Expect.equals('X-null-C', result.reflectee); | 81 Expect.equals('X-null-C', result.reflectee); |
83 result = om.invoke(const Symbol('c'), ['X', 'Y']); | 82 result = om.invoke(const Symbol('c'), ['X', 'Y']); |
84 Expect.equals('X-Y-C', result.reflectee); | 83 Expect.equals('X-Y-C', result.reflectee); |
85 result = om.invoke(const Symbol('c'), ['X', 'Y', 'Z']); | 84 result = om.invoke(const Symbol('c'), ['X', 'Y', 'Z']); |
86 Expect.equals('X-Y-Z', result.reflectee); | 85 Expect.equals('X-Y-Z', result.reflectee); |
87 Expect.throws(() => om.invoke(const Symbol('c'), []), isNoSuchMethodError, | 86 Expect.throws(() => om.invoke(const Symbol('c'), []), |
88 'Insufficient positional arguments'); | 87 isNoSuchMethodError, |
| 88 'Insufficient positional arguments'); |
89 Expect.throws(() => om.invoke(const Symbol('c'), ['X', 'Y', 'Z', 'W']), | 89 Expect.throws(() => om.invoke(const Symbol('c'), ['X', 'Y', 'Z', 'W']), |
90 isNoSuchMethodError, 'Extra positional arguments'); | 90 isNoSuchMethodError, |
91 Expect.throws( | 91 'Extra positional arguments'); |
92 () => om.invoke(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'}), | 92 Expect.throws(() => om.invoke(const Symbol('c'), ['X'], {const Symbol('undef')
: 'Y'}), |
93 isNoSuchMethodError, | 93 isNoSuchMethodError, |
94 'Unmatched named argument'); | 94 'Unmatched named argument'); |
95 | 95 |
96 result = om.invoke(const Symbol('d'), []); | 96 result = om.invoke(const Symbol('d'), []); |
97 Expect.equals('null-B-C', result.reflectee); | 97 Expect.equals('null-B-C', result.reflectee); |
98 result = om.invoke(const Symbol('d'), ['X']); | 98 result = om.invoke(const Symbol('d'), ['X']); |
99 Expect.equals('X-B-C', result.reflectee); | 99 Expect.equals('X-B-C', result.reflectee); |
100 result = om.invoke(const Symbol('d'), ['X', 'Y']); | 100 result = om.invoke(const Symbol('d'), ['X', 'Y']); |
101 Expect.equals('X-Y-C', result.reflectee); | 101 Expect.equals('X-Y-C', result.reflectee); |
102 result = om.invoke(const Symbol('d'), ['X', 'Y', 'Z']); | 102 result = om.invoke(const Symbol('d'), ['X', 'Y', 'Z']); |
103 Expect.equals('X-Y-Z', result.reflectee); | 103 Expect.equals('X-Y-Z', result.reflectee); |
104 Expect.throws(() => om.invoke(const Symbol('d'), ['X', 'Y', 'Z', 'W']), | 104 Expect.throws(() => om.invoke(const Symbol('d'), ['X', 'Y', 'Z', 'W']), |
105 isNoSuchMethodError, 'Extra positional arguments'); | 105 isNoSuchMethodError, |
106 Expect.throws( | 106 'Extra positional arguments'); |
107 () => om.invoke(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'}), | 107 Expect.throws(() => om.invoke(const Symbol('d'), ['X'], {const Symbol('undef')
: 'Y'}), |
108 isNoSuchMethodError, | 108 isNoSuchMethodError, |
109 'Unmatched named argument'); | 109 'Unmatched named argument'); |
110 | 110 |
111 result = om.invoke(const Symbol('e'), ['X', 'Y', 'Z']); | 111 result = om.invoke(const Symbol('e'), ['X', 'Y', 'Z']); |
112 Expect.equals('X-Y-Z', result.reflectee); | 112 Expect.equals('X-Y-Z', result.reflectee); |
113 Expect.throws(() => om.invoke(const Symbol('e'), ['X']), isNoSuchMethodError, | 113 Expect.throws(() => om.invoke(const Symbol('e'), ['X']), |
114 'Insufficient positional arguments'); | 114 isNoSuchMethodError, |
| 115 'Insufficient positional arguments'); |
115 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']), | 116 Expect.throws(() => om.invoke(const Symbol('e'), ['X', 'Y', 'Z', 'W']), |
116 isNoSuchMethodError, 'Extra positional arguments'); | 117 isNoSuchMethodError, |
117 Expect.throws( | 118 'Extra positional arguments'); |
118 () => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'}), | 119 Expect.throws(() => om.invoke(const Symbol('e'), ['X'], {const Symbol('undef')
: 'Y'}), |
119 isNoSuchMethodError, | 120 isNoSuchMethodError, |
120 'Unmatched named argument'); | 121 'Unmatched named argument'); |
121 } | 122 } |
122 | 123 |
123 testSyncNewInstance() { | 124 testSyncNewInstance() { |
124 ClassMirror cm = reflectClass(E); | 125 ClassMirror cm = reflectClass(E); |
125 InstanceMirror result; | 126 InstanceMirror result; |
126 | 127 |
127 result = cm.newInstance(const Symbol(''), ['X']); | 128 result = cm.newInstance(const Symbol(''), ['X']); |
128 Expect.equals('X-B-null', result.reflectee.field); | 129 Expect.equals('X-B-null', result.reflectee.field); |
129 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b'): 'Y'}); | 130 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('b') : 'Y'}); |
130 Expect.equals('X-Y-null', result.reflectee.field); | 131 Expect.equals('X-Y-null', result.reflectee.field); |
131 result = cm.newInstance(const Symbol(''), ['X'], | 132 result = cm.newInstance(const Symbol(''), ['X'], {const Symbol('c') : 'Z', con
st Symbol('b') : 'Y'}); |
132 {const Symbol('c'): 'Z', const Symbol('b'): 'Y'}); | |
133 Expect.equals('X-Y-Z', result.reflectee.field); | 133 Expect.equals('X-Y-Z', result.reflectee.field); |
134 Expect.throws(() => cm.newInstance(const Symbol(''), []), isNoSuchMethodError, | 134 Expect.throws(() => cm.newInstance(const Symbol(''), []), |
135 'Insufficient positional arguments'); | 135 isNoSuchMethodError, |
| 136 'Insufficient positional arguments'); |
136 Expect.throws(() => cm.newInstance(const Symbol(''), ['X', 'Y']), | 137 Expect.throws(() => cm.newInstance(const Symbol(''), ['X', 'Y']), |
137 isNoSuchMethodError, 'Extra positional arguments'); | 138 isNoSuchMethodError, |
138 Expect.throws( | 139 'Extra positional arguments'); |
139 () => | 140 Expect.throws(() => cm.newInstance(const Symbol(''), ['X'], {const Symbol('und
ef') : 'Y'}), |
140 cm.newInstance(const Symbol(''), ['X'], {const Symbol('undef'): 'Y'}), | 141 isNoSuchMethodError, |
141 isNoSuchMethodError, | 142 'Unmatched named argument'); |
142 'Unmatched named argument'); | |
143 | 143 |
144 result = cm.newInstance(const Symbol('b'), []); | 144 result = cm.newInstance(const Symbol('b'), []); |
145 Expect.equals('A-null-null', result.reflectee.field); | 145 Expect.equals('A-null-null', result.reflectee.field); |
146 result = cm.newInstance(const Symbol('b'), [], {const Symbol('a'): 'X'}); | 146 result = cm.newInstance(const Symbol('b'), [], {const Symbol('a') : 'X'}); |
147 Expect.equals('X-null-null', result.reflectee.field); | 147 Expect.equals('X-null-null', result.reflectee.field); |
148 result = cm.newInstance(const Symbol('b'), [], | 148 result = cm.newInstance(const Symbol('b'), [], {const Symbol('b') :'Y', const
Symbol('c') :'Z', const Symbol('a') :'X'}); |
149 {const Symbol('b'): 'Y', const Symbol('c'): 'Z', const Symbol('a'): 'X'}); | |
150 Expect.equals('X-Y-Z', result.reflectee.field); | 149 Expect.equals('X-Y-Z', result.reflectee.field); |
151 Expect.throws(() => cm.newInstance(const Symbol('b'), ['X']), | 150 Expect.throws(() => cm.newInstance(const Symbol('b'), ['X']), |
152 isNoSuchMethodError, 'Extra positional arguments'); | 151 isNoSuchMethodError, |
153 Expect.throws( | 152 'Extra positional arguments'); |
154 () => cm | 153 Expect.throws(() => cm.newInstance(const Symbol('b'), ['X'], {const Symbol('un
def'): 'Y'}), |
155 .newInstance(const Symbol('b'), ['X'], {const Symbol('undef'): 'Y'}), | 154 isNoSuchMethodError, |
156 isNoSuchMethodError, | 155 'Unmatched named argument'); |
157 'Unmatched named argument'); | |
158 | 156 |
159 result = cm.newInstance(const Symbol('c'), ['X']); | 157 result = cm.newInstance(const Symbol('c'), ['X']); |
160 Expect.equals('X-null-C', result.reflectee.field); | 158 Expect.equals('X-null-C', result.reflectee.field); |
161 result = cm.newInstance(const Symbol('c'), ['X', 'Y']); | 159 result = cm.newInstance(const Symbol('c'), ['X', 'Y']); |
162 Expect.equals('X-Y-C', result.reflectee.field); | 160 Expect.equals('X-Y-C', result.reflectee.field); |
163 result = cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z']); | 161 result = cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z']); |
164 Expect.equals('X-Y-Z', result.reflectee.field); | 162 Expect.equals('X-Y-Z', result.reflectee.field); |
165 Expect.throws(() => cm.newInstance(const Symbol('c'), []), | 163 Expect.throws(() => cm.newInstance(const Symbol('c'), []), |
166 isNoSuchMethodError, 'Insufficient positional arguments'); | 164 isNoSuchMethodError, |
| 165 'Insufficient positional arguments'); |
167 Expect.throws(() => cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z', 'W']), | 166 Expect.throws(() => cm.newInstance(const Symbol('c'), ['X', 'Y', 'Z', 'W']), |
168 isNoSuchMethodError, 'Extra positional arguments'); | 167 isNoSuchMethodError, |
169 Expect.throws( | 168 'Extra positional arguments'); |
170 () => cm | 169 Expect.throws(() => cm.newInstance(const Symbol('c'), ['X'], {const Symbol('un
def'): 'Y'}), |
171 .newInstance(const Symbol('c'), ['X'], {const Symbol('undef'): 'Y'}), | 170 isNoSuchMethodError, |
172 isNoSuchMethodError, | 171 'Unmatched named argument'); |
173 'Unmatched named argument'); | |
174 | 172 |
175 result = cm.newInstance(const Symbol('d'), []); | 173 result = cm.newInstance(const Symbol('d'), []); |
176 Expect.equals('null-B-C', result.reflectee.field); | 174 Expect.equals('null-B-C', result.reflectee.field); |
177 result = cm.newInstance(const Symbol('d'), ['X']); | 175 result = cm.newInstance(const Symbol('d'), ['X']); |
178 Expect.equals('X-B-C', result.reflectee.field); | 176 Expect.equals('X-B-C', result.reflectee.field); |
179 result = cm.newInstance(const Symbol('d'), ['X', 'Y']); | 177 result = cm.newInstance(const Symbol('d'), ['X', 'Y']); |
180 Expect.equals('X-Y-C', result.reflectee.field); | 178 Expect.equals('X-Y-C', result.reflectee.field); |
181 result = cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z']); | 179 result = cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z']); |
182 Expect.equals('X-Y-Z', result.reflectee.field); | 180 Expect.equals('X-Y-Z', result.reflectee.field); |
183 Expect.throws(() => cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z', 'W']), | 181 Expect.throws(() => cm.newInstance(const Symbol('d'), ['X', 'Y', 'Z', 'W']), |
184 isNoSuchMethodError, 'Extra positional arguments'); | 182 isNoSuchMethodError, |
185 Expect.throws( | 183 'Extra positional arguments'); |
186 () => cm | 184 Expect.throws(() => cm.newInstance(const Symbol('d'), ['X'], {const Symbol('un
def'): 'Y'}), |
187 .newInstance(const Symbol('d'), ['X'], {const Symbol('undef'): 'Y'}), | 185 isNoSuchMethodError, |
188 isNoSuchMethodError, | 186 'Unmatched named argument'); |
189 'Unmatched named argument'); | |
190 | 187 |
191 result = cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z']); | 188 result = cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z']); |
192 Expect.equals('X-Y-Z', result.reflectee.field); | 189 Expect.equals('X-Y-Z', result.reflectee.field); |
193 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X']), | 190 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X']), |
194 isNoSuchMethodError, 'Insufficient positional arguments'); | 191 isNoSuchMethodError, |
| 192 'Insufficient positional arguments'); |
195 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']), | 193 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X', 'Y', 'Z', 'W']), |
196 isNoSuchMethodError, 'Extra positional arguments'); | 194 isNoSuchMethodError, |
197 Expect.throws( | 195 'Extra positional arguments'); |
198 () => cm | 196 Expect.throws(() => cm.newInstance(const Symbol('e'), ['X'], {const Symbol('un
def'): 'Y'}), |
199 .newInstance(const Symbol('e'), ['X'], {const Symbol('undef'): 'Y'}), | 197 isNoSuchMethodError, |
200 isNoSuchMethodError, | 198 'Unmatched named argument'); |
201 'Unmatched named argument'); | |
202 } | 199 } |
203 | 200 |
204 testSyncApply() { | 201 testSyncApply() { |
205 ClosureMirror cm; | 202 ClosureMirror cm; |
206 InstanceMirror result; | 203 InstanceMirror result; |
207 | 204 |
208 cm = reflect(a); | 205 cm = reflect(a); |
209 result = cm.apply(['X']); | 206 result = cm.apply(['X']); |
210 Expect.equals('X-B-null', result.reflectee); | 207 Expect.equals('X-B-null', result.reflectee); |
211 result = cm.apply(['X'], {const Symbol('b'): 'Y'}); | 208 result = cm.apply(['X'], {const Symbol('b') : 'Y'}); |
212 Expect.equals('X-Y-null', result.reflectee); | 209 Expect.equals('X-Y-null', result.reflectee); |
213 result = cm.apply(['X'], {const Symbol('c'): 'Z', const Symbol('b'): 'Y'}); | 210 result = cm.apply(['X'], {const Symbol('c') : 'Z', const Symbol('b') : 'Y'}); |
214 Expect.equals('X-Y-Z', result.reflectee); | 211 Expect.equals('X-Y-Z', result.reflectee); |
215 Expect.throws(() => cm.apply([]), isNoSuchMethodError, | 212 Expect.throws(() => cm.apply([]), |
216 'Insufficient positional arguments'); | 213 isNoSuchMethodError, |
217 Expect.throws(() => cm.apply(['X', 'Y']), isNoSuchMethodError, | 214 'Insufficient positional arguments'); |
218 'Extra positional arguments'); | 215 Expect.throws(() => cm.apply(['X', 'Y']), |
219 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), | 216 isNoSuchMethodError, |
220 isNoSuchMethodError, 'Unmatched named argument'); | 217 'Extra positional arguments'); |
| 218 Expect.throws(() => cm.apply(['X'], {const Symbol('undef') : 'Y'}), |
| 219 isNoSuchMethodError, |
| 220 'Unmatched named argument'); |
221 | 221 |
222 cm = reflect(b); | 222 cm = reflect(b); |
223 result = cm.apply([]); | 223 result = cm.apply([]); |
224 Expect.equals('A-null-null', result.reflectee); | 224 Expect.equals('A-null-null', result.reflectee); |
225 result = cm.apply([], {const Symbol('a'): 'X'}); | 225 result = cm.apply([], {const Symbol('a') : 'X'}); |
226 Expect.equals('X-null-null', result.reflectee); | 226 Expect.equals('X-null-null', result.reflectee); |
227 result = cm.apply([], | 227 result = cm.apply([], {const Symbol('b') :'Y', const Symbol('c') :'Z', const S
ymbol('a') :'X'}); |
228 {const Symbol('b'): 'Y', const Symbol('c'): 'Z', const Symbol('a'): 'X'}); | |
229 Expect.equals('X-Y-Z', result.reflectee); | 228 Expect.equals('X-Y-Z', result.reflectee); |
230 Expect.throws( | 229 Expect.throws(() => cm.apply(['X']), |
231 () => cm.apply(['X']), isNoSuchMethodError, 'Extra positional arguments'); | 230 isNoSuchMethodError, |
| 231 'Extra positional arguments'); |
232 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), | 232 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), |
233 isNoSuchMethodError, 'Unmatched named argument'); | 233 isNoSuchMethodError, |
| 234 'Unmatched named argument'); |
234 | 235 |
235 cm = reflect(c); | 236 cm = reflect(c); |
236 result = cm.apply(['X']); | 237 result = cm.apply(['X']); |
237 Expect.equals('X-null-C', result.reflectee); | 238 Expect.equals('X-null-C', result.reflectee); |
238 result = cm.apply(['X', 'Y']); | 239 result = cm.apply(['X', 'Y']); |
239 Expect.equals('X-Y-C', result.reflectee); | 240 Expect.equals('X-Y-C', result.reflectee); |
240 result = cm.apply(['X', 'Y', 'Z']); | 241 result = cm.apply(['X', 'Y', 'Z']); |
241 Expect.equals('X-Y-Z', result.reflectee); | 242 Expect.equals('X-Y-Z', result.reflectee); |
242 Expect.throws(() => cm.apply([]), isNoSuchMethodError, | 243 Expect.throws(() => cm.apply([]), |
243 'Insufficient positional arguments'); | 244 isNoSuchMethodError, |
244 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), isNoSuchMethodError, | 245 'Insufficient positional arguments'); |
245 'Extra positional arguments'); | 246 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), |
| 247 isNoSuchMethodError, |
| 248 'Extra positional arguments'); |
246 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), | 249 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), |
247 isNoSuchMethodError, 'Unmatched named argument'); | 250 isNoSuchMethodError, |
| 251 'Unmatched named argument'); |
248 | 252 |
249 cm = reflect(d); | 253 cm = reflect(d); |
250 result = cm.apply([]); | 254 result = cm.apply([]); |
251 Expect.equals('null-B-C', result.reflectee); | 255 Expect.equals('null-B-C', result.reflectee); |
252 result = cm.apply(['X']); | 256 result = cm.apply(['X']); |
253 Expect.equals('X-B-C', result.reflectee); | 257 Expect.equals('X-B-C', result.reflectee); |
254 result = cm.apply(['X', 'Y']); | 258 result = cm.apply(['X', 'Y']); |
255 Expect.equals('X-Y-C', result.reflectee); | 259 Expect.equals('X-Y-C', result.reflectee); |
256 result = cm.apply(['X', 'Y', 'Z']); | 260 result = cm.apply(['X', 'Y', 'Z']); |
257 Expect.equals('X-Y-Z', result.reflectee); | 261 Expect.equals('X-Y-Z', result.reflectee); |
258 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), isNoSuchMethodError, | 262 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), |
259 'Extra positional arguments'); | 263 isNoSuchMethodError, |
| 264 'Extra positional arguments'); |
260 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), | 265 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), |
261 isNoSuchMethodError, 'Unmatched named argument'); | 266 isNoSuchMethodError, |
| 267 'Unmatched named argument'); |
262 | 268 |
263 cm = reflect(e); | 269 cm = reflect(e); |
264 result = cm.apply(['X', 'Y', 'Z']); | 270 result = cm.apply(['X', 'Y', 'Z']); |
265 Expect.equals('X-Y-Z', result.reflectee); | 271 Expect.equals('X-Y-Z', result.reflectee); |
266 Expect.throws(() => cm.apply(['X']), isNoSuchMethodError, | 272 Expect.throws(() => cm.apply(['X']), |
267 'Insufficient positional arguments'); | 273 isNoSuchMethodError, |
268 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), isNoSuchMethodError, | 274 'Insufficient positional arguments'); |
269 'Extra positional arguments'); | 275 Expect.throws(() => cm.apply(['X', 'Y', 'Z', 'W']), |
| 276 isNoSuchMethodError, |
| 277 'Extra positional arguments'); |
270 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), | 278 Expect.throws(() => cm.apply(['X'], {const Symbol('undef'): 'Y'}), |
271 isNoSuchMethodError, 'Unmatched named argument'); | 279 isNoSuchMethodError, |
| 280 'Unmatched named argument'); |
272 } | 281 } |
273 | 282 |
274 main() { | 283 main() { |
275 isDart2js = true; //# 01: ok | 284 isDart2js = true; //# 01: ok |
276 | 285 |
277 testSyncInvoke(reflect(new C())); // InstanceMirror | 286 testSyncInvoke(reflect(new C())); // InstanceMirror |
278 | 287 |
279 if (isDart2js) return; | 288 if (isDart2js) return; |
280 | 289 |
281 testSyncInvoke(reflectClass(D)); // ClassMirror | 290 testSyncInvoke(reflectClass(D)); // ClassMirror |
282 LibraryMirror lib = reflectClass(D).owner; | 291 LibraryMirror lib = reflectClass(D).owner; |
283 testSyncInvoke(lib); // LibraryMirror | 292 testSyncInvoke(lib); // LibraryMirror |
284 | 293 |
285 testSyncNewInstance(); | 294 testSyncNewInstance(); |
286 | 295 |
287 testSyncApply(); | 296 testSyncApply(); |
288 } | 297 } |
OLD | NEW |