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

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

Issue 935123002: Issue 21879. Don't include 'this' and 'super' keywords if not in a method/constructor body. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 static const List<Keyword> IN_BLOCK_IN_CLASS =
24 const [
25 Keyword.ASSERT,
26 Keyword.CASE,
27 Keyword.CONTINUE,
28 Keyword.DO,
29 Keyword.FINAL,
30 Keyword.FOR,
31 Keyword.IF,
32 Keyword.NEW,
33 Keyword.RETHROW,
34 Keyword.RETURN,
35 Keyword.SUPER,
36 Keyword.SWITCH,
37 Keyword.THIS,
38 Keyword.THROW,
39 Keyword.TRY,
40 Keyword.VAR,
41 Keyword.VOID,
42 Keyword.WHILE];
43
44 static const List<Keyword> IN_BLOCK_NOT_IN_CLASS =
45 const [
46 Keyword.ASSERT,
47 Keyword.CASE,
48 Keyword.CONTINUE,
49 Keyword.DO,
50 Keyword.FINAL,
51 Keyword.FOR,
52 Keyword.IF,
53 Keyword.NEW,
54 Keyword.RETHROW,
55 Keyword.RETURN,
56 Keyword.SWITCH,
57 Keyword.THROW,
58 Keyword.TRY,
59 Keyword.VAR,
60 Keyword.VOID,
61 Keyword.WHILE];
23 62
24 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, [int relevance 63 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, [int relevance
25 = DART_RELEVANCE_KEYWORD]) { 64 = DART_RELEVANCE_KEYWORD]) {
26 Set<Keyword> actualKeywords = new Set<Keyword>(); 65 Set<Keyword> actualKeywords = new Set<Keyword>();
27 request.suggestions.forEach((CompletionSuggestion s) { 66 request.suggestions.forEach((CompletionSuggestion s) {
28 if (s.kind == CompletionSuggestionKind.KEYWORD) { 67 if (s.kind == CompletionSuggestionKind.KEYWORD) {
29 Keyword k = Keyword.keywords[s.completion]; 68 Keyword k = Keyword.keywords[s.completion];
30 if (k == null) { 69 if (k == null) {
31 fail('Invalid keyword suggested: ${s.completion}'); 70 fail('Invalid keyword suggested: ${s.completion}');
32 } else { 71 } else {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 Keyword.EXPORT, 299 Keyword.EXPORT,
261 Keyword.FINAL, 300 Keyword.FINAL,
262 Keyword.IMPORT, 301 Keyword.IMPORT,
263 Keyword.LIBRARY, 302 Keyword.LIBRARY,
264 Keyword.PART, 303 Keyword.PART,
265 Keyword.TYPEDEF, 304 Keyword.TYPEDEF,
266 Keyword.VAR], 305 Keyword.VAR],
267 DART_RELEVANCE_HIGH); 306 DART_RELEVANCE_HIGH);
268 } 307 }
269 308
270 test_function_body() { 309 test_function_body_inClass_constructorInitializer() {
310 addTestSource(r'''
311 foo(p) {}
312 class A {
313 final f;
314 A() : f = foo(() {^});
315 }
316 ''');
317 expect(computeFast(), isTrue);
318 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS);
319 }
320
321 test_function_body_inClass_field() {
322 addTestSource(r'''
323 class A {
324 var f = () {^};
325 }
326 ''');
327 expect(computeFast(), isTrue);
328 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS);
329 }
330
331 test_function_body_inClass_methodBody() {
332 addTestSource(r'''
333 class A {
334 m() {
335 f() {^};
336 }
337 }
338 ''');
339 expect(computeFast(), isTrue);
340 assertSuggestKeywords(IN_BLOCK_IN_CLASS);
341 }
342
343 test_function_body_inClass_methodBody_inFunction() {
344 addTestSource(r'''
345 class A {
346 m() {
347 f() {
348 f2() {^};
349 };
350 }
351 }
352 ''');
353 expect(computeFast(), isTrue);
354 assertSuggestKeywords(IN_BLOCK_IN_CLASS);
355 }
356
357 test_function_body_inUnit() {
271 addTestSource('main() {^}'); 358 addTestSource('main() {^}');
272 expect(computeFast(), isTrue); 359 expect(computeFast(), isTrue);
273 assertSuggestKeywords( 360 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS);
274 [
275 Keyword.ASSERT,
276 Keyword.CASE,
277 Keyword.CONTINUE,
278 Keyword.DO,
279 Keyword.FACTORY,
280 Keyword.FINAL,
281 Keyword.FOR,
282 Keyword.IF,
283 Keyword.NEW,
284 Keyword.RETHROW,
285 Keyword.RETURN,
286 Keyword.SUPER,
287 Keyword.SWITCH,
288 Keyword.THIS,
289 Keyword.THROW,
290 Keyword.TRY,
291 Keyword.VAR,
292 Keyword.VOID,
293 Keyword.WHILE]);
294 } 361 }
295 362
296 test_function_body2() { 363 test_function_body_inUnit_afterBlock() {
297 addTestSource('main() {{}^}'); 364 addTestSource('main() {{}^}');
298 expect(computeFast(), isTrue); 365 expect(computeFast(), isTrue);
299 assertSuggestKeywords( 366 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS);
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 } 367 }
321 368
322 test_in_class() { 369 test_in_class() {
323 addTestSource('class A {^}'); 370 addTestSource('class A {^}');
324 expect(computeFast(), isTrue); 371 expect(computeFast(), isTrue);
325 assertSuggestKeywords( 372 assertSuggestKeywords(
326 [ 373 [
327 Keyword.CONST, 374 Keyword.CONST,
328 Keyword.DYNAMIC, 375 Keyword.DYNAMIC,
329 Keyword.FACTORY, 376 Keyword.FACTORY,
(...skipping 25 matching lines...) Expand all
355 402
356 test_library_name() { 403 test_library_name() {
357 addTestSource('library ^'); 404 addTestSource('library ^');
358 expect(computeFast(), isTrue); 405 expect(computeFast(), isTrue);
359 assertSuggestKeywords([]); 406 assertSuggestKeywords([]);
360 } 407 }
361 408
362 test_method_body() { 409 test_method_body() {
363 addTestSource('class A { foo() {^}}'); 410 addTestSource('class A { foo() {^}}');
364 expect(computeFast(), isTrue); 411 expect(computeFast(), isTrue);
365 assertSuggestKeywords( 412 assertSuggestKeywords(IN_BLOCK_IN_CLASS);
366 [
367 Keyword.ASSERT,
368 Keyword.CASE,
369 Keyword.CONTINUE,
370 Keyword.DO,
371 Keyword.FACTORY,
372 Keyword.FINAL,
373 Keyword.FOR,
374 Keyword.IF,
375 Keyword.NEW,
376 Keyword.RETHROW,
377 Keyword.RETURN,
378 Keyword.SUPER,
379 Keyword.SWITCH,
380 Keyword.THIS,
381 Keyword.THROW,
382 Keyword.TRY,
383 Keyword.VAR,
384 Keyword.VOID,
385 Keyword.WHILE]);
386 } 413 }
387 414
388 test_named_constructor_invocation() { 415 test_named_constructor_invocation() {
389 addTestSource('void main() {new Future.^}'); 416 addTestSource('void main() {new Future.^}');
390 expect(computeFast(), isTrue); 417 expect(computeFast(), isTrue);
391 assertSuggestKeywords([]); 418 assertSuggestKeywords([]);
392 } 419 }
393 420
394 test_part_of() { 421 test_part_of() {
395 addTestSource('part of foo;^'); 422 addTestSource('part of foo;^');
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); 476 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},'));
450 } 477 }
451 478
452 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { 479 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) {
453 if (iter1.length != iter2.length) return false; 480 if (iter1.length != iter2.length) return false;
454 if (iter1.any((k) => !iter2.contains(k))) return false; 481 if (iter1.any((k) => !iter2.contains(k))) return false;
455 if (iter2.any((k) => !iter1.contains(k))) return false; 482 if (iter2.any((k) => !iter1.contains(k))) return false;
456 return true; 483 return true;
457 } 484 }
458 } 485 }
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