@@ -123,6 +123,124 @@ class A {}
123
123
await _assertLanguageVersionCurrent ('package:aaa/c.dart' );
124
124
}
125
125
126
+ test_scope () async {
127
+ await assertNoErrorsInCode (r'''
128
+ int foo;
129
+ ''' );
130
+
131
+ var scope = result.libraryElement.scope;
132
+
133
+ assertElement (
134
+ scope.lookup (id: 'foo' , setter: false ),
135
+ findElement.topGet ('foo' ),
136
+ );
137
+ assertElement (
138
+ scope.lookup (id: 'foo' , setter: true ),
139
+ findElement.topSet ('foo' ),
140
+ );
141
+ }
142
+
143
+ test_scope_implicitCoreImport () async {
144
+ await assertNoErrorsInCode ('' );
145
+
146
+ var scope = result.libraryElement.scope;
147
+
148
+ assertElement (
149
+ scope.lookup (id: 'int' , setter: false ),
150
+ intElement,
151
+ );
152
+ }
153
+
154
+ test_scope_notFound () async {
155
+ await assertNoErrorsInCode ('' );
156
+
157
+ var scope = result.libraryElement.scope;
158
+
159
+ assertElementNull (
160
+ scope.lookup (id: 'noSuchGetter' , setter: false ),
161
+ );
162
+
163
+ assertElementNull (
164
+ scope.lookup (id: 'noSuchSetter' , setter: true ),
165
+ );
166
+ }
167
+
168
+ test_scope_prefersLocal () async {
169
+ await assertNoErrorsInCode (r'''
170
+ // ignore:unused_import
171
+ import 'dart:math';
172
+
173
+ int sin() => 3;
174
+ ''' );
175
+
176
+ var scope = result.libraryElement.scope;
177
+
178
+ assertElement (
179
+ scope.lookup (id: 'sin' , setter: false ),
180
+ findElement.topFunction ('sin' ),
181
+ );
182
+
183
+ assertElement (
184
+ scope.lookup (id: 'cos' , setter: false ),
185
+ findElement.importFind ('dart:math' ).topFunction ('cos' ),
186
+ );
187
+ }
188
+
189
+ test_scope_prefix () async {
190
+ await assertNoErrorsInCode (r'''
191
+ // ignore:unused_import
192
+ import 'dart:math' as math;
193
+ ''' );
194
+
195
+ var scope = result.libraryElement.scope;
196
+
197
+ assertElement (
198
+ scope.lookup (id: 'math' , setter: false ),
199
+ findElement.prefix ('math' ),
200
+ );
201
+ }
202
+
203
+ test_scope_respectsCombinator_hide () async {
204
+ await assertNoErrorsInCode (r'''
205
+ // ignore:unused_import
206
+ import 'dart:math' hide sin;
207
+ ''' );
208
+
209
+ var scope = result.libraryElement.scope;
210
+
211
+ assertElementNull (
212
+ scope.lookup (id: 'sin' , setter: false ),
213
+ );
214
+
215
+ var mathFind = findElement.importFind ('dart:math' );
216
+ assertElement (
217
+ scope.lookup (id: 'cos' , setter: false ),
218
+ mathFind.topFunction ('cos' ),
219
+ );
220
+ assertElement (
221
+ scope.lookup (id: 'tan' , setter: false ),
222
+ mathFind.topFunction ('tan' ),
223
+ );
224
+ }
225
+
226
+ test_scope_respectsCombinator_show () async {
227
+ await assertNoErrorsInCode (r'''
228
+ // ignore:unused_import
229
+ import 'dart:math' show sin;
230
+ ''' );
231
+
232
+ var scope = result.libraryElement.scope;
233
+
234
+ assertElement (
235
+ scope.lookup (id: 'sin' , setter: false ),
236
+ findElement.importFind ('dart:math' ).topFunction ('sin' ),
237
+ );
238
+
239
+ assertElementNull (
240
+ scope.lookup (id: 'cos' , setter: false ),
241
+ );
242
+ }
243
+
126
244
Future <void > _assertLanguageVersion ({
127
245
@required String uriStr,
128
246
@required Version package,
0 commit comments