| 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 import "dart:mirrors"; | 5 import "dart:mirrors"; |
| 6 | |
| 7 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "method_mirror_source_other.dart"; |
| 8 | 8 |
| 9 expectSource(Mirror mirror, String source) { | 9 expectSource(Mirror mirror, String source) { |
| 10 MethodMirror methodMirror; | 10 MethodMirror methodMirror; |
| 11 if (mirror is ClosureMirror) { | 11 if (mirror is ClosureMirror) { |
| 12 methodMirror = mirror.function; | 12 methodMirror = mirror.function; |
| 13 } else { | 13 } else { |
| 14 methodMirror = mirror as MethodMirror; | 14 methodMirror = mirror as MethodMirror; |
| 15 } | 15 } |
| 16 Expect.isTrue(methodMirror is MethodMirror); | 16 Expect.isTrue(methodMirror is MethodMirror); |
| 17 Expect.equals(methodMirror.source, source); | 17 Expect.equals(source, methodMirror.source); |
| 18 } | 18 } |
| 19 | 19 |
| 20 foo1() {} | 20 foo1() {} |
| 21 doSomething(e) => e; | 21 doSomething(e) => e; |
| 22 | 22 |
| 23 int get x => 42; | 23 int get x => 42; |
| 24 set x(value) { } | 24 set x(value) { } |
| 25 | 25 |
| 26 class S {} | 26 class S {} |
| 27 | 27 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 // Closures | 92 // Closures |
| 93 expectSource(reflect((){}), "(){}"); | 93 expectSource(reflect((){}), "(){}"); |
| 94 expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }"); | 94 expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }"); |
| 95 expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)"); | 95 expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)"); |
| 96 | 96 |
| 97 namedClosure(x,y,z) => 1; | 97 namedClosure(x,y,z) => 1; |
| 98 var a = () {}; | 98 var a = () {}; |
| 99 expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;"); | 99 expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;"); |
| 100 expectSource(reflect(a), "() {}"); | 100 expectSource(reflect(a), "() {}"); |
| 101 |
| 102 // Function at first line. |
| 103 expectSource(reflectClass(SomethingInOther).owner.declarations[#main], |
| 104 """main() { |
| 105 print("Blah"); |
| 106 }"""); |
| 101 } | 107 } |
| OLD | NEW |