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

Side by Side Diff: pkg/analysis_server/test/services/completion/keyword_computer_test.dart

Issue 897833002: fix exception and improve keyword completion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 10 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/keyword_computer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.services.completion.dart.keyword; 5 library test.services.completion.dart.keyword;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; 9 import 'package:analysis_server/src/services/completion/keyword_computer.dart';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 import '../../reflective_tests.dart'; 13 import '../../reflective_tests.dart';
14 import 'completion_test_util.dart'; 14 import 'completion_test_util.dart';
15 15
16 main() { 16 main() {
17 groupSep = ' | '; 17 groupSep = ' | ';
18 runReflectiveTests(KeywordComputerTest); 18 runReflectiveTests(KeywordComputerTest);
19 } 19 }
20 20
21 @reflectiveTest 21 @reflectiveTest
22 class KeywordComputerTest extends AbstractCompletionTest { 22 class KeywordComputerTest extends AbstractCompletionTest {
23 23
24 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, 24 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, [int relevance
25 [int relevance = COMPLETION_RELEVANCE_DEFAULT]) { 25 = COMPLETION_RELEVANCE_DEFAULT]) {
26 Set<Keyword> actualKeywords = new Set<Keyword>(); 26 Set<Keyword> actualKeywords = new Set<Keyword>();
27 request.suggestions.forEach((CompletionSuggestion s) { 27 request.suggestions.forEach((CompletionSuggestion s) {
28 if (s.kind == CompletionSuggestionKind.KEYWORD) { 28 if (s.kind == CompletionSuggestionKind.KEYWORD) {
29 Keyword k = Keyword.keywords[s.completion]; 29 Keyword k = Keyword.keywords[s.completion];
30 if (k == null) { 30 if (k == null) {
31 fail('Invalid keyword suggested: ${s.completion}'); 31 fail('Invalid keyword suggested: ${s.completion}');
32 } else { 32 } else {
33 if (!actualKeywords.add(k)) { 33 if (!actualKeywords.add(k)) {
34 fail('Duplicate keyword suggested: ${s.completion}'); 34 fail('Duplicate keyword suggested: ${s.completion}');
35 } 35 }
36 } 36 }
37 expect(s.relevance, equals(relevance)); 37 expect(s.relevance, equals(relevance), reason: k.toString());
38 expect(s.selectionOffset, equals(s.completion.length)); 38 expect(s.selectionOffset, equals(s.completion.length));
39 expect(s.selectionLength, equals(0)); 39 expect(s.selectionLength, equals(0));
40 expect(s.isDeprecated, equals(false)); 40 expect(s.isDeprecated, equals(false));
41 expect(s.isPotential, equals(false)); 41 expect(s.isPotential, equals(false));
42 } 42 }
43 }); 43 });
44 if (expectedKeywords.any((k) => k is String)) { 44 if (expectedKeywords.any((k) => k is String)) {
45 StringBuffer msg = new StringBuffer(); 45 StringBuffer msg = new StringBuffer();
46 msg.writeln('Expected set should be:'); 46 msg.writeln('Expected set should be:');
47 expectedKeywords.forEach((n) { 47 expectedKeywords.forEach((n) {
(...skipping 24 matching lines...) Expand all
72 [ 72 [
73 Keyword.ABSTRACT, 73 Keyword.ABSTRACT,
74 Keyword.CLASS, 74 Keyword.CLASS,
75 Keyword.CONST, 75 Keyword.CONST,
76 Keyword.FINAL, 76 Keyword.FINAL,
77 Keyword.TYPEDEF, 77 Keyword.TYPEDEF,
78 Keyword.VAR], 78 Keyword.VAR],
79 COMPLETION_RELEVANCE_HIGH); 79 COMPLETION_RELEVANCE_HIGH);
80 } 80 }
81 81
82 test_after_class2() {
83 addTestSource('class A {} c^');
84 expect(computeFast(), isTrue);
85 assertSuggestKeywords(
86 [
87 Keyword.ABSTRACT,
88 Keyword.CLASS,
89 Keyword.CONST,
90 Keyword.FINAL,
91 Keyword.TYPEDEF,
92 Keyword.VAR],
93 COMPLETION_RELEVANCE_HIGH);
94 }
95
96 test_after_import() {
97 addTestSource('import foo; ^');
98 expect(computeFast(), isTrue);
99 assertSuggestKeywords(
100 [
101 Keyword.ABSTRACT,
102 Keyword.CLASS,
103 Keyword.CONST,
104 Keyword.EXPORT,
105 Keyword.FINAL,
106 Keyword.IMPORT,
107 Keyword.PART,
108 Keyword.TYPEDEF,
109 Keyword.VAR],
110 COMPLETION_RELEVANCE_HIGH);
111 }
112
113 test_after_import2() {
114 addTestSource('import foo; c^');
115 expect(computeFast(), isTrue);
116 assertSuggestKeywords(
117 [
118 Keyword.ABSTRACT,
119 Keyword.CLASS,
120 Keyword.CONST,
121 Keyword.EXPORT,
122 Keyword.FINAL,
123 Keyword.IMPORT,
124 Keyword.PART,
125 Keyword.TYPEDEF,
126 Keyword.VAR],
127 COMPLETION_RELEVANCE_HIGH);
128 }
129
82 test_before_import() { 130 test_before_import() {
83 addTestSource('^ import foo;'); 131 addTestSource('^ import foo;');
84 expect(computeFast(), isTrue); 132 expect(computeFast(), isTrue);
85 assertSuggestKeywords( 133 assertSuggestKeywords(
86 [Keyword.EXPORT, Keyword.IMPORT, Keyword.LIBRARY, Keyword.PART], 134 [Keyword.EXPORT, Keyword.IMPORT, Keyword.LIBRARY, Keyword.PART],
87 COMPLETION_RELEVANCE_HIGH); 135 COMPLETION_RELEVANCE_HIGH);
88 } 136 }
89 137
90 test_class() { 138 test_class() {
91 addTestSource('class A ^'); 139 addTestSource('class A ^');
92 expect(computeFast(), isTrue); 140 expect(computeFast(), isTrue);
93 assertSuggestKeywords( 141 assertSuggestKeywords(
94 [Keyword.EXTENDS, Keyword.IMPLEMENTS], 142 [Keyword.EXTENDS, Keyword.IMPLEMENTS],
95 COMPLETION_RELEVANCE_HIGH); 143 COMPLETION_RELEVANCE_HIGH);
96 } 144 }
97 145
146 test_class2() {
147 addTestSource('class A e^');
148 expect(computeFast(), isTrue);
149 assertSuggestKeywords(
150 [Keyword.EXTENDS, Keyword.IMPLEMENTS],
151 COMPLETION_RELEVANCE_HIGH);
152 }
153
154 test_class3() {
155 addTestSource('class A e^ { }');
156 expect(computeFast(), isTrue);
157 assertSuggestKeywords(
158 [Keyword.EXTENDS, Keyword.IMPLEMENTS],
159 COMPLETION_RELEVANCE_HIGH);
160 }
161
98 test_class_extends() { 162 test_class_extends() {
99 addTestSource('class A extends foo ^'); 163 addTestSource('class A extends foo ^');
100 expect(computeFast(), isTrue); 164 expect(computeFast(), isTrue);
101 assertSuggestKeywords( 165 assertSuggestKeywords(
102 [Keyword.IMPLEMENTS, Keyword.WITH], 166 [Keyword.IMPLEMENTS, Keyword.WITH],
103 COMPLETION_RELEVANCE_HIGH); 167 COMPLETION_RELEVANCE_HIGH);
104 } 168 }
105 169
170 test_class_extends2() {
171 addTestSource('class A extends foo i^');
172 expect(computeFast(), isTrue);
173 assertSuggestKeywords(
174 [Keyword.IMPLEMENTS, Keyword.WITH],
175 COMPLETION_RELEVANCE_HIGH);
176 }
177
178 test_class_extends3() {
179 addTestSource('class A extends foo i^ { }');
180 expect(computeFast(), isTrue);
181 assertSuggestKeywords(
182 [Keyword.IMPLEMENTS, Keyword.WITH],
183 COMPLETION_RELEVANCE_HIGH);
184 }
185
106 test_class_extends_name() { 186 test_class_extends_name() {
107 addTestSource('class A extends ^'); 187 addTestSource('class A extends ^');
108 expect(computeFast(), isTrue); 188 expect(computeFast(), isTrue);
109 assertSuggestKeywords([]); 189 assertSuggestKeywords([]);
110 } 190 }
111 191
112 test_class_implements() { 192 test_class_implements() {
113 addTestSource('class A ^ implements foo'); 193 addTestSource('class A ^ implements foo');
114 expect(computeFast(), isTrue); 194 expect(computeFast(), isTrue);
115 assertSuggestKeywords([Keyword.EXTENDS], COMPLETION_RELEVANCE_HIGH); 195 assertSuggestKeywords([Keyword.EXTENDS], COMPLETION_RELEVANCE_HIGH);
116 } 196 }
117 197
198 test_class_implements2() {
199 addTestSource('class A e^ implements foo');
200 expect(computeFast(), isTrue);
201 // TODO (danrubel) refinement: don't suggest implements
202 assertSuggestKeywords(
203 [Keyword.EXTENDS, Keyword.IMPLEMENTS],
204 COMPLETION_RELEVANCE_HIGH);
205 }
206
207 test_class_implements3() {
208 addTestSource('class A e^ implements foo { }');
209 expect(computeFast(), isTrue);
210 // TODO (danrubel) refinement: don't suggest implements
211 assertSuggestKeywords(
212 [Keyword.EXTENDS, Keyword.IMPLEMENTS],
213 COMPLETION_RELEVANCE_HIGH);
214 }
215
118 test_class_implements_name() { 216 test_class_implements_name() {
119 addTestSource('class A implements ^'); 217 addTestSource('class A implements ^');
120 expect(computeFast(), isTrue); 218 expect(computeFast(), isTrue);
121 assertSuggestKeywords([]); 219 assertSuggestKeywords([]);
122 } 220 }
123 221
124 test_class_name() { 222 test_class_name() {
125 addTestSource('class ^'); 223 addTestSource('class ^');
126 expect(computeFast(), isTrue); 224 expect(computeFast(), isTrue);
127 assertSuggestKeywords([]); 225 assertSuggestKeywords([]);
128 } 226 }
129 227
228 test_class_with() {
229 addTestSource('class A extends foo with bar ^');
230 expect(computeFast(), isTrue);
231 assertSuggestKeywords([Keyword.IMPLEMENTS], COMPLETION_RELEVANCE_HIGH);
232 }
233
234 test_class_with2() {
235 addTestSource('class A extends foo with bar i^');
236 expect(computeFast(), isTrue);
237 assertSuggestKeywords([Keyword.IMPLEMENTS], COMPLETION_RELEVANCE_HIGH);
238 }
239
240 test_class_with3() {
241 addTestSource('class A extends foo with bar i^ { }');
242 expect(computeFast(), isTrue);
243 assertSuggestKeywords([Keyword.IMPLEMENTS], COMPLETION_RELEVANCE_HIGH);
244 }
245
130 test_class_with_name() { 246 test_class_with_name() {
131 addTestSource('class A extends foo with ^'); 247 addTestSource('class A extends foo with ^');
132 expect(computeFast(), isTrue); 248 expect(computeFast(), isTrue);
133 assertSuggestKeywords([]); 249 assertSuggestKeywords([]);
134 } 250 }
135 251
136 test_empty() { 252 test_empty() {
137 addTestSource('^'); 253 addTestSource('^');
138 expect(computeFast(), isTrue); 254 expect(computeFast(), isTrue);
139 assertSuggestKeywords( 255 assertSuggestKeywords(
(...skipping 30 matching lines...) Expand all
170 Keyword.SUPER, 286 Keyword.SUPER,
171 Keyword.SWITCH, 287 Keyword.SWITCH,
172 Keyword.THIS, 288 Keyword.THIS,
173 Keyword.THROW, 289 Keyword.THROW,
174 Keyword.TRY, 290 Keyword.TRY,
175 Keyword.VAR, 291 Keyword.VAR,
176 Keyword.VOID, 292 Keyword.VOID,
177 Keyword.WHILE]); 293 Keyword.WHILE]);
178 } 294 }
179 295
296 test_function_body2() {
297 addTestSource('main() {{}^}');
298 expect(computeFast(), isTrue);
299 assertSuggestKeywords(
300 [
301 Keyword.ASSERT,
302 Keyword.CASE,
303 Keyword.CONTINUE,
304 Keyword.DO,
305 Keyword.FACTORY,
306 Keyword.FINAL,
307 Keyword.FOR,
308 Keyword.IF,
309 Keyword.NEW,
310 Keyword.RETHROW,
311 Keyword.RETURN,
312 Keyword.SUPER,
313 Keyword.SWITCH,
314 Keyword.THIS,
315 Keyword.THROW,
316 Keyword.TRY,
317 Keyword.VAR,
318 Keyword.VOID,
319 Keyword.WHILE]);
320 }
321
180 test_in_class() { 322 test_in_class() {
181 addTestSource('class A {^}'); 323 addTestSource('class A {^}');
182 expect(computeFast(), isTrue); 324 expect(computeFast(), isTrue);
183 assertSuggestKeywords( 325 assertSuggestKeywords(
184 [ 326 [
185 Keyword.CONST, 327 Keyword.CONST,
186 Keyword.DYNAMIC, 328 Keyword.DYNAMIC,
187 Keyword.FACTORY, 329 Keyword.FACTORY,
188 Keyword.FINAL, 330 Keyword.FINAL,
189 Keyword.GET, 331 Keyword.GET,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); 449 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},'));
308 } 450 }
309 451
310 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { 452 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) {
311 if (iter1.length != iter2.length) return false; 453 if (iter1.length != iter2.length) return false;
312 if (iter1.any((k) => !iter2.contains(k))) return false; 454 if (iter1.any((k) => !iter2.contains(k))) return false;
313 if (iter2.any((k) => !iter1.contains(k))) return false; 455 if (iter2.any((k) => !iter1.contains(k))) return false;
314 return true; 456 return true;
315 } 457 }
316 } 458 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/keyword_computer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698