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

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

Issue 1539693002: move DartCompletionSorter to dart specific contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/domain_completion_util.dart
diff --git a/pkg/analysis_server/test/domain_completion_util.dart b/pkg/analysis_server/test/domain_completion_util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..29cff996eff2558c7915a984cd3847ec6b7cdbf1
--- /dev/null
+++ b/pkg/analysis_server/test/domain_completion_util.dart
@@ -0,0 +1,123 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.domain.completion;
+
+import 'dart:async';
+
+import 'package:analysis_server/plugin/protocol/protocol.dart';
+import 'package:analysis_server/src/constants.dart';
+import 'package:analysis_server/src/domain_completion.dart';
+import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
+import 'package:analysis_server/src/services/index/index.dart' show Index;
+import 'package:analysis_server/src/services/index/local_memory_index.dart';
+import 'package:unittest/unittest.dart';
+
+import 'analysis_abstract.dart';
+import 'mocks.dart';
+
+class AbstractCompletionDomainTest extends AbstractAnalysisTest {
+ String completionId;
+ int completionOffset;
+ int replacementOffset;
+ int replacementLength;
+ List<CompletionSuggestion> suggestions = [];
+ bool suggestionsDone = false;
+
+ String addTestFile(String content, {int offset}) {
+ completionOffset = content.indexOf('^');
+ if (offset != null) {
+ expect(completionOffset, -1, reason: 'cannot supply offset and ^');
+ completionOffset = offset;
+ return super.addTestFile(content);
+ }
+ expect(completionOffset, isNot(equals(-1)), reason: 'missing ^');
+ int nextOffset = content.indexOf('^', completionOffset + 1);
+ expect(nextOffset, equals(-1), reason: 'too many ^');
+ return super.addTestFile(content.substring(0, completionOffset) +
+ content.substring(completionOffset + 1));
+ }
+
+ void assertHasResult(CompletionSuggestionKind kind, String completion,
+ {int relevance: DART_RELEVANCE_DEFAULT,
+ bool isDeprecated: false,
+ bool isPotential: false,
+ int selectionOffset}) {
+ var cs;
+ suggestions.forEach((s) {
+ if (s.completion == completion) {
+ if (cs == null) {
+ cs = s;
+ } else {
+ fail('expected exactly one $completion but found > 1');
+ }
+ }
+ });
+ if (cs == null) {
+ var completions = suggestions.map((s) => s.completion).toList();
+ fail('expected "$completion" but found\n $completions');
+ }
+ expect(cs.kind, equals(kind));
+ expect(cs.relevance, equals(relevance));
+ expect(cs.selectionOffset, selectionOffset ?? completion.length);
+ expect(cs.selectionLength, equals(0));
+ expect(cs.isDeprecated, equals(isDeprecated));
+ expect(cs.isPotential, equals(isPotential));
+ }
+
+ void assertNoResult(String completion) {
+ if (suggestions.any((cs) => cs.completion == completion)) {
+ fail('did not expect completion: $completion');
+ }
+ }
+
+ void assertValidId(String id) {
+ expect(id, isNotNull);
+ expect(id.isNotEmpty, isTrue);
+ }
+
+ @override
+ Index createIndex() {
+ return createLocalMemoryIndex();
+ }
+
+ Future getSuggestions() {
+ return waitForTasksFinished().then((_) {
+ Request request =
+ new CompletionGetSuggestionsParams(testFile, completionOffset)
+ .toRequest('0');
+ Response response = handleSuccessfulRequest(request);
+ completionId = response.id;
+ assertValidId(completionId);
+ return pumpEventQueue().then((_) {
+ expect(suggestionsDone, isTrue);
+ });
+ });
+ }
+
+ void processNotification(Notification notification) {
+ if (notification.event == COMPLETION_RESULTS) {
+ var params = new CompletionResultsParams.fromNotification(notification);
+ String id = params.id;
+ assertValidId(id);
+ if (id == completionId) {
+ expect(suggestionsDone, isFalse);
+ replacementOffset = params.replacementOffset;
+ replacementLength = params.replacementLength;
+ suggestionsDone = params.isLast;
+ expect(suggestionsDone, isNotNull);
+ suggestions = params.results;
+ }
+ } else if (notification.event == SERVER_ERROR) {
+ fail('server error: ${notification.toJson()}');
+ }
+ }
+
+ @override
+ void setUp() {
+ super.setUp();
+ createProject();
+ handler = new CompletionDomainHandler(server);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698