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

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

Issue 2651103004: Issue 28387. Test for search of classes defined in SDK. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | 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/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ClassElement element = _findElementAtString('A p'); 211 ClassElement element = _findElementAtString('A p');
212 Element p = _findElement('p'); 212 Element p = _findElement('p');
213 Element main = _findElement('main'); 213 Element main = _findElement('main');
214 var expected = [ 214 var expected = [
215 _expectId(p, SearchResultKind.REFERENCE, 'A p'), 215 _expectId(p, SearchResultKind.REFERENCE, 'A p'),
216 _expectId(main, SearchResultKind.REFERENCE, 'A v') 216 _expectId(main, SearchResultKind.REFERENCE, 'A v')
217 ]; 217 ];
218 await _verifyReferences(element, expected); 218 await _verifyReferences(element, expected);
219 } 219 }
220 220
221 test_searchReferences_ClassElement_definedInSdk() async {
222 await _resolveTestUnit('''
223 import 'dart:math';
224 Random v1;
225 Random v2;
226 ''');
227
228 // Find the Random class element in the SDK source.
229 // IDEA performs search always at declaration, never at reference.
Brian Wilkerson 2017/01/25 14:52:42 I don't understand the second line of this comment
scheglov 2017/01/25 15:02:19 Yes, kind of. When you search on Random in "Rando
Brian Wilkerson 2017/01/25 15:09:27 Ok. It makes perfect sense to test that code path
scheglov 2017/01/25 16:38:57 Done.
230 ClassElement randomElement;
231 {
232 String randomPath = sdk.mapDartUri('dart:math').fullName;
233 AnalysisResult result = await driver.getResult(randomPath);
234 randomElement = result.unit.element.getType('Random');
235 }
236
237 Element v1 = _findElement('v1');
238 Element v2 = _findElement('v2');
239 var expected = [
240 _expectId(v1, SearchResultKind.REFERENCE, 'Random v1;'),
241 _expectId(v2, SearchResultKind.REFERENCE, 'Random v2;'),
242 ];
243 await _verifyReferences(randomElement, expected);
244 }
245
221 test_searchReferences_CompilationUnitElement() async { 246 test_searchReferences_CompilationUnitElement() async {
222 provider.newFile(_p('$testProject/foo.dart'), ''); 247 provider.newFile(_p('$testProject/foo.dart'), '');
223 await _resolveTestUnit(''' 248 await _resolveTestUnit('''
224 import 'foo.dart'; // import 249 import 'foo.dart'; // import
225 export 'foo.dart'; // export 250 export 'foo.dart'; // export
226 '''); 251 ''');
227 CompilationUnitElement element = 252 CompilationUnitElement element =
228 testLibraryElement.imports[0].importedLibrary.definingCompilationUnit; 253 testLibraryElement.imports[0].importedLibrary.definingCompilationUnit;
229 int uriLength = "'foo.dart'".length; 254 int uriLength = "'foo.dart'".length;
230 var expected = [ 255 var expected = [
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 List<SearchResult> results = await driver.search.references(element); 1161 List<SearchResult> results = await driver.search.references(element);
1137 _assertResults(results, expectedMatches); 1162 _assertResults(results, expectedMatches);
1138 expect(results, hasLength(expectedMatches.length)); 1163 expect(results, hasLength(expectedMatches.length));
1139 } 1164 }
1140 1165
1141 static void _assertResults( 1166 static void _assertResults(
1142 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { 1167 List<SearchResult> matches, List<ExpectedResult> expectedMatches) {
1143 expect(matches, unorderedEquals(expectedMatches)); 1168 expect(matches, unorderedEquals(expectedMatches));
1144 } 1169 }
1145 } 1170 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698