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 library dart2js.test.memory_source_file_helper; | 5 library dart2js.test.memory_source_file_helper; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
9 import 'memory_compiler.dart'; | 9 import 'memory_compiler.dart'; |
10 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'
; | 10 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mirror
s.dart'; |
11 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart'; | 11 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart'; |
12 | 12 |
13 const Map MEMORY_SOURCE_FILES = const { | 13 const Map MEMORY_SOURCE_FILES = const { |
14 'main.dart': r""" | 14 'main.dart': r""" |
15 | 15 |
16 library main; | 16 library main; |
17 | 17 |
18 import 'dart:async' as async show Future; | 18 import 'dart:async' as async show Future; |
19 | 19 |
20 var variable; | 20 var variable; |
(...skipping 12 matching lines...) Expand all Loading... |
33 """, | 33 """, |
34 }; | 34 }; |
35 | 35 |
36 void main() { | 36 void main() { |
37 asyncTest(() => mirrorSystemFor(MEMORY_SOURCE_FILES).then( | 37 asyncTest(() => mirrorSystemFor(MEMORY_SOURCE_FILES).then( |
38 (MirrorSystem mirrors) => test(mirrors), | 38 (MirrorSystem mirrors) => test(mirrors), |
39 onError: (e) => Expect.fail('$e'))); | 39 onError: (e) => Expect.fail('$e'))); |
40 } | 40 } |
41 | 41 |
42 void test(MirrorSystem mirrors) { | 42 void test(MirrorSystem mirrors) { |
43 LibraryMirror dartCore = mirrors.libraries[Uri.parse('dart:core')]; | 43 LibrarySourceMirror dartCore = mirrors.libraries[Uri.parse('dart:core')]; |
44 Expect.isNotNull(dartCore); | 44 Expect.isNotNull(dartCore); |
45 | 45 |
46 LibraryMirror dartAsync = mirrors.libraries[Uri.parse('dart:async')]; | 46 LibrarySourceMirror dartAsync = mirrors.libraries[Uri.parse('dart:async')]; |
47 Expect.isNotNull(dartAsync); | 47 Expect.isNotNull(dartAsync); |
48 | 48 |
49 LibraryMirror library = mirrors.libraries[Uri.parse('memory:main.dart')]; | 49 LibrarySourceMirror library = mirrors.libraries[Uri.parse('memory:main.dart')]
; |
50 Expect.isNotNull(library); | 50 Expect.isNotNull(library); |
51 | 51 |
52 // Check top-level scope. | 52 // Check top-level scope. |
53 | 53 |
54 DeclarationMirror String_ = library.lookupInScope('String'); | 54 DeclarationSourceMirror String_ = library.lookupInScope('String'); |
55 Expect.isTrue(String_ is ClassMirror); | 55 Expect.isTrue(String_ is ClassMirror); |
56 Expect.equals('String', String_.simpleName); | 56 Expect.equals(#String, String_.simpleName); |
57 Expect.equals(dartCore, String_.owner); | 57 Expect.equals(dartCore, String_.owner); |
58 | 58 |
59 Expect.isNull(library.lookupInScope('async')); | 59 Expect.isNull(library.lookupInScope('async')); |
60 Expect.isNull(library.lookupInScope('Future')); | 60 Expect.isNull(library.lookupInScope('Future')); |
61 DeclarationMirror Future_ = library.lookupInScope('async.Future'); | 61 DeclarationSourceMirror Future_ = library.lookupInScope('async.Future'); |
62 Expect.isTrue(Future_ is ClassMirror); | 62 Expect.isTrue(Future_ is ClassMirror); |
63 Expect.equals('Future', Future_.simpleName); | 63 Expect.equals(#Future, Future_.simpleName); |
64 Expect.equals(dartAsync, Future_.owner); | 64 Expect.equals(dartAsync, Future_.owner); |
65 // Timer is not in scope. | 65 // Timer is not in scope. |
66 Expect.isNull(library.lookupInScope('Timer')); | 66 Expect.isNull(library.lookupInScope('Timer')); |
67 // async.Timer is hidden. | 67 // async.Timer is hidden. |
68 Expect.isNull(library.lookupInScope('async.Timer')); | 68 Expect.isNull(library.lookupInScope('async.Timer')); |
69 | 69 |
70 DeclarationMirror variable = library.lookupInScope('variable'); | 70 DeclarationSourceMirror variable = library.lookupInScope('variable'); |
71 Expect.isTrue(variable is VariableMirror); | 71 Expect.isTrue(variable is VariableMirror); |
72 Expect.equals('variable', variable.simpleName); | 72 Expect.equals(#variable, variable.simpleName); |
73 Expect.equals('main.variable', variable.qualifiedName); | 73 Expect.equals(#main.variable, variable.qualifiedName); |
74 Expect.equals(library, variable.owner); | 74 Expect.equals(library, variable.owner); |
75 // Parameter `a` is not in scope. | 75 // Parameter `a` is not in scope. |
76 Expect.isNull(library.lookupInScope('a')); | 76 Expect.isNull(library.lookupInScope('a')); |
77 // Parameter `b` is not in scope. | 77 // Parameter `b` is not in scope. |
78 Expect.isNull(library.lookupInScope('b')); | 78 Expect.isNull(library.lookupInScope('b')); |
79 | 79 |
80 DeclarationMirror method = library.lookupInScope('method'); | 80 DeclarationSourceMirror method = library.lookupInScope('method'); |
81 Expect.isTrue(method is MethodMirror); | 81 Expect.isTrue(method is MethodMirror); |
82 Expect.equals('method', method.simpleName); | 82 Expect.equals(#method, method.simpleName); |
83 Expect.equals('main.method', method.qualifiedName); | 83 Expect.equals(#main.method, method.qualifiedName); |
84 Expect.equals(library, method.owner); | 84 Expect.equals(library, method.owner); |
85 | 85 |
86 DeclarationMirror Class = library.lookupInScope('Class'); | 86 DeclarationSourceMirror Class = library.lookupInScope('Class'); |
87 Expect.isTrue(Class is ClassMirror); | 87 Expect.isTrue(Class is ClassMirror); |
88 Expect.equals('Class', Class.simpleName); | 88 Expect.equals(#Class, Class.simpleName); |
89 Expect.equals('main.Class', Class.qualifiedName); | 89 Expect.equals(#main.Class, Class.qualifiedName); |
90 Expect.equals(library, Class.owner); | 90 Expect.equals(library, Class.owner); |
91 // Type variable `A` is not in scope. | 91 // Type variable `A` is not in scope. |
92 Expect.isNull(library.lookupInScope('A')); | 92 Expect.isNull(library.lookupInScope('A')); |
93 | 93 |
94 DeclarationMirror Subclass = library.lookupInScope('Subclass'); | 94 DeclarationSourceMirror Subclass = library.lookupInScope('Subclass'); |
95 Expect.isTrue(Subclass is ClassMirror); | 95 Expect.isTrue(Subclass is ClassMirror); |
96 Expect.equals('Subclass', Subclass.simpleName); | 96 Expect.equals(#Subclass, Subclass.simpleName); |
97 Expect.equals('main.Subclass', Subclass.qualifiedName); | 97 Expect.equals(#main.Subclass, Subclass.qualifiedName); |
98 Expect.equals(library, Subclass.owner); | 98 Expect.equals(library, Subclass.owner); |
99 // Type variable `B` is not in scope. | 99 // Type variable `B` is not in scope. |
100 Expect.isNull(library.lookupInScope('B')); | 100 Expect.isNull(library.lookupInScope('B')); |
101 | 101 |
102 // Check top-level declaration scope. | 102 // Check top-level declaration scope. |
103 checkTopScope(DeclarationMirror declaration) { | 103 checkTopScope(DeclarationSourceMirror declaration) { |
104 Expect.equals(String_, declaration.lookupInScope('String')); | 104 Expect.equals(String_, declaration.lookupInScope('String')); |
105 Expect.equals(Future_, declaration.lookupInScope('async.Future')); | 105 Expect.equals(Future_, declaration.lookupInScope('async.Future')); |
106 Expect.isNull(method.lookupInScope('Timer')); | 106 Expect.isNull(method.lookupInScope('Timer')); |
107 Expect.isNull(declaration.lookupInScope('async.Timer')); | 107 Expect.isNull(declaration.lookupInScope('async.Timer')); |
108 Expect.equals(variable, declaration.lookupInScope('variable')); | 108 Expect.equals(variable, declaration.lookupInScope('variable')); |
109 Expect.equals(method, declaration.lookupInScope('method')); | 109 Expect.equals(method, declaration.lookupInScope('method')); |
110 Expect.equals(Class, declaration.lookupInScope('Class')); | 110 Expect.equals(Class, declaration.lookupInScope('Class')); |
111 // Type variable `A` is not in scope. | 111 // Type variable `A` is not in scope. |
112 Expect.isNull(declaration.lookupInScope('A')); | 112 Expect.isNull(declaration.lookupInScope('A')); |
113 // Field `field` is not in scope. | 113 // Field `field` is not in scope. |
114 Expect.isNull(declaration.lookupInScope('field')); | 114 Expect.isNull(declaration.lookupInScope('field')); |
115 Expect.equals(Subclass, declaration.lookupInScope('Subclass')); | 115 Expect.equals(Subclass, declaration.lookupInScope('Subclass')); |
116 // Type variable `B` is not in scope. | 116 // Type variable `B` is not in scope. |
117 Expect.isNull(declaration.lookupInScope('B')); | 117 Expect.isNull(declaration.lookupInScope('B')); |
118 // Field `subfield` is not in scope. | 118 // Field `subfield` is not in scope. |
119 Expect.isNull(declaration.lookupInScope('subfield')); | 119 Expect.isNull(declaration.lookupInScope('subfield')); |
120 } | 120 } |
121 | 121 |
122 checkTopScope(variable); | 122 checkTopScope(variable); |
123 // Parameter `a` is not in scope of `variable`. | 123 // Parameter `a` is not in scope of `variable`. |
124 Expect.isNull(variable.lookupInScope('a')); | 124 Expect.isNull(variable.lookupInScope('a')); |
125 // Parameter `b` is not in scope of `variable`. | 125 // Parameter `b` is not in scope of `variable`. |
126 Expect.isNull(variable.lookupInScope('b')); | 126 Expect.isNull(variable.lookupInScope('b')); |
127 | 127 |
128 checkTopScope(method); | 128 checkTopScope(method); |
129 // Parameter `a` is in scope of `method`. | 129 // Parameter `a` is in scope of `method`. |
| 130 print(method.lookupInScope('a')); |
130 Expect.isTrue(method.lookupInScope('a') is ParameterMirror); | 131 Expect.isTrue(method.lookupInScope('a') is ParameterMirror); |
131 // Parameter `b` is in scope of `method`. | 132 // Parameter `b` is in scope of `method`. |
132 Expect.isTrue(method.lookupInScope('b') is ParameterMirror); | 133 Expect.isTrue(method.lookupInScope('b') is ParameterMirror); |
133 | 134 |
134 // Check class scope. | 135 // Check class scope. |
135 DeclarationMirror Class_field = Class.lookupInScope('field'); | 136 DeclarationSourceMirror Class_field = Class.lookupInScope('field'); |
136 Expect.isTrue(Class_field is VariableMirror); | 137 Expect.isTrue(Class_field is VariableMirror); |
137 Expect.notEquals(variable, Class_field); | 138 Expect.notEquals(variable, Class_field); |
138 Expect.equals(Class, Class_field.owner); | 139 Expect.equals(Class, Class_field.owner); |
139 | 140 |
140 DeclarationMirror Class_variable = Class.lookupInScope('variable'); | 141 DeclarationSourceMirror Class_variable = Class.lookupInScope('variable'); |
141 Expect.isTrue(Class_variable is VariableMirror); | 142 Expect.isTrue(Class_variable is VariableMirror); |
142 Expect.notEquals(variable, Class_variable); | 143 Expect.notEquals(variable, Class_variable); |
143 Expect.equals(Class, Class_variable.owner); | 144 Expect.equals(Class, Class_variable.owner); |
144 | 145 |
145 DeclarationMirror Class_method = Class.lookupInScope('method'); | 146 DeclarationSourceMirror Class_method = Class.lookupInScope('method'); |
146 Expect.isTrue(Class_method is MethodMirror); | 147 Expect.isTrue(Class_method is MethodMirror); |
147 Expect.notEquals(method, Class_method); | 148 Expect.notEquals(method, Class_method); |
148 Expect.equals(Class, Class_method.owner); | 149 Expect.equals(Class, Class_method.owner); |
149 | 150 |
150 checkClassScope(DeclarationMirror declaration, {bool parametersInScope}) { | 151 checkClassScope(DeclarationSourceMirror declaration, {bool parametersInScope})
{ |
151 Expect.equals(String_, declaration.lookupInScope('String')); | 152 Expect.equals(String_, declaration.lookupInScope('String')); |
152 Expect.equals(Future_, declaration.lookupInScope('async.Future')); | 153 Expect.equals(Future_, declaration.lookupInScope('async.Future')); |
153 Expect.isNull(declaration.lookupInScope('Timer')); | 154 Expect.isNull(declaration.lookupInScope('Timer')); |
154 Expect.isNull(declaration.lookupInScope('async.Timer')); | 155 Expect.isNull(declaration.lookupInScope('async.Timer')); |
155 | 156 |
156 Expect.equals(Class_field, declaration.lookupInScope('field')); | 157 Expect.equals(Class_field, declaration.lookupInScope('field')); |
157 Expect.equals(Class_variable, declaration.lookupInScope('variable')); | 158 Expect.equals(Class_variable, declaration.lookupInScope('variable')); |
158 Expect.equals(Class_method, declaration.lookupInScope('method')); | 159 Expect.equals(Class_method, declaration.lookupInScope('method')); |
159 | 160 |
160 // Parameter `a` is not in scope. | 161 // Parameter `a` is not in scope. |
(...skipping 21 matching lines...) Expand all Loading... |
182 Expect.isNull(declaration.lookupInScope('B')); | 183 Expect.isNull(declaration.lookupInScope('B')); |
183 // Field `subfield` is not in scope. | 184 // Field `subfield` is not in scope. |
184 Expect.isNull(declaration.lookupInScope('subfield')); | 185 Expect.isNull(declaration.lookupInScope('subfield')); |
185 } | 186 } |
186 checkClassScope(Class, parametersInScope: false); | 187 checkClassScope(Class, parametersInScope: false); |
187 checkClassScope(Class_field, parametersInScope: false); | 188 checkClassScope(Class_field, parametersInScope: false); |
188 checkClassScope(Class_variable, parametersInScope: false); | 189 checkClassScope(Class_variable, parametersInScope: false); |
189 checkClassScope(Class_method, parametersInScope: true); | 190 checkClassScope(Class_method, parametersInScope: true); |
190 | 191 |
191 // Check class scope. | 192 // Check class scope. |
192 DeclarationMirror Subclass_subfield = Subclass.lookupInScope('subfield'); | 193 DeclarationSourceMirror Subclass_subfield = Subclass.lookupInScope('subfield')
; |
193 Expect.isTrue(Subclass_subfield is VariableMirror); | 194 Expect.isTrue(Subclass_subfield is VariableMirror); |
194 Expect.notEquals(variable, Subclass_subfield); | 195 Expect.notEquals(variable, Subclass_subfield); |
195 Expect.equals(Subclass, Subclass_subfield.owner); | 196 Expect.equals(Subclass, Subclass_subfield.owner); |
196 | 197 |
197 checkSubclassScope(DeclarationMirror declaration) { | 198 checkSubclassScope(DeclarationSourceMirror declaration) { |
198 Expect.equals(String_, declaration.lookupInScope('String')); | 199 Expect.equals(String_, declaration.lookupInScope('String')); |
199 Expect.equals(Future_, declaration.lookupInScope('async.Future')); | 200 Expect.equals(Future_, declaration.lookupInScope('async.Future')); |
200 Expect.isNull(declaration.lookupInScope('Timer')); | 201 Expect.isNull(declaration.lookupInScope('Timer')); |
201 Expect.isNull(declaration.lookupInScope('async.Timer')); | 202 Expect.isNull(declaration.lookupInScope('async.Timer')); |
202 | 203 |
203 // Top level `variable` is in scope. | 204 // Top level `variable` is in scope. |
204 Expect.equals(variable, declaration.lookupInScope('variable')); | 205 Expect.equals(variable, declaration.lookupInScope('variable')); |
205 // Top level `method` is in scope. | 206 // Top level `method` is in scope. |
206 Expect.equals(method, declaration.lookupInScope('method')); | 207 Expect.equals(method, declaration.lookupInScope('method')); |
207 | 208 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 Expect.equals(Subclass_subfield, | 254 Expect.equals(Subclass_subfield, |
254 lookupQualifiedInScope(library, 'Subclass.subfield')); | 255 lookupQualifiedInScope(library, 'Subclass.subfield')); |
255 | 256 |
256 Expect.equals(Future_, lookupQualifiedInScope(library, 'async.Future')); | 257 Expect.equals(Future_, lookupQualifiedInScope(library, 'async.Future')); |
257 Expect.isTrue( | 258 Expect.isTrue( |
258 lookupQualifiedInScope(library, 'async.Future.then') is MethodMirror); | 259 lookupQualifiedInScope(library, 'async.Future.then') is MethodMirror); |
259 // `Timer` should not be found through the prefix `async.Future`. | 260 // `Timer` should not be found through the prefix `async.Future`. |
260 Expect.isNull( | 261 Expect.isNull( |
261 lookupQualifiedInScope(library, 'async.Future.Timer')); | 262 lookupQualifiedInScope(library, 'async.Future.Timer')); |
262 } | 263 } |
OLD | NEW |