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

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

Issue 1471173003: hook new DartCompletionContributor API into existing framework (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.services.completion.dart.keyword;
6
7 import 'package:analysis_server/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
10 import 'package:analyzer/src/generated/scanner.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 import 'package:unittest/unittest.dart';
13
14 import '../../utils.dart';
15 import 'completion_test_util.dart';
16
17 main() {
18 initializeTestEnvironment();
19 defineReflectiveTests(KeywordContributorTest);
20 }
21
22 @reflectiveTest
23 class KeywordContributorTest extends AbstractCompletionTest {
24 static const List<Keyword> CLASS_BODY_KEYWORDS = const [
25 Keyword.CONST,
26 Keyword.DYNAMIC,
27 Keyword.FACTORY,
28 Keyword.FINAL,
29 Keyword.GET,
30 Keyword.OPERATOR,
31 Keyword.SET,
32 Keyword.STATIC,
33 Keyword.VAR,
34 Keyword.VOID
35 ];
36
37 static const List<Keyword> DECLARATION_KEYWORDS = const [
38 Keyword.ABSTRACT,
39 Keyword.CLASS,
40 Keyword.CONST,
41 Keyword.DYNAMIC,
42 Keyword.FINAL,
43 Keyword.TYPEDEF,
44 Keyword.VAR,
45 Keyword.VOID
46 ];
47
48 static const List<Keyword> DIRECTIVE_AND_DECLARATION_KEYWORDS = const [
49 Keyword.ABSTRACT,
50 Keyword.CLASS,
51 Keyword.CONST,
52 Keyword.DYNAMIC,
53 Keyword.EXPORT,
54 Keyword.FINAL,
55 Keyword.IMPORT,
56 Keyword.PART,
57 Keyword.TYPEDEF,
58 Keyword.VAR,
59 Keyword.VOID
60 ];
61
62 static const List<Keyword> DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS =
63 const [
64 Keyword.ABSTRACT,
65 Keyword.CLASS,
66 Keyword.CONST,
67 Keyword.DYNAMIC,
68 Keyword.EXPORT,
69 Keyword.FINAL,
70 Keyword.IMPORT,
71 Keyword.LIBRARY,
72 Keyword.PART,
73 Keyword.TYPEDEF,
74 Keyword.VAR,
75 Keyword.VOID
76 ];
77
78 static const List<String> NO_PSEUDO_KEYWORDS = const [];
79
80 static const List<Keyword> STMT_START_IN_CLASS = const [
81 Keyword.ASSERT,
82 Keyword.CONST,
83 Keyword.DO,
84 Keyword.FINAL,
85 Keyword.FOR,
86 Keyword.IF,
87 Keyword.NEW,
88 Keyword.RETURN,
89 Keyword.SUPER,
90 Keyword.SWITCH,
91 Keyword.THIS,
92 Keyword.THROW,
93 Keyword.TRY,
94 Keyword.VAR,
95 Keyword.VOID,
96 Keyword.WHILE
97 ];
98
99 static const List<Keyword> STMT_START_IN_LOOP_IN_CLASS = const [
100 Keyword.ASSERT,
101 Keyword.BREAK,
102 Keyword.CONST,
103 Keyword.CONTINUE,
104 Keyword.DO,
105 Keyword.FINAL,
106 Keyword.FOR,
107 Keyword.IF,
108 Keyword.NEW,
109 Keyword.RETURN,
110 Keyword.SUPER,
111 Keyword.SWITCH,
112 Keyword.THIS,
113 Keyword.THROW,
114 Keyword.TRY,
115 Keyword.VAR,
116 Keyword.VOID,
117 Keyword.WHILE
118 ];
119
120 static const List<Keyword> STMT_START_IN_SWITCH_IN_CLASS = const [
121 Keyword.ASSERT,
122 Keyword.BREAK,
123 Keyword.CASE,
124 Keyword.CONST,
125 Keyword.DEFAULT,
126 Keyword.DO,
127 Keyword.FINAL,
128 Keyword.FOR,
129 Keyword.IF,
130 Keyword.NEW,
131 Keyword.RETURN,
132 Keyword.SUPER,
133 Keyword.SWITCH,
134 Keyword.THIS,
135 Keyword.THROW,
136 Keyword.TRY,
137 Keyword.VAR,
138 Keyword.VOID,
139 Keyword.WHILE
140 ];
141
142 static const List<Keyword> STMT_START_IN_SWITCH_OUTSIDE_CLASS = const [
143 Keyword.ASSERT,
144 Keyword.BREAK,
145 Keyword.CASE,
146 Keyword.CONST,
147 Keyword.DEFAULT,
148 Keyword.DO,
149 Keyword.FINAL,
150 Keyword.FOR,
151 Keyword.IF,
152 Keyword.NEW,
153 Keyword.RETURN,
154 Keyword.SWITCH,
155 Keyword.THROW,
156 Keyword.TRY,
157 Keyword.VAR,
158 Keyword.VOID,
159 Keyword.WHILE
160 ];
161
162 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [
163 Keyword.ASSERT,
164 Keyword.CONST,
165 Keyword.DO,
166 Keyword.FINAL,
167 Keyword.FOR,
168 Keyword.IF,
169 Keyword.NEW,
170 Keyword.RETURN,
171 Keyword.SWITCH,
172 Keyword.THROW,
173 Keyword.TRY,
174 Keyword.VAR,
175 Keyword.VOID,
176 Keyword.WHILE
177 ];
178
179 static const List<Keyword> STMT_START_IN_LOOP_OUTSIDE_CLASS = const [
180 Keyword.ASSERT,
181 Keyword.BREAK,
182 Keyword.CONST,
183 Keyword.CONTINUE,
184 Keyword.DO,
185 Keyword.FINAL,
186 Keyword.FOR,
187 Keyword.IF,
188 Keyword.NEW,
189 Keyword.RETURN,
190 Keyword.SWITCH,
191 Keyword.THROW,
192 Keyword.TRY,
193 Keyword.VAR,
194 Keyword.VOID,
195 Keyword.WHILE
196 ];
197
198 static const List<Keyword> EXPRESSION_START_INSTANCE = const [
199 Keyword.CONST,
200 Keyword.FALSE,
201 Keyword.NEW,
202 Keyword.NULL,
203 Keyword.SUPER,
204 Keyword.THIS,
205 Keyword.TRUE,
206 ];
207
208 static const List<Keyword> EXPRESSION_START_NO_INSTANCE = const [
209 Keyword.CONST,
210 Keyword.FALSE,
211 Keyword.NEW,
212 Keyword.NULL,
213 Keyword.TRUE,
214 ];
215
216 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords,
217 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS,
218 int relevance: DART_RELEVANCE_KEYWORD}) {
219 Set<String> expectedCompletions = new Set<String>();
220 Map<String, int> expectedOffsets = <String, int>{};
221 Set<String> actualCompletions = new Set<String>();
222 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax));
223 expectedCompletions.addAll(pseudoKeywords);
224 for (CompletionSuggestion s in request.suggestions) {
225 if (s.kind == CompletionSuggestionKind.KEYWORD) {
226 Keyword k = Keyword.keywords[s.completion];
227 if (k == null && !expectedCompletions.contains(s.completion)) {
228 fail('Invalid keyword suggested: ${s.completion}');
229 } else {
230 if (!actualCompletions.add(s.completion)) {
231 fail('Duplicate keyword suggested: ${s.completion}');
232 }
233 }
234 }
235 }
236 if (!_equalSets(expectedCompletions, actualCompletions)) {
237 StringBuffer msg = new StringBuffer();
238 msg.writeln('Expected:');
239 _appendCompletions(msg, expectedCompletions, actualCompletions);
240 msg.writeln('but found:');
241 _appendCompletions(msg, actualCompletions, expectedCompletions);
242 fail(msg.toString());
243 }
244 for (CompletionSuggestion s in request.suggestions) {
245 if (s.kind == CompletionSuggestionKind.KEYWORD) {
246 if (s.completion.startsWith(Keyword.IMPORT.syntax)) {
247 int importRelevance = relevance;
248 if (importRelevance == DART_RELEVANCE_HIGH &&
249 s.completion == "import '';") {
250 ++importRelevance;
251 }
252 expect(s.relevance, equals(importRelevance), reason: s.completion);
253 } else {
254 if (s.completion == Keyword.RETHROW.syntax) {
255 expect(s.relevance, equals(relevance - 1), reason: s.completion);
256 } else {
257 expect(s.relevance, equals(relevance), reason: s.completion);
258 }
259 }
260 int expectedOffset = expectedOffsets[s.completion];
261 if (expectedOffset == null) {
262 expectedOffset = s.completion.length;
263 }
264 expect(s.selectionOffset, equals(expectedOffset));
265 expect(s.selectionLength, equals(0));
266 expect(s.isDeprecated, equals(false));
267 expect(s.isPotential, equals(false));
268 }
269 }
270 }
271
272 fail_import_partial() {
273 addTestSource('imp^ import "package:foo/foo.dart"; import "bar.dart";');
274 expect(computeFast(), isTrue);
275 // TODO(danrubel) should not suggest declaration keywords
276 assertNotSuggested('class');
277 }
278
279 fail_import_partial4() {
280 addTestSource('^ imp import "package:foo/foo.dart";');
281 expect(computeFast(), isTrue);
282 // TODO(danrubel) should not suggest declaration keywords
283 assertNotSuggested('class');
284 }
285
286 fail_import_partial5() {
287 addTestSource('library libA; imp^ import "package:foo/foo.dart";');
288 expect(computeFast(), isTrue);
289 // TODO(danrubel) should not suggest declaration keywords
290 assertNotSuggested('class');
291 }
292
293 fail_import_partial6() {
294 addTestSource(
295 'library bar; import "zoo.dart"; imp^ import "package:foo/foo.dart";');
296 expect(computeFast(), isTrue);
297 // TODO(danrubel) should not suggest declaration keywords
298 assertNotSuggested('class');
299 }
300
301 @override
302 void setUpContributor() {
303 contributor = new KeywordContributor();
304 }
305
306 test_after_class() {
307 addTestSource('class A {} ^');
308 expect(computeFast(), isTrue);
309 assertSuggestKeywords(DECLARATION_KEYWORDS, relevance: DART_RELEVANCE_HIGH);
310 }
311
312 test_after_class2() {
313 addTestSource('class A {} c^');
314 expect(computeFast(), isTrue);
315 assertSuggestKeywords(DECLARATION_KEYWORDS, relevance: DART_RELEVANCE_HIGH);
316 }
317
318 test_after_import() {
319 addTestSource('import "foo"; ^');
320 expect(computeFast(), isTrue);
321 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
322 relevance: DART_RELEVANCE_HIGH);
323 }
324
325 test_after_import2() {
326 addTestSource('import "foo"; c^');
327 expect(computeFast(), isTrue);
328 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
329 relevance: DART_RELEVANCE_HIGH);
330 }
331
332 test_anonymous_function_async() {
333 addTestSource('main() {foo(() ^ {}}}');
334 expect(computeFast(), isTrue);
335 assertSuggestKeywords([],
336 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
337 }
338
339 test_anonymous_function_async2() {
340 addTestSource('main() {foo(() a^ {}}}');
341 expect(computeFast(), isTrue);
342 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, pseudoKeywords: ['async']);
343 }
344
345 test_anonymous_function_async3() {
346 addTestSource('main() {foo(() async ^ {}}}');
347 expect(computeFast(), isTrue);
348 assertSuggestKeywords([]);
349 }
350
351 test_argument() {
352 addTestSource('main() {foo(^);}');
353 expect(computeFast(), isTrue);
354 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
355 }
356
357 test_argument2() {
358 addTestSource('main() {foo(n^);}');
359 expect(computeFast(), isTrue);
360 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
361 }
362
363 test_argument_literal() {
364 addTestSource('main() {foo("^");}');
365 expect(computeFast(), isTrue);
366 assertSuggestKeywords([]);
367 }
368
369 test_argument_named() {
370 addTestSource('main() {foo(bar: ^);}');
371 expect(computeFast(), isTrue);
372 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
373 }
374
375 test_argument_named2() {
376 addTestSource('main() {foo(bar: n^);}');
377 expect(computeFast(), isTrue);
378 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
379 }
380
381 test_argument_named_literal() {
382 addTestSource('main() {foo(bar: "^");}');
383 expect(computeFast(), isTrue);
384 assertSuggestKeywords([]);
385 }
386
387 test_assignment_field() {
388 addTestSource('class A {var foo = ^}');
389 expect(computeFast(), isTrue);
390 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
391 }
392
393 test_assignment_field2() {
394 addTestSource('class A {var foo = n^}');
395 expect(computeFast(), isTrue);
396 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
397 }
398
399 test_assignment_local() {
400 addTestSource('main() {var foo = ^}');
401 expect(computeFast(), isTrue);
402 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
403 }
404
405 test_assignment_local2() {
406 addTestSource('main() {var foo = n^}');
407 expect(computeFast(), isTrue);
408 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
409 }
410
411 test_assignment_local2_async() {
412 addTestSource('main() async {var foo = n^}');
413 expect(computeFast(), isTrue);
414 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE,
415 pseudoKeywords: ['await']);
416 }
417
418 test_assignment_local_async() {
419 addTestSource('main() async {var foo = ^}');
420 expect(computeFast(), isTrue);
421 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE,
422 pseudoKeywords: ['await']);
423 }
424
425 test_before_import() {
426 addTestSource('^ import foo;');
427 expect(computeFast(), isTrue);
428 assertSuggestKeywords(
429 [Keyword.EXPORT, Keyword.IMPORT, Keyword.LIBRARY, Keyword.PART],
430 relevance: DART_RELEVANCE_HIGH);
431 }
432
433 test_catch() {
434 addTestSource('main() {try {} catch (e) {^}}}');
435 expect(computeFast(), isTrue);
436 var keywords = <Keyword>[];
437 keywords.addAll(STMT_START_OUTSIDE_CLASS);
438 keywords.add(Keyword.RETHROW);
439 assertSuggestKeywords(keywords, relevance: DART_RELEVANCE_KEYWORD);
440 }
441
442 test_class() {
443 addTestSource('class A e^ { }');
444 expect(computeFast(), isTrue);
445 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
446 relevance: DART_RELEVANCE_HIGH);
447 }
448
449 test_class_body() {
450 addTestSource('class A {^}');
451 expect(computeFast(), isTrue);
452 assertSuggestKeywords(CLASS_BODY_KEYWORDS);
453 }
454
455 test_class_body_beginning() {
456 addTestSource('class A {^ var foo;}');
457 expect(computeFast(), isTrue);
458 assertSuggestKeywords(CLASS_BODY_KEYWORDS);
459 }
460
461 test_class_body_between() {
462 addTestSource('class A {var bar; ^ var foo;}');
463 expect(computeFast(), isTrue);
464 assertSuggestKeywords(CLASS_BODY_KEYWORDS);
465 }
466
467 test_class_body_end() {
468 addTestSource('class A {var foo; ^}');
469 expect(computeFast(), isTrue);
470 assertSuggestKeywords(CLASS_BODY_KEYWORDS);
471 }
472
473 test_class_extends() {
474 addTestSource('class A extends foo ^');
475 expect(computeFast(), isTrue);
476 assertSuggestKeywords([Keyword.IMPLEMENTS, Keyword.WITH],
477 relevance: DART_RELEVANCE_HIGH);
478 }
479
480 test_class_extends2() {
481 addTestSource('class A extends foo i^');
482 expect(computeFast(), isTrue);
483 assertSuggestKeywords([Keyword.IMPLEMENTS, Keyword.WITH],
484 relevance: DART_RELEVANCE_HIGH);
485 }
486
487 test_class_extends3() {
488 addTestSource('class A extends foo i^ { }');
489 expect(computeFast(), isTrue);
490 assertSuggestKeywords([Keyword.IMPLEMENTS, Keyword.WITH],
491 relevance: DART_RELEVANCE_HIGH);
492 }
493
494 test_class_extends_name() {
495 addTestSource('class A extends ^');
496 expect(computeFast(), isTrue);
497 assertSuggestKeywords([]);
498 }
499
500 test_class_implements() {
501 addTestSource('class A ^ implements foo');
502 expect(computeFast(), isTrue);
503 assertSuggestKeywords([Keyword.EXTENDS], relevance: DART_RELEVANCE_HIGH);
504 }
505
506 test_class_implements2() {
507 addTestSource('class A e^ implements foo');
508 expect(computeFast(), isTrue);
509 // TODO (danrubel) refinement: don't suggest implements
510 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
511 relevance: DART_RELEVANCE_HIGH);
512 }
513
514 test_class_implements3() {
515 addTestSource('class A e^ implements foo { }');
516 expect(computeFast(), isTrue);
517 // TODO (danrubel) refinement: don't suggest implements
518 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
519 relevance: DART_RELEVANCE_HIGH);
520 }
521
522 test_class_implements_name() {
523 addTestSource('class A implements ^');
524 expect(computeFast(), isTrue);
525 assertSuggestKeywords([]);
526 }
527
528 test_class_name() {
529 addTestSource('class ^');
530 expect(computeFast(), isTrue);
531 assertSuggestKeywords([]);
532 }
533
534 test_class_noBody() {
535 addTestSource('class A ^');
536 expect(computeFast(), isTrue);
537 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
538 relevance: DART_RELEVANCE_HIGH);
539 }
540
541 test_class_noBody2() {
542 addTestSource('class A e^');
543 expect(computeFast(), isTrue);
544 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
545 relevance: DART_RELEVANCE_HIGH);
546 }
547
548 test_class_noBody3() {
549 addTestSource('class A e^ String foo;');
550 expect(computeFast(), isTrue);
551 assertSuggestKeywords([Keyword.EXTENDS, Keyword.IMPLEMENTS],
552 relevance: DART_RELEVANCE_HIGH);
553 }
554
555 test_class_with() {
556 addTestSource('class A extends foo with bar ^');
557 expect(computeFast(), isTrue);
558 assertSuggestKeywords([Keyword.IMPLEMENTS], relevance: DART_RELEVANCE_HIGH);
559 }
560
561 test_class_with2() {
562 addTestSource('class A extends foo with bar i^');
563 expect(computeFast(), isTrue);
564 assertSuggestKeywords([Keyword.IMPLEMENTS], relevance: DART_RELEVANCE_HIGH);
565 }
566
567 test_class_with3() {
568 addTestSource('class A extends foo with bar i^ { }');
569 expect(computeFast(), isTrue);
570 assertSuggestKeywords([Keyword.IMPLEMENTS], relevance: DART_RELEVANCE_HIGH);
571 }
572
573 test_class_with_name() {
574 addTestSource('class A extends foo with ^');
575 expect(computeFast(), isTrue);
576 assertSuggestKeywords([]);
577 }
578
579 test_constructor_param() {
580 addTestSource('class A { A(^) {});}');
581 expect(computeFast(), isTrue);
582 assertSuggestKeywords([Keyword.THIS]);
583 }
584
585 test_constructor_param2() {
586 addTestSource('class A { A(t^) {});}');
587 expect(computeFast(), isTrue);
588 assertSuggestKeywords([Keyword.THIS]);
589 }
590
591 test_do_break_continue() {
592 addTestSource('main() {do {^} while (true);}');
593 expect(computeFast(), isTrue);
594 assertSuggestKeywords(STMT_START_IN_LOOP_OUTSIDE_CLASS,
595 relevance: DART_RELEVANCE_KEYWORD);
596 }
597
598 test_do_break_continue2() {
599 addTestSource('class A {foo() {do {^} while (true);}}');
600 expect(computeFast(), isTrue);
601 assertSuggestKeywords(STMT_START_IN_LOOP_IN_CLASS,
602 relevance: DART_RELEVANCE_KEYWORD);
603 }
604
605 test_empty() {
606 addTestSource('^');
607 expect(computeFast(), isTrue);
608 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
609 relevance: DART_RELEVANCE_HIGH);
610 }
611
612 test_for_break_continue() {
613 addTestSource('main() {for (int x in myList) {^}}');
614 expect(computeFast(), isTrue);
615 assertSuggestKeywords(STMT_START_IN_LOOP_OUTSIDE_CLASS,
616 relevance: DART_RELEVANCE_KEYWORD);
617 }
618
619 test_for_break_continue2() {
620 addTestSource('class A {foo() {for (int x in myList) {^}}}');
621 expect(computeFast(), isTrue);
622 assertSuggestKeywords(STMT_START_IN_LOOP_IN_CLASS,
623 relevance: DART_RELEVANCE_KEYWORD);
624 }
625
626 test_for_expression_in() {
627 addTestSource('main() {for (int x i^)}');
628 expect(computeFast(), isTrue);
629 assertSuggestKeywords([Keyword.IN], relevance: DART_RELEVANCE_HIGH);
630 }
631
632 test_for_expression_in2() {
633 addTestSource('main() {for (int x in^)}');
634 expect(computeFast(), isTrue);
635 assertSuggestKeywords([Keyword.IN], relevance: DART_RELEVANCE_HIGH);
636 }
637
638 test_for_expression_init() {
639 addTestSource('main() {for (int x = i^)}');
640 expect(computeFast(), isTrue);
641 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
642 }
643
644 test_for_expression_init2() {
645 addTestSource('main() {for (int x = in^)}');
646 expect(computeFast(), isTrue);
647 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
648 }
649
650 test_function_async() {
651 addTestSource('main()^');
652 expect(computeFast(), isTrue);
653 assertSuggestKeywords(DECLARATION_KEYWORDS,
654 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
655 }
656
657 test_function_async2() {
658 addTestSource('main()^{}');
659 expect(computeFast(), isTrue);
660 assertSuggestKeywords([],
661 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
662 }
663
664 test_function_async3() {
665 addTestSource('main()a^');
666 expect(computeFast(), isTrue);
667 assertSuggestKeywords(DECLARATION_KEYWORDS,
668 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
669 }
670
671 test_function_async4() {
672 addTestSource('main()a^{}');
673 expect(computeFast(), isTrue);
674 assertSuggestKeywords(DECLARATION_KEYWORDS,
675 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
676 }
677
678 test_function_async5() {
679 addTestSource('main()a^ Foo foo;');
680 expect(computeFast(), isTrue);
681 assertSuggestKeywords(DECLARATION_KEYWORDS,
682 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
683 }
684
685 test_function_body_inClass_constructorInitializer() {
686 addTestSource(r'''
687 foo(p) {}
688 class A {
689 final f;
690 A() : f = foo(() {^});
691 }
692 ''');
693 expect(computeFast(), isTrue);
694 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
695 }
696
697 test_function_body_inClass_constructorInitializer_async() {
698 addTestSource(r'''
699 foo(p) {}
700 class A {
701 final f;
702 A() : f = foo(() async {^});
703 }
704 ''');
705 expect(computeFast(), isTrue);
706 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, pseudoKeywords: ['await']);
707 }
708
709 test_function_body_inClass_field() {
710 addTestSource(r'''
711 class A {
712 var f = () {^};
713 }
714 ''');
715 expect(computeFast(), isTrue);
716 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
717 }
718
719 test_function_body_inClass_methodBody() {
720 addTestSource(r'''
721 class A {
722 m() {
723 f() {^};
724 }
725 }
726 ''');
727 expect(computeFast(), isTrue);
728 assertSuggestKeywords(STMT_START_IN_CLASS);
729 }
730
731 test_function_body_inClass_methodBody_inFunction() {
732 addTestSource(r'''
733 class A {
734 m() {
735 f() {
736 f2() {^};
737 };
738 }
739 }
740 ''');
741 expect(computeFast(), isTrue);
742 assertSuggestKeywords(STMT_START_IN_CLASS);
743 }
744
745 test_function_body_inClass_methodBody_inFunction_async() {
746 addTestSource(r'''
747 class A {
748 m() {
749 f() {
750 f2() async {^};
751 };
752 }
753 }
754 ''');
755 expect(computeFast(), isTrue);
756 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']);
757 }
758
759 test_function_body_inUnit() {
760 addTestSource('main() {^}');
761 expect(computeFast(), isTrue);
762 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
763 }
764
765 test_function_body_inUnit_afterBlock() {
766 addTestSource('main() {{}^}');
767 expect(computeFast(), isTrue);
768 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
769 }
770
771 test_function_body_inUnit_async() {
772 addTestSource('main() async {^}');
773 expect(computeFast(), isTrue);
774 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, pseudoKeywords: ['await']);
775 }
776
777 test_if_expression_in_class() {
778 addTestSource('class A {foo() {if (^) }}');
779 expect(computeFast(), isTrue);
780 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
781 }
782
783 test_if_expression_in_class2() {
784 addTestSource('class A {foo() {if (n^) }}');
785 expect(computeFast(), isTrue);
786 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
787 }
788
789 test_if_expression_in_function() {
790 addTestSource('foo() {if (^) }');
791 expect(computeFast(), isTrue);
792 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
793 }
794
795 test_if_expression_in_function2() {
796 addTestSource('foo() {if (n^) }');
797 expect(computeFast(), isTrue);
798 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
799 }
800
801 test_if_in_class() {
802 addTestSource('class A {foo() {if (true) ^}}');
803 expect(computeFast(), isTrue);
804 assertSuggestKeywords(STMT_START_IN_CLASS);
805 }
806
807 test_if_in_class2() {
808 addTestSource('class A {foo() {if (true) ^;}}');
809 expect(computeFast(), isTrue);
810 assertSuggestKeywords(STMT_START_IN_CLASS);
811 }
812
813 test_if_in_class3() {
814 addTestSource('class A {foo() {if (true) r^;}}');
815 expect(computeFast(), isTrue);
816 assertSuggestKeywords(STMT_START_IN_CLASS);
817 }
818
819 test_if_in_class4() {
820 addTestSource('class A {foo() {if (true) ^ go();}}');
821 expect(computeFast(), isTrue);
822 assertSuggestKeywords(STMT_START_IN_CLASS);
823 }
824
825 test_if_outside_class() {
826 addTestSource('foo() {if (true) ^}');
827 expect(computeFast(), isTrue);
828 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
829 }
830
831 test_if_outside_class2() {
832 addTestSource('foo() {if (true) ^;}');
833 expect(computeFast(), isTrue);
834 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
835 }
836
837 test_if_outside_class3() {
838 addTestSource('foo() {if (true) r^;}');
839 expect(computeFast(), isTrue);
840 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
841 }
842
843 test_if_outside_class4() {
844 addTestSource('foo() {if (true) ^ go();}');
845 expect(computeFast(), isTrue);
846 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS);
847 }
848
849 test_import() {
850 addTestSource('import "foo" deferred as foo ^;');
851 expect(computeFast(), isTrue);
852 assertSuggestKeywords([],
853 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH);
854 }
855
856 test_import_as() {
857 addTestSource('import "foo" deferred ^;');
858 expect(computeFast(), isTrue);
859 assertSuggestKeywords([Keyword.AS], relevance: DART_RELEVANCE_HIGH);
860 }
861
862 test_import_as2() {
863 addTestSource('import "foo" deferred a^;');
864 expect(computeFast(), isTrue);
865 assertSuggestKeywords([Keyword.AS], relevance: DART_RELEVANCE_HIGH);
866 }
867
868 test_import_as3() {
869 addTestSource('import "foo" deferred a^');
870 expect(computeFast(), isTrue);
871 assertSuggestKeywords([Keyword.AS], relevance: DART_RELEVANCE_HIGH);
872 }
873
874 test_import_deferred() {
875 addTestSource('import "foo" ^ as foo;');
876 expect(computeFast(), isTrue);
877 assertSuggestKeywords([Keyword.DEFERRED], relevance: DART_RELEVANCE_HIGH);
878 }
879
880 test_import_deferred2() {
881 addTestSource('import "foo" d^ as foo;');
882 expect(computeFast(), isTrue);
883 assertSuggestKeywords([Keyword.DEFERRED], relevance: DART_RELEVANCE_HIGH);
884 }
885
886 test_import_deferred3() {
887 addTestSource('import "foo" d^ show foo;');
888 expect(computeFast(), isTrue);
889 assertSuggestKeywords([Keyword.AS],
890 pseudoKeywords: ['deferred as'], relevance: DART_RELEVANCE_HIGH);
891 }
892
893 test_import_deferred4() {
894 addTestSource('import "foo" d^ hide foo;');
895 expect(computeFast(), isTrue);
896 assertSuggestKeywords([Keyword.AS],
897 pseudoKeywords: ['deferred as'], relevance: DART_RELEVANCE_HIGH);
898 }
899
900 test_import_deferred5() {
901 addTestSource('import "foo" d^');
902 expect(computeFast(), isTrue);
903 assertSuggestKeywords([Keyword.AS],
904 pseudoKeywords: ['deferred as', 'show', 'hide'],
905 relevance: DART_RELEVANCE_HIGH);
906 }
907
908 test_import_deferred6() {
909 addTestSource('import "foo" d^ import');
910 expect(computeFast(), isTrue);
911 assertSuggestKeywords([Keyword.AS],
912 pseudoKeywords: ['deferred as', 'show', 'hide'],
913 relevance: DART_RELEVANCE_HIGH);
914 }
915
916 test_import_deferred_as() {
917 addTestSource('import "foo" ^;');
918 expect(computeFast(), isTrue);
919 assertSuggestKeywords([Keyword.AS],
920 pseudoKeywords: ['deferred as', 'show', 'hide'],
921 relevance: DART_RELEVANCE_HIGH);
922 }
923
924 test_import_deferred_as2() {
925 addTestSource('import "foo" d^;');
926 expect(computeFast(), isTrue);
927 assertSuggestKeywords([Keyword.AS],
928 pseudoKeywords: ['deferred as', 'show', 'hide'],
929 relevance: DART_RELEVANCE_HIGH);
930 }
931
932 test_import_deferred_as3() {
933 addTestSource('import "foo" ^');
934 expect(computeFast(), isTrue);
935 assertSuggestKeywords([Keyword.AS],
936 pseudoKeywords: ['deferred as', 'show', 'hide'],
937 relevance: DART_RELEVANCE_HIGH);
938 }
939
940 test_import_deferred_as4() {
941 addTestSource('import "foo" d^');
942 expect(computeFast(), isTrue);
943 assertSuggestKeywords([Keyword.AS],
944 pseudoKeywords: ['deferred as', 'show', 'hide'],
945 relevance: DART_RELEVANCE_HIGH);
946 }
947
948 test_import_deferred_as5() {
949 addTestSource('import "foo" sh^ import "bar"; import "baz";');
950 expect(computeFast(), isTrue);
951 assertSuggestKeywords([Keyword.AS],
952 pseudoKeywords: ['deferred as', 'show', 'hide'],
953 relevance: DART_RELEVANCE_HIGH);
954 }
955
956 test_import_deferred_not() {
957 addTestSource('import "foo" as foo ^;');
958 expect(computeFast(), isTrue);
959 assertSuggestKeywords([],
960 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH);
961 }
962
963 test_import_deferred_partial() {
964 addTestSource('import "package:foo/foo.dart" def^ as foo;');
965 expect(computeFast(), isTrue);
966 assertSuggestKeywords([Keyword.DEFERRED], relevance: DART_RELEVANCE_HIGH);
967 expect(request.replacementOffset, 30);
968 expect(request.replacementLength, 3);
969 }
970
971 test_import_incomplete() {
972 addTestSource('import "^"');
973 expect(computeFast(), isTrue);
974 assertNoSuggestions();
975 }
976
977 test_import_partial() {
978 addTestSource('imp^ import "package:foo/foo.dart"; import "bar.dart";');
979 expect(computeFast(), isTrue);
980 // TODO(danrubel) should not suggest declaration keywords
981 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
982 relevance: DART_RELEVANCE_HIGH);
983 expect(request.replacementOffset, 0);
984 expect(request.replacementLength, 3);
985 }
986
987 test_import_partial2() {
988 addTestSource('^imp import "package:foo/foo.dart";');
989 expect(computeFast(), isTrue);
990 // TODO(danrubel) should not suggest declaration keywords
991 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
992 relevance: DART_RELEVANCE_HIGH);
993 expect(request.replacementOffset, 0);
994 expect(request.replacementLength, 3);
995 }
996
997 test_import_partial3() {
998 addTestSource(' ^imp import "package:foo/foo.dart"; import "bar.dart";');
999 expect(computeFast(), isTrue);
1000 // TODO(danrubel) should not suggest declaration keywords
1001 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
1002 relevance: DART_RELEVANCE_HIGH);
1003 expect(request.replacementOffset, 1);
1004 expect(request.replacementLength, 3);
1005 }
1006
1007 test_import_partial4() {
1008 addTestSource('^ imp import "package:foo/foo.dart";');
1009 expect(computeFast(), isTrue);
1010 // TODO(danrubel) should not suggest declaration keywords
1011 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
1012 relevance: DART_RELEVANCE_HIGH);
1013 expect(request.replacementOffset, 0);
1014 expect(request.replacementLength, 0);
1015 }
1016
1017 test_import_partial5() {
1018 addTestSource('library libA; imp^ import "package:foo/foo.dart";');
1019 expect(computeFast(), isTrue);
1020 // TODO(danrubel) should not suggest declaration keywords
1021 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
1022 relevance: DART_RELEVANCE_HIGH);
1023 expect(request.replacementOffset, 14);
1024 expect(request.replacementLength, 3);
1025 }
1026
1027 test_import_partial6() {
1028 addTestSource(
1029 'library bar; import "zoo.dart"; imp^ import "package:foo/foo.dart";');
1030 expect(computeFast(), isTrue);
1031 // TODO(danrubel) should not suggest declaration keywords
1032 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
1033 relevance: DART_RELEVANCE_HIGH);
1034 expect(request.replacementOffset, 32);
1035 expect(request.replacementLength, 3);
1036 }
1037
1038 test_inComment_block() {
1039 addTestSource('''
1040 main() {
1041 /* text ^ */
1042 print(42);
1043 }
1044 ''');
1045 expect(computeFast(), isTrue);
1046 assertNoSuggestions();
1047 }
1048
1049 test_inComment_endOfLine() {
1050 addTestSource('''
1051 main() {
1052 // text ^
1053 }
1054 ''');
1055 expect(computeFast(), isTrue);
1056 assertNoSuggestions();
1057 }
1058
1059 test_is_expression() {
1060 addTestSource('main() {if (x is^)}');
1061 expect(computeFast(), isTrue);
1062 assertSuggestKeywords([Keyword.IS], relevance: DART_RELEVANCE_HIGH);
1063 }
1064
1065 test_library() {
1066 addTestSource('library foo;^');
1067 expect(computeFast(), isTrue);
1068 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
1069 relevance: DART_RELEVANCE_HIGH);
1070 }
1071
1072 test_library_declaration() {
1073 addTestSource('library ^');
1074 expect(computeFast(), isTrue);
1075 assertSuggestKeywords([]);
1076 }
1077
1078 test_library_declaration2() {
1079 addTestSource('library a^');
1080 expect(computeFast(), isTrue);
1081 assertSuggestKeywords([]);
1082 }
1083
1084 test_library_declaration3() {
1085 addTestSource('library a.^');
1086 expect(computeFast(), isTrue);
1087 assertSuggestKeywords([]);
1088 }
1089
1090 test_library_name() {
1091 addTestSource('library ^');
1092 expect(computeFast(), isTrue);
1093 assertSuggestKeywords([]);
1094 }
1095
1096 test_method_async() {
1097 addTestSource('class A { foo() ^}');
1098 expect(computeFast(), isTrue);
1099 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1100 }
1101
1102 test_method_async2() {
1103 addTestSource('class A { foo() ^{}}');
1104 expect(computeFast(), isTrue);
1105 assertSuggestKeywords([],
1106 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
1107 }
1108
1109 test_method_async3() {
1110 addTestSource('class A { foo() a^}');
1111 expect(computeFast(), isTrue);
1112 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1113 }
1114
1115 test_method_async4() {
1116 addTestSource('class A { foo() a^{}}');
1117 expect(computeFast(), isTrue);
1118 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1119 }
1120
1121 test_method_async5() {
1122 addTestSource('class A { foo() ^ Foo foo;}');
1123 expect(computeFast(), isTrue);
1124 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1125 }
1126
1127 test_method_async6() {
1128 addTestSource('class A { foo() a^ Foo foo;}');
1129 expect(computeFast(), isTrue);
1130 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1131 }
1132
1133 test_method_async7() {
1134 addTestSource('class A { foo() ^ => Foo foo;}');
1135 expect(computeFast(), isTrue);
1136 assertSuggestKeywords([],
1137 pseudoKeywords: ['async'], relevance: DART_RELEVANCE_HIGH);
1138 }
1139
1140 test_method_async8() {
1141 addTestSource('class A { foo() a^ Foo foo;}');
1142 expect(computeFast(), isTrue);
1143 assertSuggestKeywords(CLASS_BODY_KEYWORDS, pseudoKeywords: ['async']);
1144 }
1145
1146 test_method_body() {
1147 addTestSource('class A { foo() {^}}');
1148 expect(computeFast(), isTrue);
1149 assertSuggestKeywords(STMT_START_IN_CLASS);
1150 }
1151
1152 test_method_body2() {
1153 addTestSource('class A { foo() => ^}');
1154 expect(computeFast(), isTrue);
1155 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1156 }
1157
1158 test_method_body3() {
1159 addTestSource('class A { foo() => ^ Foo foo;}');
1160 expect(computeFast(), isTrue);
1161 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1162 }
1163
1164 test_method_body4() {
1165 addTestSource('class A { foo() => ^;}');
1166 expect(computeFast(), isTrue);
1167 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1168 }
1169
1170 test_method_body_async() {
1171 addTestSource('class A { foo() async {^}}');
1172 expect(computeFast(), isTrue);
1173 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']);
1174 }
1175
1176 test_method_body_async2() {
1177 addTestSource('class A { foo() async => ^}');
1178 expect(computeFast(), isTrue);
1179 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']);
1180 }
1181
1182 test_method_body_async3() {
1183 addTestSource('class A { foo() async => ^ Foo foo;}');
1184 expect(computeFast(), isTrue);
1185 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']);
1186 }
1187
1188 test_method_body_async4() {
1189 addTestSource('class A { foo() async => ^;}');
1190 expect(computeFast(), isTrue);
1191 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']);
1192 }
1193
1194 test_method_body_expression1() {
1195 addTestSource('class A { foo() {return b == true ? ^}}');
1196 expect(computeFast(), isTrue);
1197 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1198 }
1199
1200 test_method_body_expression2() {
1201 addTestSource('class A { foo() {return b == true ? 1 : ^}}');
1202 expect(computeFast(), isTrue);
1203 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1204 }
1205
1206 test_method_body_return() {
1207 addTestSource('class A { foo() {return ^}}');
1208 expect(computeFast(), isTrue);
1209 assertSuggestKeywords(EXPRESSION_START_INSTANCE);
1210 }
1211
1212 test_method_param() {
1213 addTestSource('class A { foo(^) {});}');
1214 expect(computeFast(), isTrue);
1215 assertNoSuggestions();
1216 }
1217
1218 test_method_param2() {
1219 addTestSource('class A { foo(t^) {});}');
1220 expect(computeFast(), isTrue);
1221 assertNoSuggestions();
1222 }
1223
1224 test_named_constructor_invocation() {
1225 addTestSource('void main() {new Future.^}');
1226 expect(computeFast(), isTrue);
1227 assertSuggestKeywords([]);
1228 }
1229
1230 test_newInstance() {
1231 addTestSource('class A { foo() {new ^}}');
1232 expect(computeFast(), isTrue);
1233 assertSuggestKeywords([]);
1234 }
1235
1236 test_newInstance2() {
1237 addTestSource('class A { foo() {new ^ print("foo");}}');
1238 expect(computeFast(), isTrue);
1239 assertSuggestKeywords([]);
1240 }
1241
1242 test_newInstance_prefixed() {
1243 addTestSource('class A { foo() {new A.^}}');
1244 expect(computeFast(), isTrue);
1245 assertSuggestKeywords([]);
1246 }
1247
1248 test_newInstance_prefixed2() {
1249 addTestSource('class A { foo() {new A.^ print("foo");}}');
1250 expect(computeFast(), isTrue);
1251 assertSuggestKeywords([]);
1252 }
1253
1254 test_part_of() {
1255 addTestSource('part of foo;^');
1256 expect(computeFast(), isTrue);
1257 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
1258 relevance: DART_RELEVANCE_HIGH);
1259 }
1260
1261 test_partial_class() {
1262 addTestSource('cl^');
1263 expect(computeFast(), isTrue);
1264 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
1265 relevance: DART_RELEVANCE_HIGH);
1266 }
1267
1268 test_partial_class2() {
1269 addTestSource('library a; cl^');
1270 expect(computeFast(), isTrue);
1271 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
1272 relevance: DART_RELEVANCE_HIGH);
1273 }
1274
1275 test_prefixed_field() {
1276 addTestSource('class A { int x; foo() {x.^}}');
1277 expect(computeFast(), isTrue);
1278 assertSuggestKeywords([]);
1279 }
1280
1281 test_prefixed_field2() {
1282 addTestSource('class A { int x; foo() {x.^ print("foo");}}');
1283 expect(computeFast(), isTrue);
1284 assertSuggestKeywords([]);
1285 }
1286
1287 test_prefixed_library() {
1288 addTestSource('import "b" as b; class A { foo() {b.^}}');
1289 expect(computeFast(), isTrue);
1290 assertSuggestKeywords([]);
1291 }
1292
1293 test_prefixed_local() {
1294 addTestSource('class A { foo() {int x; x.^}}');
1295 expect(computeFast(), isTrue);
1296 assertSuggestKeywords([]);
1297 }
1298
1299 test_prefixed_local2() {
1300 addTestSource('class A { foo() {int x; x.^ print("foo");}}');
1301 expect(computeFast(), isTrue);
1302 assertSuggestKeywords([]);
1303 }
1304
1305 test_property_access() {
1306 addTestSource('class A { get x => 7; foo() {new A().^}}');
1307 expect(computeFast(), isTrue);
1308 assertSuggestKeywords([]);
1309 }
1310
1311 test_switch_expression() {
1312 addTestSource('main() {switch(^) {}}');
1313 expect(computeFast(), isTrue);
1314 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
1315 }
1316
1317 test_switch_expression2() {
1318 addTestSource('main() {switch(n^) {}}');
1319 expect(computeFast(), isTrue);
1320 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
1321 }
1322
1323 test_switch_expression3() {
1324 addTestSource('main() {switch(n^)}');
1325 expect(computeFast(), isTrue);
1326 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE);
1327 }
1328
1329 test_switch_start() {
1330 addTestSource('main() {switch(1) {^}}');
1331 expect(computeFast(), isTrue);
1332 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1333 relevance: DART_RELEVANCE_HIGH);
1334 }
1335
1336 test_switch_start2() {
1337 addTestSource('main() {switch(1) {^ case 1:}}');
1338 expect(computeFast(), isTrue);
1339 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1340 relevance: DART_RELEVANCE_HIGH);
1341 }
1342
1343 test_switch_start3() {
1344 addTestSource('main() {switch(1) {^default:}}');
1345 expect(computeFast(), isTrue);
1346 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1347 relevance: DART_RELEVANCE_HIGH);
1348 }
1349
1350 test_switch_start4() {
1351 addTestSource('main() {switch(1) {^ default:}}');
1352 expect(computeFast(), isTrue);
1353 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1354 relevance: DART_RELEVANCE_HIGH);
1355 }
1356
1357 test_switch_start5() {
1358 addTestSource('main() {switch(1) {c^ default:}}');
1359 expect(computeFast(), isTrue);
1360 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1361 relevance: DART_RELEVANCE_HIGH);
1362 expect(request.replacementOffset, 19);
1363 expect(request.replacementLength, 1);
1364 }
1365
1366 test_switch_start6() {
1367 addTestSource('main() {switch(1) {c^}}');
1368 expect(computeFast(), isTrue);
1369 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1370 relevance: DART_RELEVANCE_HIGH);
1371 expect(request.replacementOffset, 19);
1372 expect(request.replacementLength, 1);
1373 }
1374
1375 test_switch_start7() {
1376 addTestSource('main() {switch(1) { c^ }}');
1377 expect(computeFast(), isTrue);
1378 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT],
1379 relevance: DART_RELEVANCE_HIGH);
1380 expect(request.replacementOffset, 20);
1381 expect(request.replacementLength, 1);
1382 }
1383
1384 test_switch_statement() {
1385 addTestSource('main() {switch(1) {case 1:^}}');
1386 expect(computeFast(), isTrue);
1387 assertSuggestKeywords(STMT_START_IN_SWITCH_OUTSIDE_CLASS);
1388 }
1389
1390 test_switch_statement2() {
1391 addTestSource('class A{foo() {switch(1) {case 1:^}}}');
1392 expect(computeFast(), isTrue);
1393 assertSuggestKeywords(STMT_START_IN_SWITCH_IN_CLASS);
1394 }
1395
1396 test_while_break_continue() {
1397 addTestSource('main() {while (true) {^}}');
1398 expect(computeFast(), isTrue);
1399 assertSuggestKeywords(STMT_START_IN_LOOP_OUTSIDE_CLASS,
1400 relevance: DART_RELEVANCE_KEYWORD);
1401 }
1402
1403 test_while_break_continue2() {
1404 addTestSource('class A {foo() {while (true) {^}}}');
1405 expect(computeFast(), isTrue);
1406 assertSuggestKeywords(STMT_START_IN_LOOP_IN_CLASS,
1407 relevance: DART_RELEVANCE_KEYWORD);
1408 }
1409
1410 void _appendCompletions(
1411 StringBuffer msg, Iterable<String> completions, Iterable<String> other) {
1412 List<String> sorted = completions.toList();
1413 sorted.sort((c1, c2) => c1.compareTo(c2));
1414 sorted.forEach(
1415 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}'));
1416 }
1417
1418 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) {
1419 if (iter1.length != iter2.length) return false;
1420 if (iter1.any((c) => !iter2.contains(c))) return false;
1421 if (iter2.any((c) => !iter1.contains(c))) return false;
1422 return true;
1423 }
1424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698