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

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

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

Powered by Google App Engine
This is Rietveld 408576698