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

Unified Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 1278033006: tests for keyword/identifier replacementOffset - asserts fixes #23906 and fixes #23947 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/keyword_contributor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/domain_completion_test.dart
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index a54a5955dc42afe29cc27e088e57bee422509cf7..f09af0e82152471ec1d4ae7d556a5d15d8ce89a6 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -55,14 +55,9 @@ class CompletionManagerTest extends AbstractAnalysisTest {
ExtensionManager manager = new ExtensionManager();
ServerPlugin serverPlugin = new ServerPlugin();
manager.processPlugins([serverPlugin]);
- return new Test_AnalysisServer(
- super.serverChannel,
- super.resourceProvider,
- super.packageMapProvider,
- index,
- serverPlugin,
- new AnalysisServerOptions(),
- new MockSdk(),
+ return new Test_AnalysisServer(super.serverChannel, super.resourceProvider,
+ super.packageMapProvider, index, serverPlugin,
+ new AnalysisServerOptions(), new MockSdk(),
InstrumentationService.NULL_SERVICE);
}
@@ -268,7 +263,7 @@ class CompletionTest extends AbstractAnalysisTest {
List<CompletionSuggestion> suggestions = [];
bool suggestionsDone = false;
- String addTestFile(String content, {offset}) {
+ String addTestFile(String content, {int offset}) {
completionOffset = content.indexOf('^');
if (offset != null) {
expect(completionOffset, -1, reason: 'cannot supply offset and ^');
@@ -283,9 +278,10 @@ class CompletionTest extends AbstractAnalysisTest {
}
void assertHasResult(CompletionSuggestionKind kind, String completion,
- [int relevance = DART_RELEVANCE_DEFAULT,
- bool isDeprecated = false,
- bool isPotential = false]) {
+ {int relevance: DART_RELEVANCE_DEFAULT,
+ bool isDeprecated: false,
+ bool isPotential: false,
+ int selectionOffset}) {
var cs;
suggestions.forEach((s) {
if (s.completion == completion) {
@@ -302,7 +298,7 @@ class CompletionTest extends AbstractAnalysisTest {
}
expect(cs.kind, equals(kind));
expect(cs.relevance, equals(relevance));
- expect(cs.selectionOffset, equals(completion.length));
+ expect(cs.selectionOffset, selectionOffset ?? completion.length);
expect(cs.selectionLength, equals(0));
expect(cs.isDeprecated, equals(isDeprecated));
expect(cs.isPotential, equals(isPotential));
@@ -386,6 +382,64 @@ class CompletionTest extends AbstractAnalysisTest {
});
}
+ test_imports_incremental() async {
+ addTestFile('''library foo;
+ e^
+ import "dart:async";
+ import "package:foo/foo.dart";
+ class foo { }''');
+ await waitForTasksFinished();
+ server.updateContent('uc1', {testFile: new AddContentOverlay(testCode)});
+ server.updateContent('uc2', {
+ testFile:
+ new ChangeContentOverlay([new SourceEdit(completionOffset, 0, 'xp')])
+ });
+ completionOffset += 2;
+ await getSuggestions();
+ expect(replacementOffset, completionOffset - 3);
+ expect(replacementLength, 3);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'export',
+ relevance: DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'import',
+ relevance: DART_RELEVANCE_HIGH);
+ assertNoResult('extends');
+ assertNoResult('library');
+ }
+
+ test_imports_partial() async {
+ addTestFile('''^
+ import "package:foo/foo.dart";
+ import "package:bar/bar.dart";
+ class Baz { }''');
+
+ // Wait for analysis then edit the content
+ await waitForTasksFinished();
+ String revisedContent = testCode.substring(0, completionOffset) +
+ 'i' +
+ testCode.substring(completionOffset);
+ ++completionOffset;
+ server.handleRequest(new AnalysisUpdateContentParams(
+ {testFile: new AddContentOverlay(revisedContent)}).toRequest('add1'));
+
+ // Request code completion immediately after edit
+ Response response = handleSuccessfulRequest(new CompletionGetSuggestionsParams(
+ testFile, completionOffset).toRequest('0'));
+ completionId = response.id;
+ assertValidId(completionId);
+ await waitForTasksFinished();
+ expect(replacementOffset, completionOffset - 1);
+ expect(replacementLength, 1);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'library',
+ relevance: DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'import',
+ relevance: DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'export',
+ relevance: DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'part',
+ relevance: DART_RELEVANCE_HIGH);
+ assertNoResult('extends');
+ }
+
test_imports_prefixed() {
addTestFile('''
import 'dart:html' as foo;
@@ -424,10 +478,10 @@ class CompletionTest extends AbstractAnalysisTest {
return getSuggestions().then((_) {
expect(replacementOffset, equals(completionOffset - 2));
expect(replacementLength, equals(2));
- assertHasResult(
- CompletionSuggestionKind.KEYWORD, 'export', DART_RELEVANCE_HIGH);
- assertHasResult(
- CompletionSuggestionKind.KEYWORD, 'class', DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'export',
+ relevance: DART_RELEVANCE_HIGH);
+ assertHasResult(CompletionSuggestionKind.KEYWORD, 'class',
+ relevance: DART_RELEVANCE_HIGH);
});
}
@@ -447,12 +501,12 @@ class CompletionTest extends AbstractAnalysisTest {
expect(replacementOffset, equals(completionOffset));
expect(replacementLength, equals(0));
assertHasResult(CompletionSuggestionKind.INVOCATION, 'A');
- assertHasResult(
- CompletionSuggestionKind.INVOCATION, 'a', DART_RELEVANCE_LOCAL_FIELD);
+ assertHasResult(CompletionSuggestionKind.INVOCATION, 'a',
+ relevance: DART_RELEVANCE_LOCAL_FIELD);
assertHasResult(CompletionSuggestionKind.INVOCATION, 'b',
- DART_RELEVANCE_LOCAL_VARIABLE);
+ relevance: DART_RELEVANCE_LOCAL_VARIABLE);
assertHasResult(CompletionSuggestionKind.INVOCATION, 'x',
- DART_RELEVANCE_LOCAL_METHOD);
+ relevance: DART_RELEVANCE_LOCAL_METHOD);
assertHasResult(CompletionSuggestionKind.INVOCATION, 'DateTime');
});
}
@@ -477,14 +531,12 @@ class B extends A {m() {^}}
expect(replacementOffset, equals(completionOffset));
expect(replacementLength, equals(0));
assertHasResult(CompletionSuggestionKind.INVOCATION, 'm',
- DART_RELEVANCE_LOCAL_METHOD);
+ relevance: DART_RELEVANCE_LOCAL_METHOD);
});
}
test_partFile() {
- addFile(
- '/project/bin/testA.dart',
- '''
+ addFile('/project/bin/testA.dart', '''
library libA;
part "$testFile";
import 'dart:html';
@@ -504,9 +556,7 @@ class B extends A {m() {^}}
}
test_partFile2() {
- addFile(
- '/testA.dart',
- '''
+ addFile('/testA.dart', '''
part of libA;
class A { }''');
addTestFile('''
@@ -552,7 +602,7 @@ class B extends A {m() {^}}
// Suggestions based upon imported elements are partially filtered
//assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object');
assertHasResult(CompletionSuggestionKind.INVOCATION, 'test',
- DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
+ relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
assertNoResult('HtmlElement');
});
}
@@ -666,24 +716,14 @@ class MockSubscription<E> implements StreamSubscription<E> {
class Test_AnalysisServer extends AnalysisServer {
final MockContext mockContext = new MockContext();
- Test_AnalysisServer(
- ServerCommunicationChannel channel,
+ Test_AnalysisServer(ServerCommunicationChannel channel,
ResourceProvider resourceProvider,
- PubPackageMapProvider packageMapProvider,
- Index index,
- ServerPlugin serverPlugin,
- AnalysisServerOptions analysisServerOptions,
- DartSdk defaultSdk,
- InstrumentationService instrumentationService)
- : super(
- channel,
- resourceProvider,
- packageMapProvider,
- index,
- serverPlugin,
- analysisServerOptions,
- defaultSdk,
- instrumentationService);
+ PubPackageMapProvider packageMapProvider, Index index,
+ ServerPlugin serverPlugin, AnalysisServerOptions analysisServerOptions,
+ DartSdk defaultSdk, InstrumentationService instrumentationService)
+ : super(channel, resourceProvider, packageMapProvider, index,
+ serverPlugin, analysisServerOptions, defaultSdk,
+ instrumentationService);
@override
AnalysisContext getAnalysisContext(String path) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/keyword_contributor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698