| 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 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 expectSource(Mirror mirror, String source) { | 9 expectSource(Mirror mirror, String source) { |
| 10 if (mirror is ClosureMirror) { | 10 if (mirror is ClosureMirror) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 set someX(v) { | 49 set someX(v) { |
| 50 // Discard this one. | 50 // Discard this one. |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 main() { | 55 main() { |
| 56 // Top-level members | 56 // Top-level members |
| 57 LibraryMirror lib = reflectClass(C).owner; | 57 LibraryMirror lib = reflectClass(C).owner; |
| 58 expectSource(lib.members[const Symbol("foo1")], | 58 expectSource(lib.members[#foo1], |
| 59 "foo1() {}"); | 59 "foo1() {}"); |
| 60 expectSource(lib.members[const Symbol("x")], | 60 expectSource(lib.members[#x], |
| 61 "int get x => 42;"); | 61 "int get x => 42;"); |
| 62 expectSource(lib.members[const Symbol("x=")], | 62 expectSource(lib.members[const Symbol("x=")], |
| 63 "set x(value) { }"); | 63 "set x(value) { }"); |
| 64 | 64 |
| 65 // Class members | 65 // Class members |
| 66 ClassMirror cm = reflectClass(C); | 66 ClassMirror cm = reflectClass(C); |
| 67 expectSource(cm.members[const Symbol("foo")], | 67 expectSource(cm.members[#foo], |
| 68 "static dynamic foo() {\n" | 68 "static dynamic foo() {\n" |
| 69 " // Happy foo.\n" | 69 " // Happy foo.\n" |
| 70 " }"); | 70 " }"); |
| 71 expectSource(cm.members[const Symbol("bar")], | 71 expectSource(cm.members[#bar], |
| 72 "void bar() { /* Not so happy bar. */ }"); | 72 "void bar() { /* Not so happy bar. */ }"); |
| 73 expectSource(cm.members[const Symbol("someX")], | 73 expectSource(cm.members[#someX], |
| 74 "num get someX =>\n" | 74 "num get someX =>\n" |
| 75 " 181;"); | 75 " 181;"); |
| 76 expectSource(cm.members[const Symbol("someX=")], | 76 expectSource(cm.members[const Symbol("someX=")], |
| 77 "set someX(v) {\n" | 77 "set someX(v) {\n" |
| 78 " // Discard this one.\n" | 78 " // Discard this one.\n" |
| 79 " }"); | 79 " }"); |
| 80 expectSource(cm.constructors[const Symbol("C")], | 80 expectSource(cm.constructors[#C], |
| 81 "C(this._x, y)\n" | 81 "C(this._x, y)\n" |
| 82 " : _y = y,\n" | 82 " : _y = y,\n" |
| 83 " super();"); | 83 " super();"); |
| 84 expectSource(cm.constructors[const Symbol("C.other")], | 84 expectSource(cm.constructors[#C.other], |
| 85 "factory C.other(num z) {}"); | 85 "factory C.other(num z) {}"); |
| 86 expectSource(cm.constructors[const Symbol("C.other3")], | 86 expectSource(cm.constructors[#C.other3], |
| 87 "factory C.other3() = C.other2;"); | 87 "factory C.other3() = C.other2;"); |
| 88 | 88 |
| 89 // Closures | 89 // Closures |
| 90 expectSource(reflect((){}), "(){}"); | 90 expectSource(reflect((){}), "(){}"); |
| 91 expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }"); | 91 expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }"); |
| 92 expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)"); | 92 expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)"); |
| 93 | 93 |
| 94 namedClosure(x,y,z) => 1; | 94 namedClosure(x,y,z) => 1; |
| 95 var a = () {}; | 95 var a = () {}; |
| 96 expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;"); | 96 expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;"); |
| 97 expectSource(reflect(a), "() {}"); | 97 expectSource(reflect(a), "() {}"); |
| 98 } | 98 } |
| OLD | NEW |