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

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

Issue 428313002: refactor code completion to allow for multiple suggestion computers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
Index: pkg/analysis_server/test/completion_test.dart
diff --git a/pkg/analysis_server/test/completion_test.dart b/pkg/analysis_server/test/completion_test.dart
deleted file mode 100644
index 3c0008b40048ed2cf31d39ad7c66a881e7b986a6..0000000000000000000000000000000000000000
--- a/pkg/analysis_server/test/completion_test.dart
+++ /dev/null
@@ -1,140 +0,0 @@
-// 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/src/constants.dart';
-import 'package:analysis_server/src/domain_completion.dart';
-import 'package:analysis_server/src/protocol.dart';
-import 'package:analysis_services/completion/completion_suggestion.dart';
-import 'package:analysis_services/constants.dart';
-import 'package:analysis_services/index/index.dart' show Index;
-import 'package:analysis_services/index/local_memory_index.dart';
-import 'package:analysis_testing/reflective_tests.dart';
-import 'package:unittest/unittest.dart';
-
-import 'analysis_abstract.dart';
-
-main() {
- groupSep = ' | ';
- runReflectiveTests(CompletionTest);
-}
-
-@ReflectiveTestCase()
-class CompletionTest extends AbstractAnalysisTest {
- String completionId;
- int completionOffset;
- List<CompletionSuggestion> suggestions = [];
- bool suggestionsDone = false;
-
- String addTestFile(String content) {
- completionOffset = content.indexOf('^');
- 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,
- [CompletionRelevance relevance = CompletionRelevance.DEFAULT,
- bool isDeprecated = false, bool isPotential = false]) {
- var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
- 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, equals(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 Request('0', COMPLETION_GET_SUGGESTIONS);
- request.setParameter(FILE, testFile);
- request.setParameter(OFFSET, completionOffset);
- Response response = handleSuccessfulRequest(request);
- completionId = response.getResult(ID);
- assertValidId(completionId);
- return waitForSuggestions();
- });
- }
-
- void processNotification(Notification notification) {
- if (notification.event == COMPLETION_RESULTS) {
- String id = notification.getParameter(ID);
- assertValidId(id);
- if (id == completionId) {
- expect(suggestionsDone, isFalse);
- suggestionsDone = notification.getParameter(LAST);
- expect(suggestionsDone, isNotNull);
- for (Map<String, Object> json in notification.getParameter(RESULTS)) {
- expect(json, isNotNull);
- suggestions.add(new CompletionSuggestion.fromJson(json));
- }
- }
- }
- }
-
- @override
- void setUp() {
- super.setUp();
- createProject();
- handler = new CompletionDomainHandler(server);
- }
-
- Future waitForSuggestions() {
- if (suggestionsDone) {
- return new Future.value();
- }
- return new Future.delayed(Duration.ZERO, waitForSuggestions);
- }
-
- test_suggestions_importedType() {
- addTestFile('''
- import 'dart:html';
- main() {^}
- ''');
- return getSuggestions().then((_) {
- assertHasResult(CompletionSuggestionKind.CLASS, 'Object');
- assertHasResult(CompletionSuggestionKind.CLASS, 'HtmlElement');
- assertNoResult('test');
- });
- }
-
- test_suggestions_topLevel() {
- addTestFile('''
- typedef foo();
- var test^ = '';
- main() {test.}
- ''');
- return getSuggestions().then((_) {
- assertHasResult(CompletionSuggestionKind.CLASS, 'Object');
- assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test');
- assertNoResult('HtmlElement');
- });
- }
-}

Powered by Google App Engine
This is Rietveld 408576698