Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: tests/lib/mirrors/method_mirror_source_test.dart

Issue 23038010: Fix Function.end_token_pos() and implement MethodMirror.source getter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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:expect/expect.dart";
8
9 expectSource(Mirror mirror, String source) {
10 if (mirror is ClosureMirror) {
11 mirror = mirror.function;
12 }
13 Expect.isTrue(mirror is MethodMirror);
14 Expect.equals(mirror.source, source);
15 }
16
17 foo1() {}
18
19 int get x => 42;
20 set x(value) { }
21
22 class S {}
23
24 class C extends S {
25
26 var _x;
27 var _y;
28
29 C(this.x, y)
30 : _y = y,
31 super();
32
33 factory C.other(num z) {}
34 factory C.other2() {}
35 factory C.other3() = C.other2;
36
37 static dynamic foo() {
38 // Happy foo.
39 }
40
41 // Some comment.
42
43 void bar() { /* Not so happy bar. */ }
44
45 num get someX =>
46 181;
47
48 set someX(v) {
49 // Discard this one.
50 }
51 }
52
53
54 main() {
55 // Top-level members
56 LibraryMirror lib = reflectClass(C).owner;
57 expectSource(lib.members[const Symbol("foo1")],
58 "foo1() {}");
59 expectSource(lib.members[const Symbol("x")],
60 "int get x => 42;");
61 expectSource(lib.members[const Symbol("x=")],
62 "set x(value) { }");
63
64 // Class members
65 ClassMirror cm = reflectClass(C);
66 expectSource(cm.members[const Symbol("foo")],
67 "static dynamic foo() {\n"
68 " // Happy foo.\n"
69 " }");
70 expectSource(cm.members[const Symbol("bar")],
71 "void bar() { /* Not so happy bar. */ }");
72 expectSource(cm.members[const Symbol("someX")],
73 "num get someX =>\n"
74 " 181;");
75 expectSource(cm.members[const Symbol("someX=")],
76 "set someX(v) {\n"
77 " // Discard this one.\n"
78 " }");
79 expectSource(cm.constructors[const Symbol("C")],
80 "C(this.x, y)\n"
81 " : _y = y,\n"
82 " super();");
83 expectSource(cm.constructors[const Symbol("C.other")],
84 "factory C.other(num z) {}");
85 expectSource(cm.constructors[const Symbol("C.other3")],
86 "factory C.other3() = C.other2;");
87
88 // Closures
89 expectSource(reflect((){}), "(){}");
90 expectSource(reflect((x,y,z) { return x*y*z; }), "(x,y,z) { return x*y*z; }");
91 expectSource(reflect((e) => doSomething(e)), "(e) => doSomething(e)");
92
93 namedClosure(x,y,z) => 1;
94 var a = () {};
95 expectSource(reflect(namedClosure), "namedClosure(x,y,z) => 1;");
96 expectSource(reflect(a), "() {}");
97 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698