| 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 import "dart:mirrors"; |
| 6 |
| 7 import "package:async_helper/async_helper.dart"; |
| 8 import "package:expect/expect.dart"; |
| 9 import "../memory_compiler.dart"; |
| 10 |
| 11 const SOURCE = const { |
| 12 'main.dart': """ |
| 13 library main; |
| 14 |
| 15 class Class { |
| 16 var a, b, c, d, e, f, g, h; |
| 17 Class.optional(this.a, int b, void this.c(), |
| 18 [this.d, int this.e, void this.f(), |
| 19 this.g = 0, int this.h = 0]); |
| 20 Class.named(this.a, int b, void this.c(), |
| 21 {this.d, int this.e, void this.f(), |
| 22 this.g: 0, int this.h: 0}); |
| 23 methodOptional(a, int b, void c(), |
| 24 [d, int e, void f(), |
| 25 g = 0, int h = 0]) {} |
| 26 methodNamed(a, int b, void c(), |
| 27 {d, int e, void f(), |
| 28 g: 0, int h: 0}) {} |
| 29 } |
| 30 """, |
| 31 }; |
| 32 |
| 33 main() { |
| 34 asyncTest(() => mirrorSystemFor(SOURCE).then((MirrorSystem mirrors) { |
| 35 LibraryMirror dartCore = mirrors.libraries[Uri.parse('memory:main.dart')]; |
| 36 ClassMirror classMirror = dartCore.declarations[#Class]; |
| 37 testMethod(classMirror.declarations[#optional]); |
| 38 testMethod(classMirror.declarations[#named]); |
| 39 testMethod(classMirror.declarations[#methodOptional]); |
| 40 testMethod(classMirror.declarations[#methodNamed]); |
| 41 })); |
| 42 } |
| 43 |
| 44 testMethod(MethodMirror mirror) { |
| 45 Expect.equals(8, mirror.parameters.length); |
| 46 for (int i = 0 ; i < 6 ; i++) { |
| 47 testParameter(mirror.parameters[i], false); |
| 48 } |
| 49 for (int i = 6 ; i < 8 ; i++) { |
| 50 testParameter(mirror.parameters[i], true); |
| 51 } |
| 52 } |
| 53 |
| 54 testParameter(ParameterMirror mirror, bool expectDefaultValue) { |
| 55 if (expectDefaultValue) { |
| 56 Expect.isTrue(mirror.hasDefaultValue); |
| 57 Expect.isNotNull(mirror.defaultValue); |
| 58 } else { |
| 59 Expect.isFalse(mirror.hasDefaultValue); |
| 60 Expect.isNull(mirror.defaultValue); |
| 61 } |
| 62 } |
| OLD | NEW |