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 // This tests uses the multi-test "ok" feature: | 5 // This tests uses the multi-test "ok" feature: |
6 // none: Desired behaviour, passing on the VM. | 6 // none: Desired behaviour, passing on the VM. |
7 // 01: Trimmed version for dart2js. | 7 // 01: Trimmed version for dart2js. |
8 // | 8 // |
9 // TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par. | 9 // TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par. |
10 | 10 |
11 /** Test of [ParameterMirror]. */ | 11 /** Test of [ParameterMirror]. */ |
12 library test.parameter_test; | 12 library test.parameter_test; |
13 | 13 |
14 @MirrorsUsed(targets: const ['test.parameter_test', 'dart.core.int'], override:
'*') | 14 @MirrorsUsed( |
| 15 targets: const ['test.parameter_test', 'dart.core.int'], override: '*') |
15 import 'dart:mirrors'; | 16 import 'dart:mirrors'; |
16 | 17 |
17 import 'package:expect/expect.dart'; | 18 import 'package:expect/expect.dart'; |
18 import 'stringify.dart'; | 19 import 'stringify.dart'; |
19 | 20 |
20 class B { | 21 class B { |
21 B(); | 22 B(); |
22 B.foo(int x); | 23 B.foo(int x); |
23 B.bar(int z, x); | 24 B.bar(int z, x); |
24 | 25 |
25 // TODO(6490): Currently only supported by the VM. | 26 // TODO(6490): Currently only supported by the VM. |
26 B.baz(final int x, int y, final int z); | 27 B.baz(final int x, int y, final int z); |
27 B.qux(int x, [int y= 3 + 1]); | 28 B.qux(int x, [int y = 3 + 1]); |
28 B.quux(int x, {String str: "foo"}); | 29 B.quux(int x, {String str: "foo"}); |
29 B.corge({int x: 3 * 17, String str: "bar"}); | 30 B.corge({int x: 3 * 17, String str: "bar"}); |
30 | 31 |
31 var _x; | 32 var _x; |
32 get x => _x; | 33 get x => _x; |
33 set x(final value) { _x = value; } | 34 set x(final value) { |
| 35 _x = value; |
| 36 } |
34 | 37 |
35 grault([int x]) {} | 38 grault([int x]) {} |
36 garply({int y}) {} | 39 garply({int y}) {} |
37 waldo(int z) {} | 40 waldo(int z) {} |
38 } | 41 } |
39 | 42 |
40 class C <S extends int, T> { | 43 class C<S extends int, T> { |
41 // TODO(6490): Currently only supported by the VM. | 44 // TODO(6490): Currently only supported by the VM. |
42 foo(int a, S b) => b; | 45 foo(int a, S b) => b; |
43 bar(S a, T b, num c) {} | 46 bar(S a, T b, num c) {} |
44 } | 47 } |
45 | 48 |
46 main() { | 49 main() { |
47 ClassMirror cm = reflectClass(B); | 50 ClassMirror cm = reflectClass(B); |
48 var constructors = new Map<Symbol, MethodMirror>(); | 51 var constructors = new Map<Symbol, MethodMirror>(); |
49 cm.declarations.forEach((k, v) { | 52 cm.declarations.forEach((k, v) { |
50 if (v is MethodMirror && v.isConstructor) constructors[k] = v; | 53 if (v is MethodMirror && v.isConstructor) constructors[k] = v; |
51 }); | 54 }); |
52 | 55 |
53 List<Symbol> constructorKeys = | 56 List<Symbol> constructorKeys = [ |
54 [#B, #B.bar, #B.baz, #B.foo, #B.quux, #B.qux, #B.corge]; | 57 #B, |
| 58 #B.bar, |
| 59 #B.baz, |
| 60 #B.foo, |
| 61 #B.quux, |
| 62 #B.qux, |
| 63 #B.corge |
| 64 ]; |
55 Expect.setEquals(constructorKeys, constructors.keys); | 65 Expect.setEquals(constructorKeys, constructors.keys); |
56 | 66 |
57 MethodMirror unnamedConstructor = constructors[#B]; | 67 MethodMirror unnamedConstructor = constructors[#B]; |
58 expect('Method(s(B) in s(B), constructor)', unnamedConstructor); | 68 expect('Method(s(B) in s(B), constructor)', unnamedConstructor); |
59 expect('[]', unnamedConstructor.parameters); | 69 expect('[]', unnamedConstructor.parameters); |
60 expect('Class(s(B) in s(test.parameter_test), top-level)', | 70 expect('Class(s(B) in s(test.parameter_test), top-level)', |
61 unnamedConstructor.returnType); | 71 unnamedConstructor.returnType); |
62 | 72 |
63 MethodMirror fooConstructor = constructors[#B.foo]; | 73 MethodMirror fooConstructor = constructors[#B.foo]; |
64 expect('Method(s(B.foo) in s(B), constructor)', fooConstructor); | 74 expect('Method(s(B.foo) in s(B), constructor)', fooConstructor); |
65 expect('[Parameter(s(x) in s(B.foo),' | 75 expect( |
66 ' type = Class(s(int) in s(dart.core), top-level))]', | 76 '[Parameter(s(x) in s(B.foo),' |
67 fooConstructor.parameters); | 77 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 78 fooConstructor.parameters); |
68 expect('Class(s(B) in s(test.parameter_test), top-level)', | 79 expect('Class(s(B) in s(test.parameter_test), top-level)', |
69 fooConstructor.returnType); | 80 fooConstructor.returnType); |
70 | 81 |
71 MethodMirror barConstructor = constructors[#B.bar]; | 82 MethodMirror barConstructor = constructors[#B.bar]; |
72 expect('Method(s(B.bar) in s(B), constructor)', barConstructor); | 83 expect('Method(s(B.bar) in s(B), constructor)', barConstructor); |
73 expect('[Parameter(s(z) in s(B.bar),' | 84 expect( |
74 ' type = Class(s(int) in s(dart.core), top-level)), ' | 85 '[Parameter(s(z) in s(B.bar),' |
75 'Parameter(s(x) in s(B.bar),' | 86 ' type = Class(s(int) in s(dart.core), top-level)), ' |
76 ' type = Type(s(dynamic), top-level))]', | 87 'Parameter(s(x) in s(B.bar),' |
77 barConstructor.parameters); | 88 ' type = Type(s(dynamic), top-level))]', |
| 89 barConstructor.parameters); |
78 expect('Class(s(B) in s(test.parameter_test), top-level)', | 90 expect('Class(s(B) in s(test.parameter_test), top-level)', |
79 barConstructor.returnType); | 91 barConstructor.returnType); |
80 | 92 |
81 // dart2js stops testing here. | 93 // dart2js stops testing here. |
82 return; // //# 01: ok | 94 return; // //# 01: ok |
83 | 95 |
84 MethodMirror bazConstructor = constructors[#B.baz]; | 96 MethodMirror bazConstructor = constructors[#B.baz]; |
85 expect('Method(s(B.baz) in s(B), constructor)', bazConstructor); | 97 expect('Method(s(B.baz) in s(B), constructor)', bazConstructor); |
86 expect('[Parameter(s(x) in s(B.baz), final,' | 98 expect( |
87 ' type = Class(s(int) in s(dart.core), top-level)), ' | 99 '[Parameter(s(x) in s(B.baz), final,' |
88 'Parameter(s(y) in s(B.baz),' | 100 ' type = Class(s(int) in s(dart.core), top-level)), ' |
89 ' type = Class(s(int) in s(dart.core), top-level)), ' | 101 'Parameter(s(y) in s(B.baz),' |
90 'Parameter(s(z) in s(B.baz), final,' | 102 ' type = Class(s(int) in s(dart.core), top-level)), ' |
91 ' type = Class(s(int) in s(dart.core), top-level))]', | 103 'Parameter(s(z) in s(B.baz), final,' |
92 bazConstructor.parameters); | 104 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 105 bazConstructor.parameters); |
93 expect('Class(s(B) in s(test.parameter_test), top-level)', | 106 expect('Class(s(B) in s(test.parameter_test), top-level)', |
94 bazConstructor.returnType); | 107 bazConstructor.returnType); |
95 | 108 |
96 MethodMirror quxConstructor = constructors[#B.qux]; | 109 MethodMirror quxConstructor = constructors[#B.qux]; |
97 expect('Method(s(B.qux) in s(B), constructor)', quxConstructor); | 110 expect('Method(s(B.qux) in s(B), constructor)', quxConstructor); |
98 expect('[Parameter(s(x) in s(B.qux),' | 111 expect( |
99 ' type = Class(s(int) in s(dart.core), top-level)), ' | 112 '[Parameter(s(x) in s(B.qux),' |
100 'Parameter(s(y) in s(B.qux), optional,' | 113 ' type = Class(s(int) in s(dart.core), top-level)), ' |
101 ' value = Instance(value = 4),' | 114 'Parameter(s(y) in s(B.qux), optional,' |
102 ' type = Class(s(int) in s(dart.core), top-level))]', | 115 ' value = Instance(value = 4),' |
103 quxConstructor.parameters); | 116 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 117 quxConstructor.parameters); |
104 expect('Class(s(B) in s(test.parameter_test), top-level)', | 118 expect('Class(s(B) in s(test.parameter_test), top-level)', |
105 quxConstructor.returnType); | 119 quxConstructor.returnType); |
106 | 120 |
107 MethodMirror quuxConstructor = constructors[#B.quux]; | 121 MethodMirror quuxConstructor = constructors[#B.quux]; |
108 expect('Method(s(B.quux) in s(B), constructor)', quuxConstructor); | 122 expect('Method(s(B.quux) in s(B), constructor)', quuxConstructor); |
109 expect('[Parameter(s(x) in s(B.quux),' | 123 expect( |
110 ' type = Class(s(int) in s(dart.core), top-level)), ' | 124 '[Parameter(s(x) in s(B.quux),' |
111 'Parameter(s(str) in s(B.quux), optional, named,' | 125 ' type = Class(s(int) in s(dart.core), top-level)), ' |
112 ' value = Instance(value = foo),' | 126 'Parameter(s(str) in s(B.quux), optional, named,' |
113 ' type = Class(s(String) in s(dart.core), top-level))]', | 127 ' value = Instance(value = foo),' |
114 quuxConstructor.parameters); | 128 ' type = Class(s(String) in s(dart.core), top-level))]', |
| 129 quuxConstructor.parameters); |
115 expect('Class(s(B) in s(test.parameter_test), top-level)', | 130 expect('Class(s(B) in s(test.parameter_test), top-level)', |
116 quuxConstructor.returnType); | 131 quuxConstructor.returnType); |
117 | 132 |
118 MethodMirror corgeConstructor = constructors[#B.corge]; | 133 MethodMirror corgeConstructor = constructors[#B.corge]; |
119 expect('Method(s(B.corge) in s(B), constructor)', corgeConstructor); | 134 expect('Method(s(B.corge) in s(B), constructor)', corgeConstructor); |
120 expect('[Parameter(s(x) in s(B.corge), optional, named,' | 135 expect( |
121 ' value = Instance(value = 51),' | 136 '[Parameter(s(x) in s(B.corge), optional, named,' |
122 ' type = Class(s(int) in s(dart.core), top-level)), ' | 137 ' value = Instance(value = 51),' |
123 'Parameter(s(str) in s(B.corge), optional, named,' | 138 ' type = Class(s(int) in s(dart.core), top-level)), ' |
124 ' value = Instance(value = bar),' | 139 'Parameter(s(str) in s(B.corge), optional, named,' |
125 ' type = Class(s(String) in s(dart.core), top-level))]', | 140 ' value = Instance(value = bar),' |
126 corgeConstructor.parameters); | 141 ' type = Class(s(String) in s(dart.core), top-level))]', |
| 142 corgeConstructor.parameters); |
127 expect('Class(s(B) in s(test.parameter_test), top-level)', | 143 expect('Class(s(B) in s(test.parameter_test), top-level)', |
128 corgeConstructor.returnType); | 144 corgeConstructor.returnType); |
129 | 145 |
130 MethodMirror xGetter = cm.declarations[#x]; | 146 MethodMirror xGetter = cm.declarations[#x]; |
131 expect('Method(s(x) in s(B), getter)', xGetter); | 147 expect('Method(s(x) in s(B), getter)', xGetter); |
132 expect('[]', xGetter.parameters); | 148 expect('[]', xGetter.parameters); |
133 | 149 |
134 MethodMirror xSetter = cm.declarations[const Symbol('x=')]; | 150 MethodMirror xSetter = cm.declarations[const Symbol('x=')]; |
135 expect('Method(s(x=) in s(B), setter)', xSetter); | 151 expect('Method(s(x=) in s(B), setter)', xSetter); |
136 expect('[Parameter(s(value) in s(x=), final,' | 152 expect( |
137 ' type = Type(s(dynamic), top-level))]', | 153 '[Parameter(s(value) in s(x=), final,' |
138 xSetter.parameters); | 154 ' type = Type(s(dynamic), top-level))]', |
| 155 xSetter.parameters); |
139 | 156 |
140 MethodMirror grault = cm.declarations[#grault]; | 157 MethodMirror grault = cm.declarations[#grault]; |
141 expect('Method(s(grault) in s(B))', grault); | 158 expect('Method(s(grault) in s(B))', grault); |
142 expect('[Parameter(s(x) in s(grault), optional,' | 159 expect( |
143 ' type = Class(s(int) in s(dart.core), top-level))]', | 160 '[Parameter(s(x) in s(grault), optional,' |
144 grault.parameters); | 161 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 162 grault.parameters); |
145 expect('Instance(value = <null>)', grault.parameters[0].defaultValue); | 163 expect('Instance(value = <null>)', grault.parameters[0].defaultValue); |
146 | 164 |
147 MethodMirror garply = cm.declarations[#garply]; | 165 MethodMirror garply = cm.declarations[#garply]; |
148 expect('Method(s(garply) in s(B))', garply); | 166 expect('Method(s(garply) in s(B))', garply); |
149 expect('[Parameter(s(y) in s(garply), optional, named,' | 167 expect( |
150 ' type = Class(s(int) in s(dart.core), top-level))]', | 168 '[Parameter(s(y) in s(garply), optional, named,' |
151 garply.parameters); | 169 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 170 garply.parameters); |
152 expect('Instance(value = <null>)', garply.parameters[0].defaultValue); | 171 expect('Instance(value = <null>)', garply.parameters[0].defaultValue); |
153 | 172 |
154 MethodMirror waldo = cm.declarations[#waldo]; | 173 MethodMirror waldo = cm.declarations[#waldo]; |
155 expect('Method(s(waldo) in s(B))', waldo); | 174 expect('Method(s(waldo) in s(B))', waldo); |
156 expect('[Parameter(s(z) in s(waldo),' | 175 expect( |
157 ' type = Class(s(int) in s(dart.core), top-level))]', | 176 '[Parameter(s(z) in s(waldo),' |
158 waldo.parameters); | 177 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 178 waldo.parameters); |
159 expect('<null>', waldo.parameters[0].defaultValue); | 179 expect('<null>', waldo.parameters[0].defaultValue); |
160 | 180 |
161 cm = reflectClass(C); | 181 cm = reflectClass(C); |
162 | 182 |
163 MethodMirror fooInC = cm.declarations[#foo]; | 183 MethodMirror fooInC = cm.declarations[#foo]; |
164 expect('Method(s(foo) in s(C))', fooInC); | 184 expect('Method(s(foo) in s(C))', fooInC); |
165 expect('[Parameter(s(a) in s(foo),' | 185 expect( |
166 ' type = Class(s(int) in s(dart.core), top-level)), ' | 186 '[Parameter(s(a) in s(foo),' |
167 'Parameter(s(b) in s(foo),' | 187 ' type = Class(s(int) in s(dart.core), top-level)), ' |
168 ' type = TypeVariable(s(S) in s(C),' | 188 'Parameter(s(b) in s(foo),' |
169 ' upperBound = Class(s(int) in s(dart.core), top-level)))]', | 189 ' type = TypeVariable(s(S) in s(C),' |
170 fooInC.parameters); | 190 ' upperBound = Class(s(int) in s(dart.core), top-level)))]', |
| 191 fooInC.parameters); |
171 | 192 |
172 MethodMirror barInC = cm.declarations[#bar]; | 193 MethodMirror barInC = cm.declarations[#bar]; |
173 expect('Method(s(bar) in s(C))', barInC); | 194 expect('Method(s(bar) in s(C))', barInC); |
174 expect('[Parameter(s(a) in s(bar),' | 195 expect( |
175 ' type = TypeVariable(s(S) in s(C),' | 196 '[Parameter(s(a) in s(bar),' |
176 ' upperBound = Class(s(int) in s(dart.core), top-level))), ' | 197 ' type = TypeVariable(s(S) in s(C),' |
177 'Parameter(s(b) in s(bar),' | 198 ' upperBound = Class(s(int) in s(dart.core), top-level))), ' |
178 ' type = TypeVariable(s(T) in s(C),' | 199 'Parameter(s(b) in s(bar),' |
179 ' upperBound = Class(s(Object) in s(dart.core), top-level))), ' | 200 ' type = TypeVariable(s(T) in s(C),' |
180 'Parameter(s(c) in s(bar),' | 201 ' upperBound = Class(s(Object) in s(dart.core), top-level))), ' |
181 ' type = Class(s(num) in s(dart.core), top-level))]', | 202 'Parameter(s(c) in s(bar),' |
182 barInC.parameters); | 203 ' type = Class(s(num) in s(dart.core), top-level))]', |
| 204 barInC.parameters); |
183 } | 205 } |
OLD | NEW |