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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/search_test.dart

Issue 2542583003: Search for ImportElement(s). (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/search.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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart'; 9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/dart/analysis/search.dart'; 10 import 'package:analyzer/src/dart/analysis/search.dart';
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 '''); 293 ''');
294 FunctionElement element = _findElement('test'); 294 FunctionElement element = _findElement('test');
295 Element main = _findElement('main'); 295 Element main = _findElement('main');
296 var expected = [ 296 var expected = [
297 _expectId(main, SearchResultKind.INVOCATION, 'test();'), 297 _expectId(main, SearchResultKind.INVOCATION, 'test();'),
298 _expectId(main, SearchResultKind.REFERENCE, 'test);') 298 _expectId(main, SearchResultKind.REFERENCE, 'test);')
299 ]; 299 ];
300 await _verifyReferences(element, expected); 300 await _verifyReferences(element, expected);
301 } 301 }
302 302
303 test_searchReferences_ImportElement_noPrefix() async {
304 await _resolveTestUnit('''
305 import 'dart:math' show max, PI, Random hide min;
306 export 'dart:math' show max, PI, Random hide min;
307 main() {
308 print(PI);
309 print(new Random());
310 print(max(1, 2));
311 }
312 Random bar() => null;
313 ''');
314 ImportElement element = testLibraryElement.imports[0];
315 Element mainElement = await _findElement('main');
316 Element barElement = await _findElement('bar');
317 var kind = SearchResultKind.REFERENCE;
318 var expected = [
319 _expectId(mainElement, kind, 'PI);', length: 0),
320 _expectId(mainElement, kind, 'Random()', length: 0),
321 _expectId(mainElement, kind, 'max(', length: 0),
322 _expectId(barElement, kind, 'Random bar()', length: 0),
323 ];
324 await _verifyReferences(element, expected);
325 }
326
327 test_searchReferences_ImportElement_withPrefix() async {
328 await _resolveTestUnit('''
329 import 'dart:math' as math show max, PI, Random hide min;
330 export 'dart:math' show max, PI, Random hide min;
331 main() {
332 print(math.PI);
333 print(new math.Random());
334 print(math.max(1, 2));
335 }
336 math.Random bar() => null;
337 ''');
338 ImportElement element = testLibraryElement.imports[0];
339 Element mainElement = await _findElement('main');
340 Element barElement = await _findElement('bar');
341 var kind = SearchResultKind.REFERENCE;
342 var length = 'math.'.length;
343 var expected = [
344 _expectId(mainElement, kind, 'math.PI);', length: length),
345 _expectId(mainElement, kind, 'math.Random()', length: length),
346 _expectId(mainElement, kind, 'math.max(', length: length),
347 _expectId(barElement, kind, 'math.Random bar()', length: length),
348 ];
349 await _verifyReferences(element, expected);
350 }
351
352 test_searchReferences_ImportElement_withPrefix_forMultipleImports() async {
353 await _resolveTestUnit('''
354 import 'dart:async' as p;
355 import 'dart:math' as p;
356 main() {
357 p.Random;
358 p.Future;
359 }
360 ''');
361 Element mainElement = await _findElement('main');
362 var kind = SearchResultKind.REFERENCE;
363 var length = 'p.'.length;
364 {
365 ImportElement element = testLibraryElement.imports[0];
366 var expected = [
367 _expectId(mainElement, kind, 'p.Future;', length: length),
368 ];
369 await _verifyReferences(element, expected);
370 }
371 {
372 ImportElement element = testLibraryElement.imports[1];
373 var expected = [
374 _expectId(mainElement, kind, 'p.Random', length: length),
375 ];
376 await _verifyReferences(element, expected);
377 }
378 }
379
303 test_searchReferences_LabelElement() async { 380 test_searchReferences_LabelElement() async {
304 await _resolveTestUnit(''' 381 await _resolveTestUnit('''
305 main() { 382 main() {
306 label: 383 label:
307 while (true) { 384 while (true) {
308 if (true) { 385 if (true) {
309 break label; // 1 386 break label; // 1
310 } 387 }
311 break label; // 2 388 break label; // 2
312 } 389 }
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 List<SearchResult> results = await driver.search.references(element); 806 List<SearchResult> results = await driver.search.references(element);
730 _assertResults(results, expectedMatches); 807 _assertResults(results, expectedMatches);
731 expect(results, hasLength(expectedMatches.length)); 808 expect(results, hasLength(expectedMatches.length));
732 } 809 }
733 810
734 static void _assertResults( 811 static void _assertResults(
735 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { 812 List<SearchResult> matches, List<ExpectedResult> expectedMatches) {
736 expect(matches, unorderedEquals(expectedMatches)); 813 expect(matches, unorderedEquals(expectedMatches));
737 } 814 }
738 } 815 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/search.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698