Chromium Code Reviews| 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 /// Test of [ParameterMirror]. | 5 /// Test of [ParameterMirror]. |
| 6 library test.parameter_test; | 6 library test.parameter_test; |
| 7 | 7 |
| 8 @MirrorsUsed(targets: 'test.parameter_test', override: '*') | 8 @MirrorsUsed(targets: 'test.parameter_test', override: '*') |
| 9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
| 10 | 10 |
| 11 import 'package:expect/expect.dart'; | |
| 11 import 'stringify.dart'; | 12 import 'stringify.dart'; |
| 12 | 13 |
| 13 class B { | 14 class B { |
| 14 B(); | 15 B(); |
| 15 B.foo(int x); | 16 B.foo(int x); |
| 16 B.bar(int z, x); | 17 B.bar(int z, x); |
| 18 | |
| 19 // TODO(6490): Currently only supported by the VM. | |
| 20 B.baz(final int x, int y, final int z); | |
| 21 B.qux(int x, [int y= 3 + 1]); | |
| 22 B.quux(int x, {String str: "foo"}); | |
| 23 B.corge({int x: 3 * 17, String str: "bar"}); | |
|
rmacnak
2013/08/23 23:15:27
Include tests of parameters of getters and setters
Michael Lippautz (Google)
2013/08/24 00:17:21
Done.
| |
| 17 } | 24 } |
| 18 | 25 |
| 19 main() { | 26 main() { |
| 20 var constructors = reflectClass(B).constructors; | 27 Map<Symbol, MethodMirror> constructors = reflectClass(B).constructors; |
| 21 | 28 |
| 22 expect('{B: Method(s(B) in s(B), constructor), ' | 29 List<Symbol> constructorKeys = [ |
| 23 'B.bar: Method(s(B.bar) in s(B), constructor), ' | 30 const Symbol('B'), const Symbol('B.bar'), const Symbol('B.baz'), |
| 24 'B.foo: Method(s(B.foo) in s(B), constructor)}', | 31 const Symbol('B.foo'), const Symbol('B.quux'), const Symbol('B.qux'), |
| 25 constructors); | 32 const Symbol('B.corge')]; |
| 33 Expect.setEquals(constructorKeys, constructors.keys); | |
| 26 | 34 |
| 27 var unnamedConstructor = constructors[new Symbol('B')]; | 35 MethodMirror unnamedConstructor = constructors[const Symbol('B')]; |
| 28 | 36 expect('Method(s(B) in s(B), constructor)', unnamedConstructor); |
| 29 expect('[]', unnamedConstructor.parameters); | 37 expect('[]', unnamedConstructor.parameters); |
| 30 expect('Class(s(B) in s(test.parameter_test), top-level)', | 38 expect('Class(s(B) in s(test.parameter_test), top-level)', |
| 31 unnamedConstructor.returnType); | 39 unnamedConstructor.returnType); |
| 32 | 40 |
| 33 var fooConstructor = constructors[new Symbol('B.foo')]; | 41 MethodMirror fooConstructor = constructors[const Symbol('B.foo')]; |
| 42 expect('Method(s(B.foo) in s(B), constructor)', fooConstructor); | |
| 34 expect('[Parameter(s(x) in s(B.foo),' | 43 expect('[Parameter(s(x) in s(B.foo),' |
| 35 ' type = Class(s(int) in s(dart.core), top-level))]', | 44 ' type = Class(s(int) in s(dart.core), top-level))]', |
| 36 fooConstructor.parameters); | 45 fooConstructor.parameters); |
| 37 expect('Class(s(B) in s(test.parameter_test), top-level)', | 46 expect('Class(s(B) in s(test.parameter_test), top-level)', |
| 38 fooConstructor.returnType); | 47 fooConstructor.returnType); |
| 39 | 48 |
| 40 var barConstructor = constructors[new Symbol('B.bar')]; | 49 MethodMirror barConstructor = constructors[const Symbol('B.bar')]; |
| 50 expect('Method(s(B.bar) in s(B), constructor)', barConstructor); | |
| 41 expect('[Parameter(s(z) in s(B.bar),' | 51 expect('[Parameter(s(z) in s(B.bar),' |
| 42 ' type = Class(s(int) in s(dart.core), top-level)), ' | 52 ' type = Class(s(int) in s(dart.core), top-level)), ' |
| 43 'Parameter(s(x) in s(B.bar),' | 53 'Parameter(s(x) in s(B.bar),' |
| 44 ' type = Type(s(dynamic), top-level))]', | 54 ' type = Type(s(dynamic), top-level))]', |
| 45 barConstructor.parameters); | 55 barConstructor.parameters); |
| 46 expect('Class(s(B) in s(test.parameter_test), top-level)', | 56 expect('Class(s(B) in s(test.parameter_test), top-level)', |
| 47 barConstructor.returnType); | 57 barConstructor.returnType); |
| 48 | 58 |
| 49 print(constructors); | 59 MethodMirror bazConstructor = constructors[const Symbol('B.baz')]; |
| 60 expect('Method(s(B.baz) in s(B), constructor)', bazConstructor); | |
| 61 expect('[Parameter(s(x) in s(B.baz), final,' | |
| 62 ' type = Class(s(int) in s(dart.core), top-level)), ' | |
| 63 'Parameter(s(y) in s(B.baz),' | |
| 64 ' type = Class(s(int) in s(dart.core), top-level)), ' | |
| 65 'Parameter(s(z) in s(B.baz), final,' | |
| 66 ' type = Class(s(int) in s(dart.core), top-level))]', | |
| 67 bazConstructor.parameters); | |
| 68 expect('Class(s(B) in s(test.parameter_test), top-level)', | |
| 69 bazConstructor.returnType); | |
| 70 | |
| 71 MethodMirror quxConstructor = constructors[const Symbol('B.qux')]; | |
| 72 expect('Method(s(B.qux) in s(B), constructor)', quxConstructor); | |
| 73 expect('[Parameter(s(x) in s(B.qux),' | |
| 74 ' type = Class(s(int) in s(dart.core), top-level)), ' | |
| 75 'Parameter(s(y) in s(B.qux), optional,' | |
| 76 ' value = Instance(value = 4),' | |
| 77 ' type = Class(s(int) in s(dart.core), top-level))]', | |
| 78 quxConstructor.parameters); | |
| 79 expect('Class(s(B) in s(test.parameter_test), top-level)', | |
| 80 quxConstructor.returnType); | |
| 81 | |
| 82 MethodMirror quuxConstructor = constructors[const Symbol('B.quux')]; | |
| 83 expect('Method(s(B.quux) in s(B), constructor)', quuxConstructor); | |
| 84 expect('[Parameter(s(x) in s(B.quux),' | |
| 85 ' type = Class(s(int) in s(dart.core), top-level)), ' | |
| 86 'Parameter(s(str) in s(B.quux), optional, named,' | |
| 87 ' value = Instance(value = foo),' | |
| 88 ' type = Class(s(String) in s(dart.core), top-level))]', | |
| 89 quuxConstructor.parameters); | |
| 90 expect('Class(s(B) in s(test.parameter_test), top-level)', | |
| 91 quuxConstructor.returnType); | |
| 92 | |
| 93 MethodMirror corgeConstructor = constructors[const Symbol('B.corge')]; | |
| 94 expect('Method(s(B.corge) in s(B), constructor)', corgeConstructor); | |
| 95 expect('[Parameter(s(x) in s(B.corge), optional, named,' | |
| 96 ' value = Instance(value = 51),' | |
| 97 ' type = Class(s(int) in s(dart.core), top-level)), ' | |
| 98 'Parameter(s(str) in s(B.corge), optional, named,' | |
| 99 ' value = Instance(value = bar),' | |
| 100 ' type = Class(s(String) in s(dart.core), top-level))]', | |
| 101 corgeConstructor.parameters); | |
| 102 expect('Class(s(B) in s(test.parameter_test), top-level)', | |
| 103 corgeConstructor.returnType); | |
| 50 } | 104 } |
| OLD | NEW |