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

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

Issue 276043003: Lay waste to ClosureMirror.findInContext. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove stub in dart2js Created 6 years, 7 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/mirrors/find_in_context_private_test.dart ('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 // VMOptions=--support_find_in_context=true
6
7 import "dart:mirrors";
8
9 import "stringify.dart";
10
11 import "package:expect/expect.dart";
12
13 import "closure_mirror_import1.dart";
14 import "closure_mirror_import1.dart" as imp1;
15 import "closure_mirror_import1.dart" as imp1_hidden
16 hide globalVariableInImport, StaticClass;
17 import "closure_mirror_import2.dart" as imp2;
18
19 var globalVariable = "globalVariable";
20
21 globalFoo() => 17;
22
23 class S {
24 static staticFooInS() => "staticFooInS";
25 static var staticInS = "staticInS";
26 var instanceInS = "instanceInS";
27 }
28
29 class C extends S {
30 static staticFooInC() => "staticFooInC";
31 static var staticInC = "staticInC";
32 var instanceInC = "instanceInC";
33
34 foo() => null;
35
36 bar() {
37 var x = 7;
38 var instanceInC = 11; // Shadowing the instance field.
39 var y = 3; // Not in context.
40 baz() {
41 if (x) {}
42 if (instanceInC) {}
43 };
44 return reflect(baz);
45 }
46
47 baz() {
48 var instanceInC = null; // Shadowing with a null value.
49 return reflect(() => instanceInC);
50 }
51 }
52
53 main() {
54 C c = new C();
55 ClosureMirror cm = reflect(c.foo);
56
57 var result;
58
59 result = cm.findInContext(#globalVariable);
60 expect("Instance(value = globalVariable)", result);
61
62 result = cm.findInContext(#globalFoo);
63 Expect.isTrue(result is ClosureMirror);
64 expect("Instance(value = 17)", result.apply(const []));
65
66 result = cm.findInContext(#S.staticInS);
67 expect("Instance(value = staticInS)", result);
68
69 result = cm.findInContext(#staticInS);
70 Expect.isFalse(result is InstanceMirror);
71 Expect.equals(null, result);
72
73 result = cm.findInContext(#staticFooInS);
74 Expect.isFalse(result is InstanceMirror);
75 Expect.equals(null, result);
76
77 result = cm.findInContext(#S.staticFooInS);
78 Expect.isTrue(result is ClosureMirror);
79 expect("Instance(value = staticFooInS)", result.apply(const []));
80
81 result = cm.findInContext(#C.staticFooInS);
82 Expect.isFalse(result is InstanceMirror);
83 Expect.equals(null, result);
84
85 result = cm.findInContext(#C.staticInC);
86 expect("Instance(value = staticInC)", result);
87
88 result = cm.findInContext(#staticInC);
89 expect("Instance(value = staticInC)", result);
90
91 result = cm.findInContext(#C.staticFooInC);
92 Expect.isTrue(result is ClosureMirror);
93 expect("Instance(value = staticFooInC)", result.apply(const []));
94
95 result = cm.findInContext(#staticFooInC);
96 Expect.isTrue(result is ClosureMirror);
97 expect("Instance(value = staticFooInC)", result.apply(const []));
98
99 result = cm.findInContext(#instanceInC);
100 expect("Instance(value = instanceInC)", result);
101
102 result = cm.findInContext(#instanceInS);
103 expect("Instance(value = instanceInS)", result);
104
105 result = cm.findInContext(#globalVariableInImport1);
106 expect("Instance(value = globalVariableInImport1)", result);
107
108 result = cm.findInContext(#StaticClass.staticField);
109 expect("Instance(value = staticField)", result);
110
111 result = cm.findInContext(#StaticClass.staticFunctionInStaticClass);
112 Expect.isTrue(result is ClosureMirror);
113 expect("Instance(value = staticFunctionInStaticClass)",
114 result.apply(const []));
115
116 result = cm.findInContext(#imp1.StaticClass.staticFunctionInStaticClass);
117 Expect.isTrue(result is ClosureMirror);
118 expect("Instance(value = staticFunctionInStaticClass)",
119 result.apply(const []));
120
121 result = cm.findInContext(#imp1.globalVariableInImport1);
122 expect("Instance(value = globalVariableInImport1)", result);
123
124 result = cm.findInContext(#imp2.globalVariableInImport);
125 Expect.isFalse(result is InstanceMirror);
126 Expect.equals(null, result);
127
128 result = cm.findInContext(#imp1.StaticClass.staticField);
129 expect("Instance(value = staticField)", result);
130
131 result = cm.findInContext(#imp1_hidden.StaticClass.staticField);
132 Expect.isFalse(result is InstanceMirror);
133 Expect.equals(null, result);
134
135 result = cm.findInContext(#firstGlobalVariableInImport2);
136 expect("Instance(value = firstGlobalVariableInImport2)", result);
137
138 result = cm.findInContext(#secondGlobalVariableInImport2);
139 Expect.isFalse(result is InstanceMirror);
140 Expect.equals(null, result);
141
142 result = cm.findInContext(#imp2.secondGlobalVariableInImport2);
143 expect("Instance(value = secondGlobalVariableInImport2)", result);
144
145 result = c.bar().findInContext(#x);
146 expect("Instance(value = 7)", result);
147
148 result = c.bar().findInContext(#instanceInC);
149 expect("Instance(value = 11)", result);
150
151 result = c.bar().findInContext(#y);
152 Expect.isFalse(result is InstanceMirror);
153 Expect.equals(null, result);
154
155 result = c.baz().findInContext(#instanceInC);
156 expect("Instance(value = <null>)", result);
157 }
OLDNEW
« no previous file with comments | « tests/lib/mirrors/find_in_context_private_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698