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

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

Issue 639133003: import directive suggestion fix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
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.util; 5 library test.services.completion.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 int nextOffset = content.indexOf('^', completionOffset + 1); 49 int nextOffset = content.indexOf('^', completionOffset + 1);
50 expect(nextOffset, equals(-1), reason: 'too many ^'); 50 expect(nextOffset, equals(-1), reason: 'too many ^');
51 content = content.substring(0, completionOffset) + 51 content = content.substring(0, completionOffset) +
52 content.substring(completionOffset + 1); 52 content.substring(completionOffset + 1);
53 testSource = addSource(testFile, content); 53 testSource = addSource(testFile, content);
54 request = 54 request =
55 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset); 55 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset);
56 } 56 }
57 57
58 void assertNoSuggestions() { 58 void assertNoSuggestions() {
59 expect(request.suggestions, hasLength(0)); 59 if (request.suggestions.length > 0) {
60 _failedCompletion('Expected no suggestions', request.suggestions);
61 }
60 } 62 }
61 63
62 CompletionSuggestion assertNotSuggested(String completion) { 64 CompletionSuggestion assertNotSuggested(String completion) {
63 CompletionSuggestion suggestion = request.suggestions.firstWhere( 65 CompletionSuggestion suggestion = request.suggestions.firstWhere(
64 (cs) => cs.completion == completion, 66 (cs) => cs.completion == completion,
65 orElse: () => null); 67 orElse: () => null);
66 if (suggestion != null) { 68 if (suggestion != null) {
67 _failedCompletion( 69 _failedCompletion(
68 'did not expect completion: $completion\n $suggestion'); 70 'did not expect completion: $completion\n $suggestion');
69 } 71 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 378
377 CompletionSuggestion assertSuggestImportedClass(String name, 379 CompletionSuggestion assertSuggestImportedClass(String name,
378 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { 380 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
379 if (computer is ImportedComputer) { 381 if (computer is ImportedComputer) {
380 return assertSuggestClass(name, relevance); 382 return assertSuggestClass(name, relevance);
381 } else { 383 } else {
382 return assertNotSuggested(name); 384 return assertNotSuggested(name);
383 } 385 }
384 } 386 }
385 387
388 CompletionSuggestion assertSuggestImportedFunction(String name,
389 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce =
390 CompletionRelevance.DEFAULT]) {
391 if (computer is ImportedComputer) {
392 return assertSuggestFunction(name, returnType, isDeprecated, relevance);
393 } else {
394 return assertNotSuggested(name);
395 }
396 }
397
386 CompletionSuggestion assertSuggestImportedTopLevelVar(String name, 398 CompletionSuggestion assertSuggestImportedTopLevelVar(String name,
387 String returnType, [CompletionRelevance relevance = 399 String returnType, [CompletionRelevance relevance =
388 CompletionRelevance.DEFAULT]) { 400 CompletionRelevance.DEFAULT]) {
389 if (computer is ImportedComputer) { 401 if (computer is ImportedComputer) {
390 return assertSuggestTopLevelVar(name, returnType, relevance); 402 return assertSuggestTopLevelVar(name, returnType, relevance);
391 } else { 403 } else {
392 return assertNotSuggested(name); 404 return assertNotSuggested(name);
393 } 405 }
394 }
395
396 CompletionSuggestion assertSuggestImportedFunction(String name,
397 String returnType, [bool isDeprecated = false, CompletionRelevance relevan ce =
398 CompletionRelevance.DEFAULT]) {
399 if (computer is ImportedComputer) {
400 return assertSuggestFunction(name, returnType, isDeprecated, relevance);
401 } else {
402 return assertNotSuggested(name);
403 }
404 } 406 }
405 407
406 CompletionSuggestion assertSuggestInvocationClass(String name, 408 CompletionSuggestion assertSuggestInvocationClass(String name,
407 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { 409 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) {
408 if (computer is InvocationComputer) { 410 if (computer is InvocationComputer) {
409 return assertSuggestClass(name, relevance); 411 return assertSuggestClass(name, relevance);
410 } else { 412 } else {
411 return assertNotSuggested(name); 413 return assertNotSuggested(name);
412 } 414 }
413 } 415 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 return computeFull(true).then((_) { 683 return computeFull(true).then((_) {
682 assertSuggestNamedConstructor('c', 'X'); 684 assertSuggestNamedConstructor('c', 'X');
683 assertSuggestNamedConstructor('_d', 'X'); 685 assertSuggestNamedConstructor('_d', 'X');
684 assertNotSuggested('F1'); 686 assertNotSuggested('F1');
685 assertNotSuggested('T1'); 687 assertNotSuggested('T1');
686 assertNotSuggested('z'); 688 assertNotSuggested('z');
687 assertNotSuggested('m'); 689 assertNotSuggested('m');
688 }); 690 });
689 } 691 }
690 692
693 test_ImportDirective_dart() {
694 // SimpleStringLiteral ImportDirective
695 addTestSource('''
696 import "dart^";
697 main() {}''');
698 computeFast();
699 return computeFull(true).then((_) {
700 assertNoSuggestions();
701 });
702 }
703
691 test_InstanceCreationExpression_imported() { 704 test_InstanceCreationExpression_imported() {
692 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression 705 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression
693 addSource('/testA.dart', ''' 706 addSource('/testA.dart', '''
694 int T1; 707 int T1;
695 F1() { } 708 F1() { }
696 class A {int x;}'''); 709 class A {int x;}''');
697 addTestSource(''' 710 addTestSource('''
698 import "/testA.dart"; 711 import "/testA.dart";
699 int T2; 712 int T2;
700 F2() { } 713 F2() { }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 addTestSource(''' 972 addTestSource('''
960 import "/testB.dart"; 973 import "/testB.dart";
961 class Y {Y.c(); Y._d(); z() {}} 974 class Y {Y.c(); Y._d(); z() {}}
962 main() {var ^}'''); 975 main() {var ^}''');
963 computeFast(); 976 computeFast();
964 return computeFull(true).then((_) { 977 return computeFull(true).then((_) {
965 assertNoSuggestions(); 978 assertNoSuggestions();
966 }); 979 });
967 } 980 }
968 } 981 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698