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

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

Issue 1054363003: replace request.node with request.target (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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/test/services/completion/completion_test_util.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';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 Keyword.THROW, 56 Keyword.THROW,
57 Keyword.TRY, 57 Keyword.TRY,
58 Keyword.VAR, 58 Keyword.VAR,
59 Keyword.VOID, 59 Keyword.VOID,
60 Keyword.WHILE 60 Keyword.WHILE
61 ]; 61 ];
62 62
63 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, 63 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords,
64 [int relevance = DART_RELEVANCE_KEYWORD]) { 64 [int relevance = DART_RELEVANCE_KEYWORD]) {
65 Set<Keyword> actualKeywords = new Set<Keyword>(); 65 Set<Keyword> actualKeywords = new Set<Keyword>();
66 request.suggestions.forEach((CompletionSuggestion s) { 66 for (CompletionSuggestion s in request.suggestions) {
67 if (s.kind == CompletionSuggestionKind.KEYWORD) { 67 if (s.kind == CompletionSuggestionKind.KEYWORD) {
68 Keyword k = Keyword.keywords[s.completion]; 68 Keyword k = Keyword.keywords[s.completion];
69 if (k == null) { 69 if (k == null) {
70 fail('Invalid keyword suggested: ${s.completion}'); 70 fail('Invalid keyword suggested: ${s.completion}');
71 } else { 71 } else {
72 if (!actualKeywords.add(k)) { 72 if (!actualKeywords.add(k)) {
73 fail('Duplicate keyword suggested: ${s.completion}'); 73 fail('Duplicate keyword suggested: ${s.completion}');
74 } 74 }
75 } 75 }
76 expect(s.relevance, equals(relevance), reason: k.toString());
77 expect(s.selectionOffset, equals(s.completion.length));
78 expect(s.selectionLength, equals(0));
79 expect(s.isDeprecated, equals(false));
80 expect(s.isPotential, equals(false));
81 } 76 }
82 }); 77 };
83 if (expectedKeywords.any((k) => k is String)) { 78 if (expectedKeywords.any((k) => k is String)) {
84 StringBuffer msg = new StringBuffer(); 79 StringBuffer msg = new StringBuffer();
85 msg.writeln('Expected set should be:'); 80 msg.writeln('Expected set should be:');
86 expectedKeywords.forEach((n) { 81 expectedKeywords.forEach((n) {
87 Keyword k = Keyword.keywords[n]; 82 Keyword k = Keyword.keywords[n];
88 msg.writeln(' Keyword.${k.name},'); 83 msg.writeln(' Keyword.${k.name},');
89 }); 84 });
90 fail(msg.toString()); 85 fail(msg.toString());
91 } 86 }
92 if (!_equalSets(expectedKeywords, actualKeywords)) { 87 if (!_equalSets(expectedKeywords, actualKeywords)) {
93 StringBuffer msg = new StringBuffer(); 88 StringBuffer msg = new StringBuffer();
94 msg.writeln('Expected:'); 89 msg.writeln('Expected:');
95 _appendKeywords(msg, expectedKeywords); 90 _appendKeywords(msg, expectedKeywords);
96 msg.writeln('but found:'); 91 msg.writeln('but found:');
97 _appendKeywords(msg, actualKeywords); 92 _appendKeywords(msg, actualKeywords);
98 fail(msg.toString()); 93 fail(msg.toString());
99 } 94 }
95 for (CompletionSuggestion s in request.suggestions) {
96 if (s.kind == CompletionSuggestionKind.KEYWORD) {
97 Keyword k = Keyword.keywords[s.completion];
98 expect(s.relevance, equals(relevance), reason: k.toString());
99 expect(s.selectionOffset, equals(s.completion.length));
100 expect(s.selectionLength, equals(0));
101 expect(s.isDeprecated, equals(false));
102 expect(s.isPotential, equals(false));
103 }
104 };
100 } 105 }
101 106
102 @override 107 @override
103 void setUpComputer() { 108 void setUpComputer() {
104 computer = new KeywordComputer(); 109 computer = new KeywordComputer();
105 } 110 }
106 111
107 test_after_class() { 112 test_after_class() {
108 addTestSource('class A {} ^'); 113 addTestSource('class A {} ^');
109 expect(computeFast(), isTrue); 114 expect(computeFast(), isTrue);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 addTestSource('^ import foo;'); 171 addTestSource('^ import foo;');
167 expect(computeFast(), isTrue); 172 expect(computeFast(), isTrue);
168 assertSuggestKeywords([ 173 assertSuggestKeywords([
169 Keyword.EXPORT, 174 Keyword.EXPORT,
170 Keyword.IMPORT, 175 Keyword.IMPORT,
171 Keyword.LIBRARY, 176 Keyword.LIBRARY,
172 Keyword.PART 177 Keyword.PART
173 ], DART_RELEVANCE_HIGH); 178 ], DART_RELEVANCE_HIGH);
174 } 179 }
175 180
176 test_class() { 181 test_class4() {
177 addTestSource('class A ^');
178 expect(computeFast(), isTrue);
179 assertSuggestKeywords(
180 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
181 }
182
183 test_class2() {
184 addTestSource('class A e^');
185 expect(computeFast(), isTrue);
186 assertSuggestKeywords(
187 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
188 }
189
190 test_class3() {
191 addTestSource('class A e^ { }'); 182 addTestSource('class A e^ { }');
192 expect(computeFast(), isTrue); 183 expect(computeFast(), isTrue);
193 assertSuggestKeywords( 184 assertSuggestKeywords(
194 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH); 185 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
195 } 186 }
196 187
197 test_class_extends() { 188 test_class_extends() {
198 addTestSource('class A extends foo ^'); 189 addTestSource('class A extends foo ^');
199 expect(computeFast(), isTrue); 190 expect(computeFast(), isTrue);
200 assertSuggestKeywords( 191 assertSuggestKeywords(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 expect(computeFast(), isTrue); 239 expect(computeFast(), isTrue);
249 assertSuggestKeywords([]); 240 assertSuggestKeywords([]);
250 } 241 }
251 242
252 test_class_name() { 243 test_class_name() {
253 addTestSource('class ^'); 244 addTestSource('class ^');
254 expect(computeFast(), isTrue); 245 expect(computeFast(), isTrue);
255 assertSuggestKeywords([]); 246 assertSuggestKeywords([]);
256 } 247 }
257 248
249 test_class_noBody() {
250 addTestSource('class A ^');
251 expect(computeFast(), isTrue);
252 assertSuggestKeywords(
253 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
254 }
255
256 test_class_noBody2() {
257 addTestSource('class A e^');
258 expect(computeFast(), isTrue);
259 assertSuggestKeywords(
260 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
261 }
262
263 test_class_noBody3() {
264 addTestSource('class A e^ String foo;');
265 expect(computeFast(), isTrue);
266 assertSuggestKeywords(
267 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
268 }
269
258 test_class_with() { 270 test_class_with() {
259 addTestSource('class A extends foo with bar ^'); 271 addTestSource('class A extends foo with bar ^');
260 expect(computeFast(), isTrue); 272 expect(computeFast(), isTrue);
261 assertSuggestKeywords([Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH); 273 assertSuggestKeywords([Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
262 } 274 }
263 275
264 test_class_with2() { 276 test_class_with2() {
265 addTestSource('class A extends foo with bar i^'); 277 addTestSource('class A extends foo with bar i^');
266 expect(computeFast(), isTrue); 278 expect(computeFast(), isTrue);
267 assertSuggestKeywords([Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH); 279 assertSuggestKeywords([Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); 474 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},'));
463 } 475 }
464 476
465 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { 477 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) {
466 if (iter1.length != iter2.length) return false; 478 if (iter1.length != iter2.length) return false;
467 if (iter1.any((k) => !iter2.contains(k))) return false; 479 if (iter1.any((k) => !iter2.contains(k))) return false;
468 if (iter2.any((k) => !iter1.contains(k))) return false; 480 if (iter2.any((k) => !iter1.contains(k))) return false;
469 return true; 481 return true;
470 } 482 }
471 } 483 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/completion/completion_test_util.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698