| 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(targets: const ['test.parameter_test', 'dart.core.int'], override:
'*') |
| 15 import 'dart:mirrors'; | 15 import 'dart:mirrors'; |
| 16 | 16 |
| 17 import 'package:expect/expect.dart'; | 17 import 'package:expect/expect.dart'; |
| 18 import 'stringify.dart'; | 18 import 'stringify.dart'; |
| 19 | 19 |
| 20 class B { | 20 class B { |
| 21 B(); | 21 B(); |
| 22 B.foo(int x); | 22 B.foo(int x); |
| 23 B.bar(int z, x); | 23 B.bar(int z, x); |
| 24 | 24 |
| 25 // TODO(6490): Currently only supported by the VM. | 25 // TODO(6490): Currently only supported by the VM. |
| 26 B.baz(final int x, int y, final int z); | 26 B.baz(final int x, int y, final int z); |
| 27 B.qux(int x, [int y= 3 + 1]); | 27 B.qux(int x, [int y= 3 + 1]); |
| 28 B.quux(int x, {String str: "foo"}); | 28 B.quux(int x, {String str: "foo"}); |
| 29 B.corge({int x: 3 * 17, String str: "bar"}); | 29 B.corge({int x: 3 * 17, String str: "bar"}); |
| 30 B.corgi(int this.z); |
| 30 | 31 |
| 31 var _x; | 32 var _x; |
| 33 var z; |
| 32 get x => _x; | 34 get x => _x; |
| 33 set x(final value) { _x = value; } | 35 set x(final value) { _x = value; } |
| 34 | 36 |
| 35 grault([int x]) {} | 37 grault([int x]) {} |
| 36 garply({int y}) {} | 38 garply({int y}) {} |
| 37 waldo(int z) {} | 39 waldo(int z) {} |
| 38 } | 40 } |
| 39 | 41 |
| 40 class C <S extends int, T> { | 42 class C <S extends int, T> { |
| 41 // TODO(6490): Currently only supported by the VM. | 43 // TODO(6490): Currently only supported by the VM. |
| 42 foo(int a, S b) => b; | 44 foo(int a, S b) => b; |
| 43 bar(S a, T b, num c) {} | 45 bar(S a, T b, num c) {} |
| 44 } | 46 } |
| 45 | 47 |
| 46 main() { | 48 main() { |
| 47 ClassMirror cm = reflectClass(B); | 49 ClassMirror cm = reflectClass(B); |
| 48 var constructors = new Map<Symbol, MethodMirror>(); | 50 var constructors = new Map<Symbol, MethodMirror>(); |
| 49 cm.declarations.forEach((k, v) { | 51 cm.declarations.forEach((k, v) { |
| 50 if (v is MethodMirror && v.isConstructor) constructors[k] = v; | 52 if (v is MethodMirror && v.isConstructor) constructors[k] = v; |
| 51 }); | 53 }); |
| 52 | 54 |
| 53 List<Symbol> constructorKeys = | 55 List<Symbol> constructorKeys = |
| 54 [#B, #B.bar, #B.baz, #B.foo, #B.quux, #B.qux, #B.corge]; | 56 [#B, #B.bar, #B.baz, #B.foo, #B.quux, #B.qux, #B.corge, #B.corgi]; |
| 55 Expect.setEquals(constructorKeys, constructors.keys); | 57 Expect.setEquals(constructorKeys, constructors.keys); |
| 56 | 58 |
| 57 MethodMirror unnamedConstructor = constructors[#B]; | 59 MethodMirror unnamedConstructor = constructors[#B]; |
| 58 expect('Method(s(B) in s(B), constructor)', unnamedConstructor); | 60 expect('Method(s(B) in s(B), constructor)', unnamedConstructor); |
| 59 expect('[]', unnamedConstructor.parameters); | 61 expect('[]', unnamedConstructor.parameters); |
| 60 expect('Class(s(B) in s(test.parameter_test), top-level)', | 62 expect('Class(s(B) in s(test.parameter_test), top-level)', |
| 61 unnamedConstructor.returnType); | 63 unnamedConstructor.returnType); |
| 62 | 64 |
| 63 MethodMirror fooConstructor = constructors[#B.foo]; | 65 MethodMirror fooConstructor = constructors[#B.foo]; |
| 64 expect('Method(s(B.foo) in s(B), constructor)', fooConstructor); | 66 expect('Method(s(B.foo) in s(B), constructor)', fooConstructor); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 expect('[Parameter(s(x) in s(B.corge), optional, named,' | 122 expect('[Parameter(s(x) in s(B.corge), optional, named,' |
| 121 ' value = Instance(value = 51),' | 123 ' value = Instance(value = 51),' |
| 122 ' type = Class(s(int) in s(dart.core), top-level)), ' | 124 ' type = Class(s(int) in s(dart.core), top-level)), ' |
| 123 'Parameter(s(str) in s(B.corge), optional, named,' | 125 'Parameter(s(str) in s(B.corge), optional, named,' |
| 124 ' value = Instance(value = bar),' | 126 ' value = Instance(value = bar),' |
| 125 ' type = Class(s(String) in s(dart.core), top-level))]', | 127 ' type = Class(s(String) in s(dart.core), top-level))]', |
| 126 corgeConstructor.parameters); | 128 corgeConstructor.parameters); |
| 127 expect('Class(s(B) in s(test.parameter_test), top-level)', | 129 expect('Class(s(B) in s(test.parameter_test), top-level)', |
| 128 corgeConstructor.returnType); | 130 corgeConstructor.returnType); |
| 129 | 131 |
| 132 ParameterMirror bazZParameter = |
| 133 bazConstructor.parameters.firstWhere((p) => p.simpleName == #z); |
| 134 Expect.isFalse(bazZParameter.isInitializingFormal); |
| 135 MethodMirror corgiConstructor = constructors[#B.corgi]; |
| 136 ParameterMirror corgiZParameter = |
| 137 corgiConstructor.parameters.firstWhere((p) => p.simpleName == #z); |
| 138 Expect.isTrue(corgiZParameter.isInitializingFormal); |
| 139 |
| 130 MethodMirror xGetter = cm.declarations[#x]; | 140 MethodMirror xGetter = cm.declarations[#x]; |
| 131 expect('Method(s(x) in s(B), getter)', xGetter); | 141 expect('Method(s(x) in s(B), getter)', xGetter); |
| 132 expect('[]', xGetter.parameters); | 142 expect('[]', xGetter.parameters); |
| 133 | 143 |
| 134 MethodMirror xSetter = cm.declarations[const Symbol('x=')]; | 144 MethodMirror xSetter = cm.declarations[const Symbol('x=')]; |
| 135 expect('Method(s(x=) in s(B), setter)', xSetter); | 145 expect('Method(s(x=) in s(B), setter)', xSetter); |
| 136 expect('[Parameter(s(value) in s(x=), final,' | 146 expect('[Parameter(s(value) in s(x=), final,' |
| 137 ' type = Type(s(dynamic), top-level))]', | 147 ' type = Type(s(dynamic), top-level))]', |
| 138 xSetter.parameters); | 148 xSetter.parameters); |
| 139 | 149 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 expect('[Parameter(s(a) in s(bar),' | 184 expect('[Parameter(s(a) in s(bar),' |
| 175 ' type = TypeVariable(s(S) in s(C),' | 185 ' type = TypeVariable(s(S) in s(C),' |
| 176 ' upperBound = Class(s(int) in s(dart.core), top-level))), ' | 186 ' upperBound = Class(s(int) in s(dart.core), top-level))), ' |
| 177 'Parameter(s(b) in s(bar),' | 187 'Parameter(s(b) in s(bar),' |
| 178 ' type = TypeVariable(s(T) in s(C),' | 188 ' type = TypeVariable(s(T) in s(C),' |
| 179 ' upperBound = Class(s(Object) in s(dart.core), top-level))), ' | 189 ' upperBound = Class(s(Object) in s(dart.core), top-level))), ' |
| 180 'Parameter(s(c) in s(bar),' | 190 'Parameter(s(c) in s(bar),' |
| 181 ' type = Class(s(num) in s(dart.core), top-level))]', | 191 ' type = Class(s(num) in s(dart.core), top-level))]', |
| 182 barInC.parameters); | 192 barInC.parameters); |
| 183 } | 193 } |
| OLD | NEW |