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

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

Issue 402723003: first cut simple code completion results (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
new file mode 100644
index 0000000000000000000000000000000000000000..b91bcab1894b3c8ed34da6e18f5e74f04dab7425
--- /dev/null
+++ b/pkg/analysis_server/test/completion_test.dart
@@ -0,0 +1,100 @@
+// 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/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() {
+ group('completion', () {
+ runReflectiveTests(CompletionTest);
+ });
+}
+
+@ReflectiveTestCase()
+class CompletionTest extends AbstractAnalysisTest {
+ String completionId;
+ List<CompletionSuggestion> suggestions = [];
+ bool suggestionsDone = false;
+
+ void assertHasResult(String completion) {
+ var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
+ var completions = suggestions.map((s) => s.completion).toList();
+ fail('expected "$completion" but found\n $completions');
+ });
+ }
+
+ void assertValidId(String id) {
+ expect(id, isNotNull);
+ expect(id.isNotEmpty, isTrue);
+ }
+
+ @override
+ Index createIndex() {
+ return createLocalMemoryIndex();
+ }
+
+ Future getSuggestions(String pattern, int offset) {
scheglov 2014/07/17 20:40:00 You don't use "pattern", did you mean to find offs
danrubel 2014/07/17 21:01:14 Yes! Good eyes. Fixed.
+ return waitForTasksFinished().then((_) {
+ Request request = new Request('0', COMPLETION_GET_SUGGESTIONS);
+ request.setParameter(FILE, testFile);
+ request.setParameter(OFFSET, offset);
+ 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() {
+ addTestFile('''
+ import 'dart:html';
scheglov 2014/07/17 20:40:00 It's up to you, but I'd start sample code with lin
danrubel 2014/07/17 21:01:14 I found it jarring to see things abruptly left ali
scheglov 2014/07/17 21:09:32 OK
+ main() {}
+ ''');
+ return getSuggestions('}', 0).then((_) {
+ assertHasResult('Object');
+ assertHasResult('HtmlElement');
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698