| 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 library test.constructors_test; | |
| 6 | |
| 7 import 'dart:mirrors'; | |
| 8 | |
| 9 import 'package:expect/expect.dart'; | |
| 10 | |
| 11 import 'stringify.dart'; | |
| 12 | |
| 13 constructorsOf(ClassMirror cm) { | |
| 14 var result = new Map(); | |
| 15 cm.declarations.forEach((k, v) { | |
| 16 if (v is MethodMirror && v.isConstructor) result[k] = v; | |
| 17 }); | |
| 18 return result; | |
| 19 } | |
| 20 | |
| 21 class Foo {} | |
| 22 | |
| 23 class Bar { | |
| 24 Bar(); | |
| 25 } | |
| 26 | |
| 27 class Baz { | |
| 28 Baz.named(); | |
| 29 } | |
| 30 | |
| 31 class Biz { | |
| 32 Biz(); | |
| 33 Biz.named(); | |
| 34 } | |
| 35 | |
| 36 main() { | |
| 37 ClassMirror fooMirror = reflectClass(Foo); | |
| 38 Map<Symbol, MethodMirror> fooConstructors = constructorsOf(fooMirror); | |
| 39 ClassMirror barMirror = reflectClass(Bar); | |
| 40 Map<Symbol, MethodMirror> barConstructors = constructorsOf(barMirror); | |
| 41 ClassMirror bazMirror = reflectClass(Baz); | |
| 42 Map<Symbol, MethodMirror> bazConstructors = constructorsOf(bazMirror); | |
| 43 ClassMirror bizMirror = reflectClass(Biz); | |
| 44 Map<Symbol, MethodMirror> bizConstructors = constructorsOf(bizMirror); | |
| 45 | |
| 46 expect('{Foo: Method(s(Foo) in s(Foo), constructor)}', fooConstructors); | |
| 47 expect('{Bar: Method(s(Bar) in s(Bar), constructor)}', barConstructors); | |
| 48 expect('{Baz.named: Method(s(Baz.named) in s(Baz), constructor)}', | |
| 49 bazConstructors); | |
| 50 expect( | |
| 51 '{Biz: Method(s(Biz) in s(Biz), constructor),' | |
| 52 ' Biz.named: Method(s(Biz.named) in s(Biz), constructor)}', | |
| 53 bizConstructors); | |
| 54 print(bizConstructors); | |
| 55 | |
| 56 expect('[]', fooConstructors.values.single.parameters); | |
| 57 expect('[]', barConstructors.values.single.parameters); | |
| 58 expect('[]', bazConstructors.values.single.parameters); | |
| 59 for (var constructor in bizConstructors.values) { | |
| 60 expect('[]', constructor.parameters); | |
| 61 } | |
| 62 | |
| 63 expect( | |
| 64 '[s()]', fooConstructors.values.map((m) => m.constructorName).toList()); | |
| 65 expect( | |
| 66 '[s()]', barConstructors.values.map((m) => m.constructorName).toList()); | |
| 67 expect('[s(named)]', | |
| 68 bazConstructors.values.map((m) => m.constructorName).toList()); | |
| 69 expect( | |
| 70 '[s(), s(named)]', | |
| 71 bizConstructors.values.map((m) => m.constructorName).toList() | |
| 72 ..sort(compareSymbols)); | |
| 73 } | |
| OLD | NEW |