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

Side by Side Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 424543004: incremental progress aligning code completion api to spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 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 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.domain.completion; 5 library test.domain.completion;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/domain_completion.dart'; 10 import 'package:analysis_server/src/domain_completion.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_services/completion/completion_suggestion.dart'; 12 import 'package:analysis_services/completion/completion_suggestion.dart';
13 import 'package:analysis_services/constants.dart'; 13 import 'package:analysis_services/constants.dart';
14 import 'package:analysis_services/index/index.dart' show Index; 14 import 'package:analysis_services/index/index.dart' show Index;
15 import 'package:analysis_services/index/local_memory_index.dart'; 15 import 'package:analysis_services/index/local_memory_index.dart';
16 import 'package:analysis_testing/reflective_tests.dart'; 16 import 'package:analysis_testing/reflective_tests.dart';
17 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
18 18
19 import 'analysis_abstract.dart'; 19 import 'analysis_abstract.dart';
20 20
21 main() { 21 main() {
22 groupSep = ' | '; 22 groupSep = ' | ';
23 runReflectiveTests(CompletionTest); 23 runReflectiveTests(CompletionTest);
24 } 24 }
25 25
26 @ReflectiveTestCase() 26 @ReflectiveTestCase()
27 class CompletionTest extends AbstractAnalysisTest { 27 class CompletionTest extends AbstractAnalysisTest {
28 String completionId; 28 String completionId;
29 int completionOffset; 29 int completionOffset;
30 int replacementOffset;
31 int replacementLength;
30 List<CompletionSuggestion> suggestions = []; 32 List<CompletionSuggestion> suggestions = [];
31 bool suggestionsDone = false; 33 bool suggestionsDone = false;
32 34
33 String addTestFile(String content) { 35 String addTestFile(String content) {
34 completionOffset = content.indexOf('^'); 36 completionOffset = content.indexOf('^');
35 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); 37 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^');
36 int nextOffset = content.indexOf('^', completionOffset + 1); 38 int nextOffset = content.indexOf('^', completionOffset + 1);
37 expect(nextOffset, equals(-1), reason: 'too many ^'); 39 expect(nextOffset, equals(-1), reason: 'too many ^');
38 return super.addTestFile( 40 return super.addTestFile(
39 content.substring(0, completionOffset) 41 content.substring(0, completionOffset)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return waitForSuggestions(); 84 return waitForSuggestions();
83 }); 85 });
84 } 86 }
85 87
86 void processNotification(Notification notification) { 88 void processNotification(Notification notification) {
87 if (notification.event == COMPLETION_RESULTS) { 89 if (notification.event == COMPLETION_RESULTS) {
88 String id = notification.getParameter(ID); 90 String id = notification.getParameter(ID);
89 assertValidId(id); 91 assertValidId(id);
90 if (id == completionId) { 92 if (id == completionId) {
91 expect(suggestionsDone, isFalse); 93 expect(suggestionsDone, isFalse);
94 replacementOffset = notification.getParameter(REPLACEMENT_OFFSET);
95 replacementLength = notification.getParameter(REPLACEMENT_LENGTH);
92 suggestionsDone = notification.getParameter(LAST); 96 suggestionsDone = notification.getParameter(LAST);
93 expect(suggestionsDone, isNotNull); 97 expect(suggestionsDone, isNotNull);
94 for (Map<String, Object> json in notification.getParameter(RESULTS)) { 98 for (Map<String, Object> json in notification.getParameter(RESULTS)) {
95 expect(json, isNotNull); 99 expect(json, isNotNull);
96 suggestions.add(new CompletionSuggestion.fromJson(json)); 100 suggestions.add(new CompletionSuggestion.fromJson(json));
97 } 101 }
98 } 102 }
99 } 103 }
100 } 104 }
101 105
102 @override 106 @override
103 void setUp() { 107 void setUp() {
104 super.setUp(); 108 super.setUp();
105 createProject(); 109 createProject();
106 handler = new CompletionDomainHandler(server); 110 handler = new CompletionDomainHandler(server);
107 } 111 }
108 112
109 Future waitForSuggestions() { 113 test_suggestions_html() {
110 if (suggestionsDone) { 114 testFile = '/project/web/test.html';
111 return new Future.value(); 115 addTestFile('''
112 } 116 <html>^</html>
113 return new Future.delayed(Duration.ZERO, waitForSuggestions); 117 ''');
118 return getSuggestions().then((_) {
119 expect(replacementOffset, equals(completionOffset));
120 expect(replacementLength, equals(0));
121 expect(suggestions, hasLength(0));
122 });
114 } 123 }
115 124
116 test_suggestions_importedType() { 125 test_suggestions_importedType() {
117 addTestFile(''' 126 addTestFile('''
118 import 'dart:html'; 127 import 'dart:html';
119 main() {^} 128 main() {^}
120 '''); 129 ''');
121 return getSuggestions().then((_) { 130 return getSuggestions().then((_) {
131 expect(replacementOffset, equals(completionOffset));
132 expect(replacementLength, equals(0));
122 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); 133 assertHasResult(CompletionSuggestionKind.CLASS, 'Object');
123 assertHasResult(CompletionSuggestionKind.CLASS, 'HtmlElement'); 134 assertHasResult(CompletionSuggestionKind.CLASS, 'HtmlElement');
124 assertNoResult('test'); 135 assertNoResult('test');
125 }); 136 });
126 } 137 }
127 138
128 test_suggestions_topLevel() { 139 test_suggestions_topLevel() {
129 addTestFile(''' 140 addTestFile('''
130 typedef foo(); 141 typedef foo();
131 var test^ = ''; 142 var test = '';
132 main() {test.} 143 main() {tes^t}
133 '''); 144 ''');
134 return getSuggestions().then((_) { 145 return getSuggestions().then((_) {
146 // expect(replacementOffset, equals(completionOffset - 3));
147 // expect(replacementLength, equals(4));
135 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); 148 assertHasResult(CompletionSuggestionKind.CLASS, 'Object');
136 assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test'); 149 assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test');
137 assertNoResult('HtmlElement'); 150 assertNoResult('HtmlElement');
138 }); 151 });
139 } 152 }
153
154 Future waitForSuggestions() {
155 if (suggestionsDone) {
156 return new Future.value();
157 }
158 return new Future.delayed(Duration.ZERO, waitForSuggestions);
159 }
140 } 160 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_completion.dart ('k') | pkg/analysis_services/lib/completion/completion_computer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698