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

Side by Side Diff: pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart

Issue 1533613004: extract InheritedReferenceContributor from imported reference contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: include new tests in suite Created 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.services.completion.dart.util; 5 library test.services.completion.dart.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol
10 show Element, ElementKind; 10 show Element, ElementKind;
11 import 'package:analysis_server/plugin/protocol/protocol.dart' 11 import 'package:analysis_server/plugin/protocol/protocol.dart'
12 hide Element, ElementKind; 12 hide Element, ElementKind;
13 import 'package:analysis_server/plugin/protocol/protocol.dart'; 13 import 'package:analysis_server/plugin/protocol/protocol.dart';
14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart'; 14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
15 import 'package:analysis_server/src/services/completion/completion_core.dart'; 15 import 'package:analysis_server/src/services/completion/completion_core.dart';
16 import 'package:analysis_server/src/services/completion/dart/completion_manager. dart' 16 import 'package:analysis_server/src/services/completion/dart/completion_manager. dart'
17 show DartCompletionRequestImpl; 17 show DartCompletionRequestImpl;
18 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart' 18 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'
19 show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOW, ReplacementRange; 19 show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOW, ReplacementRange;
20 import 'package:analysis_server/src/services/index/index.dart'; 20 import 'package:analysis_server/src/services/index/index.dart';
21 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 21 import 'package:analysis_server/src/services/index/local_memory_index.dart';
22 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ; 22 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
23 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
24 import 'package:analyzer/task/dart.dart';
24 import 'package:unittest/unittest.dart'; 25 import 'package:unittest/unittest.dart';
25 26
26 import '../../../abstract_context.dart'; 27 import '../../../abstract_context.dart';
27 28
28 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { 29 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) {
29 String c1 = s1.completion.toLowerCase(); 30 String c1 = s1.completion.toLowerCase();
30 String c2 = s2.completion.toLowerCase(); 31 String c2 = s2.completion.toLowerCase();
31 return c1.compareTo(c2); 32 return c1.compareTo(c2);
32 } 33 }
33 34
34 abstract class DartCompletionContributorTest extends AbstractContextTest { 35 abstract class DartCompletionContributorTest extends AbstractContextTest {
35 Index index; 36 Index index;
36 SearchEngineImpl searchEngine; 37 SearchEngineImpl searchEngine;
37 String testFile = '/completionTest.dart'; 38 String testFile = '/completionTest.dart';
38 Source testSource; 39 Source testSource;
39 int completionOffset; 40 int completionOffset;
40 int replacementOffset; 41 int replacementOffset;
41 int replacementLength; 42 int replacementLength;
42 DartCompletionContributor contributor; 43 DartCompletionContributor contributor;
43 DartCompletionRequest request; 44 DartCompletionRequest request;
44 List<CompletionSuggestion> suggestions; 45 List<CompletionSuggestion> suggestions;
45 46
47 /**
48 * If `true` and `null` is specified as the suggestion's expected returnType
49 * then the actual suggestion is expected to have a `dynamic` returnType.
50 * Newer tests return `false` so that they can distinguish between
51 * `dynamic` and `null`.
52 * Eventually all tests should be converted and this getter removed.
53 */
54 bool get isNullExpectedReturnTypeConsideredDynamic => true;
55
46 void addTestSource(String content) { 56 void addTestSource(String content) {
47 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); 57 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once');
48 completionOffset = content.indexOf('^'); 58 completionOffset = content.indexOf('^');
49 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); 59 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^');
50 int nextOffset = content.indexOf('^', completionOffset + 1); 60 int nextOffset = content.indexOf('^', completionOffset + 1);
51 expect(nextOffset, equals(-1), reason: 'too many ^'); 61 expect(nextOffset, equals(-1), reason: 'too many ^');
52 content = content.substring(0, completionOffset) + 62 content = content.substring(0, completionOffset) +
53 content.substring(completionOffset + 1); 63 content.substring(completionOffset + 1);
54 testSource = addSource(testFile, content); 64 testSource = addSource(testFile, content);
55 } 65 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 145 }
136 return cs; 146 return cs;
137 } 147 }
138 148
139 CompletionSuggestion assertSuggestClass(String name, 149 CompletionSuggestion assertSuggestClass(String name,
140 {int relevance: DART_RELEVANCE_DEFAULT, 150 {int relevance: DART_RELEVANCE_DEFAULT,
141 String importUri, 151 String importUri,
142 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 152 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
143 bool isDeprecated: false, 153 bool isDeprecated: false,
144 String elemFile, 154 String elemFile,
155 String elemName,
145 int elemOffset}) { 156 int elemOffset}) {
146 CompletionSuggestion cs = assertSuggest(name, 157 CompletionSuggestion cs = assertSuggest(name,
147 csKind: kind, 158 csKind: kind,
148 relevance: relevance, 159 relevance: relevance,
149 importUri: importUri, 160 importUri: importUri,
150 isDeprecated: isDeprecated, 161 isDeprecated: isDeprecated,
151 elemFile: elemFile, 162 elemFile: elemFile,
152 elemOffset: elemOffset); 163 elemOffset: elemOffset);
153 protocol.Element element = cs.element; 164 protocol.Element element = cs.element;
154 expect(element, isNotNull); 165 expect(element, isNotNull);
155 expect(element.kind, equals(protocol.ElementKind.CLASS)); 166 expect(element.kind, equals(protocol.ElementKind.CLASS));
156 expect(element.name, equals(name)); 167 expect(element.name, equals(elemName ?? name));
157 expect(element.parameters, isNull); 168 expect(element.parameters, isNull);
158 expect(element.returnType, isNull); 169 expect(element.returnType, isNull);
159 assertHasNoParameterInfo(cs); 170 assertHasNoParameterInfo(cs);
160 return cs; 171 return cs;
161 } 172 }
162 173
163 CompletionSuggestion assertSuggestClassTypeAlias(String name, 174 CompletionSuggestion assertSuggestClassTypeAlias(String name,
164 {int relevance: DART_RELEVANCE_DEFAULT, 175 {int relevance: DART_RELEVANCE_DEFAULT,
165 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { 176 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) {
166 CompletionSuggestion cs = 177 CompletionSuggestion cs =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 CompletionSuggestion assertSuggestFunction(String name, String returnType, 245 CompletionSuggestion assertSuggestFunction(String name, String returnType,
235 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 246 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
236 bool isDeprecated: false, 247 bool isDeprecated: false,
237 int relevance: DART_RELEVANCE_DEFAULT, 248 int relevance: DART_RELEVANCE_DEFAULT,
238 String importUri}) { 249 String importUri}) {
239 CompletionSuggestion cs = assertSuggest(name, 250 CompletionSuggestion cs = assertSuggest(name,
240 csKind: kind, 251 csKind: kind,
241 relevance: relevance, 252 relevance: relevance,
242 importUri: importUri, 253 importUri: importUri,
243 isDeprecated: isDeprecated); 254 isDeprecated: isDeprecated);
244 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); 255 if (returnType != null) {
256 expect(cs.returnType, returnType);
257 } else if (isNullExpectedReturnTypeConsideredDynamic) {
258 expect(cs.returnType, 'dynamic');
259 } else {
260 expect(cs.returnType, isNull);
261 }
245 protocol.Element element = cs.element; 262 protocol.Element element = cs.element;
246 expect(element, isNotNull); 263 expect(element, isNotNull);
247 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); 264 expect(element.kind, equals(protocol.ElementKind.FUNCTION));
248 expect(element.name, equals(name)); 265 expect(element.name, equals(name));
249 expect(element.isDeprecated, equals(isDeprecated)); 266 expect(element.isDeprecated, equals(isDeprecated));
250 String param = element.parameters; 267 String param = element.parameters;
251 expect(param, isNotNull); 268 expect(param, isNotNull);
252 expect(param[0], equals('(')); 269 expect(param[0], equals('('));
253 expect(param[param.length - 1], equals(')')); 270 expect(param[param.length - 1], equals(')'));
254 expect(element.returnType, 271 if (returnType != null) {
255 equals(returnType != null ? returnType : 'dynamic')); 272 expect(element.returnType, returnType);
273 } else if (isNullExpectedReturnTypeConsideredDynamic) {
274 expect(element.returnType, 'dynamic');
275 } else {
276 expect(element.returnType, isNull);
277 }
256 assertHasParameterInfo(cs); 278 assertHasParameterInfo(cs);
257 return cs; 279 return cs;
258 } 280 }
259 281
260 CompletionSuggestion assertSuggestFunctionTypeAlias( 282 CompletionSuggestion assertSuggestFunctionTypeAlias(
261 String name, String returnType, {bool isDeprecated: false, 283 String name, String returnType,
284 {bool isDeprecated: false,
262 int relevance: DART_RELEVANCE_DEFAULT, 285 int relevance: DART_RELEVANCE_DEFAULT,
263 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 286 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
264 String importUri}) { 287 String importUri}) {
265 CompletionSuggestion cs = assertSuggest(name, 288 CompletionSuggestion cs = assertSuggest(name,
266 csKind: kind, 289 csKind: kind,
267 relevance: relevance, 290 relevance: relevance,
268 importUri: importUri, 291 importUri: importUri,
269 isDeprecated: isDeprecated); 292 isDeprecated: isDeprecated);
270 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); 293 if (returnType != null) {
294 expect(cs.returnType, returnType);
295 } else if (isNullExpectedReturnTypeConsideredDynamic) {
296 expect(cs.returnType, 'dynamic');
297 } else {
298 expect(cs.returnType, isNull);
299 }
271 protocol.Element element = cs.element; 300 protocol.Element element = cs.element;
272 expect(element, isNotNull); 301 expect(element, isNotNull);
273 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); 302 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS));
274 expect(element.name, equals(name)); 303 expect(element.name, equals(name));
275 expect(element.isDeprecated, equals(isDeprecated)); 304 expect(element.isDeprecated, equals(isDeprecated));
276 // TODO (danrubel) Determine why params are null 305 // TODO (danrubel) Determine why params are null
277 // String param = element.parameters; 306 // String param = element.parameters;
278 // expect(param, isNotNull); 307 // expect(param, isNotNull);
279 // expect(param[0], equals('(')); 308 // expect(param[0], equals('('));
280 // expect(param[param.length - 1], equals(')')); 309 // expect(param[param.length - 1], equals(')'));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 assertHasNoParameterInfo(cs); 385 assertHasNoParameterInfo(cs);
357 return cs; 386 return cs;
358 } 387 }
359 388
360 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, 389 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType,
361 {int relevance: DART_RELEVANCE_DEFAULT, 390 {int relevance: DART_RELEVANCE_DEFAULT,
362 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, 391 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
363 String importUri}) { 392 String importUri}) {
364 CompletionSuggestion cs = assertSuggest(name, 393 CompletionSuggestion cs = assertSuggest(name,
365 csKind: kind, relevance: relevance, importUri: importUri); 394 csKind: kind, relevance: relevance, importUri: importUri);
366 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); 395 if (returnType != null) {
396 expect(cs.returnType, returnType);
397 } else if (isNullExpectedReturnTypeConsideredDynamic) {
398 expect(cs.returnType, 'dynamic');
399 } else {
400 expect(cs.returnType, isNull);
401 }
367 protocol.Element element = cs.element; 402 protocol.Element element = cs.element;
368 expect(element, isNotNull); 403 expect(element, isNotNull);
369 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); 404 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE));
370 expect(element.name, equals(name)); 405 expect(element.name, equals(name));
371 expect(element.parameters, isNull); 406 expect(element.parameters, isNull);
372 expect(element.returnType, returnType != null ? returnType : 'dynamic'); 407 if (returnType != null) {
408 expect(element.returnType, returnType);
409 } else if (isNullExpectedReturnTypeConsideredDynamic) {
410 expect(element.returnType, 'dynamic');
411 } else {
412 expect(element.returnType, isNull);
413 }
373 assertHasNoParameterInfo(cs); 414 assertHasNoParameterInfo(cs);
374 return cs; 415 return cs;
375 } 416 }
376 417
377 /** 418 /**
378 * Return a [Future] that completes with the containing library information 419 * Return a [Future] that completes with the containing library information
379 * after it is accessible via [context.getLibrariesContaining]. 420 * after it is accessible via [context.getLibrariesContaining].
380 */ 421 */
381 Future computeLibrariesContaining([int times = 200]) { 422 Future computeLibrariesContaining([int times = 200]) {
382 List<Source> libraries = context.getLibrariesContaining(testSource); 423 List<Source> libraries = context.getLibrariesContaining(testSource);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 if (times == 0 || context == null) return new Future.value(); 520 if (times == 0 || context == null) return new Future.value();
480 context.performAnalysisTask(); 521 context.performAnalysisTask();
481 // We use a delayed future to allow microtask events to finish. The 522 // We use a delayed future to allow microtask events to finish. The
482 // Future.value or Future() constructors use scheduleMicrotask themselves an d 523 // Future.value or Future() constructors use scheduleMicrotask themselves an d
483 // would therefore not wait for microtask callbacks that are scheduled after 524 // would therefore not wait for microtask callbacks that are scheduled after
484 // invoking this method. 525 // invoking this method.
485 return new Future.delayed( 526 return new Future.delayed(
486 Duration.ZERO, () => performAnalysis(times - 1, completer)); 527 Duration.ZERO, () => performAnalysis(times - 1, completer));
487 } 528 }
488 529
530 void resolveSource(String path, String content) {
531 Source libSource = addSource(path, content);
532 var target = new LibrarySpecificUnit(libSource, libSource);
533 context.computeResult(target, RESOLVED_UNIT);
534 }
535
489 @override 536 @override
490 void setUp() { 537 void setUp() {
491 super.setUp(); 538 super.setUp();
492 index = createLocalMemoryIndex(); 539 index = createLocalMemoryIndex();
493 searchEngine = new SearchEngineImpl(index); 540 searchEngine = new SearchEngineImpl(index);
494 contributor = createContributor(); 541 contributor = createContributor();
495 } 542 }
496 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698