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