| OLD | NEW |
| 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_contributor.dart
'; | 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 Keyword.PART, | 71 Keyword.PART, |
| 72 Keyword.TYPEDEF, | 72 Keyword.TYPEDEF, |
| 73 Keyword.VAR, | 73 Keyword.VAR, |
| 74 Keyword.VOID | 74 Keyword.VOID |
| 75 ]; | 75 ]; |
| 76 | 76 |
| 77 static const List<String> NO_PSEUDO_KEYWORDS = const []; | 77 static const List<String> NO_PSEUDO_KEYWORDS = const []; |
| 78 | 78 |
| 79 static const List<Keyword> STMT_START_IN_CLASS = const [ | 79 static const List<Keyword> STMT_START_IN_CLASS = const [ |
| 80 Keyword.ASSERT, | 80 Keyword.ASSERT, |
| 81 Keyword.CASE, | |
| 82 Keyword.CONTINUE, | 81 Keyword.CONTINUE, |
| 83 Keyword.DO, | 82 Keyword.DO, |
| 84 Keyword.FINAL, | 83 Keyword.FINAL, |
| 85 Keyword.FOR, | 84 Keyword.FOR, |
| 85 Keyword.IF, |
| 86 Keyword.NEW, |
| 87 Keyword.RETHROW, |
| 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_SWITCH_IN_CLASS = const [ |
| 100 Keyword.ASSERT, |
| 101 Keyword.CASE, |
| 102 Keyword.CONTINUE, |
| 103 Keyword.DEFAULT, |
| 104 Keyword.DO, |
| 105 Keyword.FINAL, |
| 106 Keyword.FOR, |
| 86 Keyword.IF, | 107 Keyword.IF, |
| 87 Keyword.NEW, | 108 Keyword.NEW, |
| 88 Keyword.RETHROW, | 109 Keyword.RETHROW, |
| 89 Keyword.RETURN, | 110 Keyword.RETURN, |
| 90 Keyword.SUPER, | 111 Keyword.SUPER, |
| 91 Keyword.SWITCH, | 112 Keyword.SWITCH, |
| 92 Keyword.THIS, | 113 Keyword.THIS, |
| 93 Keyword.THROW, | 114 Keyword.THROW, |
| 94 Keyword.TRY, | 115 Keyword.TRY, |
| 95 Keyword.VAR, | 116 Keyword.VAR, |
| 96 Keyword.VOID, | 117 Keyword.VOID, |
| 97 Keyword.WHILE | 118 Keyword.WHILE |
| 98 ]; | 119 ]; |
| 99 | 120 |
| 121 static const List<Keyword> STMT_START_IN_SWITCH_OUTSIDE_CLASS = const [ |
| 122 Keyword.ASSERT, |
| 123 Keyword.CASE, |
| 124 Keyword.CONTINUE, |
| 125 Keyword.DEFAULT, |
| 126 Keyword.DO, |
| 127 Keyword.FINAL, |
| 128 Keyword.FOR, |
| 129 Keyword.IF, |
| 130 Keyword.NEW, |
| 131 Keyword.RETHROW, |
| 132 Keyword.RETURN, |
| 133 Keyword.SWITCH, |
| 134 Keyword.THROW, |
| 135 Keyword.TRY, |
| 136 Keyword.VAR, |
| 137 Keyword.VOID, |
| 138 Keyword.WHILE |
| 139 ]; |
| 140 |
| 100 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [ | 141 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [ |
| 101 Keyword.ASSERT, | 142 Keyword.ASSERT, |
| 102 Keyword.CASE, | |
| 103 Keyword.CONTINUE, | 143 Keyword.CONTINUE, |
| 104 Keyword.DO, | 144 Keyword.DO, |
| 105 Keyword.FINAL, | 145 Keyword.FINAL, |
| 106 Keyword.FOR, | 146 Keyword.FOR, |
| 107 Keyword.IF, | 147 Keyword.IF, |
| 108 Keyword.NEW, | 148 Keyword.NEW, |
| 109 Keyword.RETHROW, | 149 Keyword.RETHROW, |
| 110 Keyword.RETURN, | 150 Keyword.RETURN, |
| 111 Keyword.SWITCH, | 151 Keyword.SWITCH, |
| 112 Keyword.THROW, | 152 Keyword.THROW, |
| 113 Keyword.TRY, | 153 Keyword.TRY, |
| 114 Keyword.VAR, | 154 Keyword.VAR, |
| 115 Keyword.VOID, | 155 Keyword.VOID, |
| 116 Keyword.WHILE | 156 Keyword.WHILE |
| 117 ]; | 157 ]; |
| 118 | 158 |
| 159 static const List<Keyword> EXPRESSION_START_INSTANCE = const [ |
| 160 Keyword.FALSE, |
| 161 Keyword.NEW, |
| 162 Keyword.NULL, |
| 163 Keyword.SUPER, |
| 164 Keyword.THIS, |
| 165 Keyword.TRUE, |
| 166 ]; |
| 167 |
| 168 static const List<Keyword> EXPRESSION_START_NO_INSTANCE = const [ |
| 169 Keyword.FALSE, |
| 170 Keyword.NEW, |
| 171 Keyword.NULL, |
| 172 Keyword.TRUE, |
| 173 ]; |
| 174 |
| 119 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, | 175 void assertSuggestKeywords(Iterable<Keyword> expectedKeywords, |
| 120 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS, | 176 {List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS, |
| 121 int relevance: DART_RELEVANCE_KEYWORD}) { | 177 int relevance: DART_RELEVANCE_KEYWORD}) { |
| 122 Set<String> expectedCompletions = new Set<String>(); | 178 Set<String> expectedCompletions = new Set<String>(); |
| 123 Set<String> actualCompletions = new Set<String>(); | 179 Set<String> actualCompletions = new Set<String>(); |
| 124 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax)); | 180 expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax)); |
| 125 expectedCompletions.addAll(pseudoKeywords); | 181 expectedCompletions.addAll(pseudoKeywords); |
| 126 for (CompletionSuggestion s in request.suggestions) { | 182 for (CompletionSuggestion s in request.suggestions) { |
| 127 if (s.kind == CompletionSuggestionKind.KEYWORD) { | 183 if (s.kind == CompletionSuggestionKind.KEYWORD) { |
| 128 Keyword k = Keyword.keywords[s.completion]; | 184 Keyword k = Keyword.keywords[s.completion]; |
| 129 if (k == null && !pseudoKeywords.contains(s.completion)) { | 185 if (k == null && !pseudoKeywords.contains(s.completion)) { |
| 130 fail('Invalid keyword suggested: ${s.completion}'); | 186 fail('Invalid keyword suggested: ${s.completion}'); |
| 131 } else { | 187 } else { |
| 132 if (!actualCompletions.add(s.completion)) { | 188 if (!actualCompletions.add(s.completion)) { |
| 133 fail('Duplicate keyword suggested: ${s.completion}'); | 189 fail('Duplicate keyword suggested: ${s.completion}'); |
| 134 } | 190 } |
| 135 } | 191 } |
| 136 } | 192 } |
| 137 } | 193 } |
| 138 if (!_equalSets(expectedCompletions, actualCompletions)) { | 194 if (!_equalSets(expectedCompletions, actualCompletions)) { |
| 139 StringBuffer msg = new StringBuffer(); | 195 StringBuffer msg = new StringBuffer(); |
| 140 msg.writeln('Expected:'); | 196 msg.writeln('Expected:'); |
| 141 _appendCompletions(msg, expectedCompletions); | 197 _appendCompletions(msg, expectedCompletions, actualCompletions); |
| 142 msg.writeln('but found:'); | 198 msg.writeln('but found:'); |
| 143 _appendCompletions(msg, actualCompletions); | 199 _appendCompletions(msg, actualCompletions, expectedCompletions); |
| 144 fail(msg.toString()); | 200 fail(msg.toString()); |
| 145 } | 201 } |
| 146 for (CompletionSuggestion s in request.suggestions) { | 202 for (CompletionSuggestion s in request.suggestions) { |
| 147 if (s.kind == CompletionSuggestionKind.KEYWORD) { | 203 if (s.kind == CompletionSuggestionKind.KEYWORD) { |
| 148 expect(s.relevance, equals(relevance), reason: s.completion); | 204 expect(s.relevance, equals(relevance), reason: s.completion); |
| 149 expect(s.selectionOffset, equals(s.completion.length)); | 205 expect(s.selectionOffset, equals(s.completion.length)); |
| 150 expect(s.selectionLength, equals(0)); | 206 expect(s.selectionLength, equals(0)); |
| 151 expect(s.isDeprecated, equals(false)); | 207 expect(s.isDeprecated, equals(false)); |
| 152 expect(s.isPotential, equals(false)); | 208 expect(s.isPotential, equals(false)); |
| 153 } | 209 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 178 relevance: DART_RELEVANCE_HIGH); | 234 relevance: DART_RELEVANCE_HIGH); |
| 179 } | 235 } |
| 180 | 236 |
| 181 test_after_import2() { | 237 test_after_import2() { |
| 182 addTestSource('import "foo"; c^'); | 238 addTestSource('import "foo"; c^'); |
| 183 expect(computeFast(), isTrue); | 239 expect(computeFast(), isTrue); |
| 184 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, | 240 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, |
| 185 relevance: DART_RELEVANCE_HIGH); | 241 relevance: DART_RELEVANCE_HIGH); |
| 186 } | 242 } |
| 187 | 243 |
| 244 test_argument() { |
| 245 addTestSource('main() {foo(^);}'); |
| 246 expect(computeFast(), isTrue); |
| 247 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 248 } |
| 249 |
| 250 test_argument2() { |
| 251 addTestSource('main() {foo(n^);}'); |
| 252 expect(computeFast(), isTrue); |
| 253 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 254 } |
| 255 |
| 256 test_argument_literal() { |
| 257 addTestSource('main() {foo("^");}'); |
| 258 expect(computeFast(), isTrue); |
| 259 assertSuggestKeywords([]); |
| 260 } |
| 261 |
| 262 test_argument_named() { |
| 263 addTestSource('main() {foo(bar: ^);}'); |
| 264 expect(computeFast(), isTrue); |
| 265 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 266 } |
| 267 |
| 268 test_argument_named2() { |
| 269 addTestSource('main() {foo(bar: n^);}'); |
| 270 expect(computeFast(), isTrue); |
| 271 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 272 } |
| 273 |
| 274 test_argument_named_literal() { |
| 275 addTestSource('main() {foo(bar: "^");}'); |
| 276 expect(computeFast(), isTrue); |
| 277 assertSuggestKeywords([]); |
| 278 } |
| 279 |
| 280 test_assignment_field() { |
| 281 addTestSource('class A {var foo = ^}'); |
| 282 expect(computeFast(), isTrue); |
| 283 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 284 } |
| 285 |
| 286 test_assignment_field2() { |
| 287 addTestSource('class A {var foo = n^}'); |
| 288 expect(computeFast(), isTrue); |
| 289 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 290 } |
| 291 |
| 292 test_assignment_local() { |
| 293 addTestSource('main() {var foo = ^}'); |
| 294 expect(computeFast(), isTrue); |
| 295 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 296 } |
| 297 |
| 298 test_assignment_local2() { |
| 299 addTestSource('main() {var foo = n^}'); |
| 300 expect(computeFast(), isTrue); |
| 301 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 302 } |
| 303 |
| 304 test_assignment_local2_async() { |
| 305 addTestSource('main() async {var foo = n^}'); |
| 306 expect(computeFast(), isTrue); |
| 307 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE, |
| 308 pseudoKeywords: ['await']); |
| 309 } |
| 310 |
| 311 test_assignment_local_async() { |
| 312 addTestSource('main() async {var foo = ^}'); |
| 313 expect(computeFast(), isTrue); |
| 314 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE, |
| 315 pseudoKeywords: ['await']); |
| 316 } |
| 317 |
| 188 test_before_import() { | 318 test_before_import() { |
| 189 addTestSource('^ import foo;'); | 319 addTestSource('^ import foo;'); |
| 190 expect(computeFast(), isTrue); | 320 expect(computeFast(), isTrue); |
| 191 assertSuggestKeywords( | 321 assertSuggestKeywords( |
| 192 [Keyword.EXPORT, Keyword.IMPORT, Keyword.LIBRARY, Keyword.PART], | 322 [Keyword.EXPORT, Keyword.IMPORT, Keyword.LIBRARY, Keyword.PART], |
| 193 relevance: DART_RELEVANCE_HIGH); | 323 relevance: DART_RELEVANCE_HIGH); |
| 194 } | 324 } |
| 195 | 325 |
| 196 test_class() { | 326 test_class() { |
| 197 addTestSource('class A e^ { }'); | 327 addTestSource('class A e^ { }'); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 foo(p) {} | 519 foo(p) {} |
| 390 class A { | 520 class A { |
| 391 final f; | 521 final f; |
| 392 A() : f = foo(() {^}); | 522 A() : f = foo(() {^}); |
| 393 } | 523 } |
| 394 '''); | 524 '''); |
| 395 expect(computeFast(), isTrue); | 525 expect(computeFast(), isTrue); |
| 396 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); | 526 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 397 } | 527 } |
| 398 | 528 |
| 529 test_function_body_inClass_constructorInitializer_async() { |
| 530 addTestSource(r''' |
| 531 foo(p) {} |
| 532 class A { |
| 533 final f; |
| 534 A() : f = foo(() async {^}); |
| 535 } |
| 536 '''); |
| 537 expect(computeFast(), isTrue); |
| 538 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS, pseudoKeywords: ['await']); |
| 539 } |
| 540 |
| 399 test_function_body_inClass_field() { | 541 test_function_body_inClass_field() { |
| 400 addTestSource(r''' | 542 addTestSource(r''' |
| 401 class A { | 543 class A { |
| 402 var f = () {^}; | 544 var f = () {^}; |
| 403 } | 545 } |
| 404 '''); | 546 '''); |
| 405 expect(computeFast(), isTrue); | 547 expect(computeFast(), isTrue); |
| 406 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); | 548 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 407 } | 549 } |
| 408 | 550 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 425 f() { | 567 f() { |
| 426 f2() {^}; | 568 f2() {^}; |
| 427 }; | 569 }; |
| 428 } | 570 } |
| 429 } | 571 } |
| 430 '''); | 572 '''); |
| 431 expect(computeFast(), isTrue); | 573 expect(computeFast(), isTrue); |
| 432 assertSuggestKeywords(STMT_START_IN_CLASS); | 574 assertSuggestKeywords(STMT_START_IN_CLASS); |
| 433 } | 575 } |
| 434 | 576 |
| 577 test_function_body_inClass_methodBody_inFunction_async() { |
| 578 addTestSource(r''' |
| 579 class A { |
| 580 m() { |
| 581 f() { |
| 582 f2() async {^}; |
| 583 }; |
| 584 } |
| 585 } |
| 586 '''); |
| 587 expect(computeFast(), isTrue); |
| 588 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); |
| 589 } |
| 590 |
| 435 test_function_body_inUnit() { | 591 test_function_body_inUnit() { |
| 436 addTestSource('main() {^}'); | 592 addTestSource('main() {^}'); |
| 437 expect(computeFast(), isTrue); | 593 expect(computeFast(), isTrue); |
| 438 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); | 594 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| 439 } | 595 } |
| 440 | 596 |
| 441 test_function_body_inUnit_afterBlock() { | 597 test_function_body_inUnit_afterBlock() { |
| 442 addTestSource('main() {{}^}'); | 598 addTestSource('main() {{}^}'); |
| 443 expect(computeFast(), isTrue); | 599 expect(computeFast(), isTrue); |
| 444 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); | 600 assertSuggestKeywords(STMT_START_OUTSIDE_CLASS); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 817 |
| 662 test_method_body() { | 818 test_method_body() { |
| 663 addTestSource('class A { foo() {^}}'); | 819 addTestSource('class A { foo() {^}}'); |
| 664 expect(computeFast(), isTrue); | 820 expect(computeFast(), isTrue); |
| 665 assertSuggestKeywords(STMT_START_IN_CLASS); | 821 assertSuggestKeywords(STMT_START_IN_CLASS); |
| 666 } | 822 } |
| 667 | 823 |
| 668 test_method_body2() { | 824 test_method_body2() { |
| 669 addTestSource('class A { foo() => ^}'); | 825 addTestSource('class A { foo() => ^}'); |
| 670 expect(computeFast(), isTrue); | 826 expect(computeFast(), isTrue); |
| 671 assertSuggestKeywords(STMT_START_IN_CLASS); | 827 assertSuggestKeywords(EXPRESSION_START_INSTANCE); |
| 672 } | 828 } |
| 673 | 829 |
| 674 test_method_body3() { | 830 test_method_body3() { |
| 675 addTestSource('class A { foo() => ^ Foo foo;}'); | 831 addTestSource('class A { foo() => ^ Foo foo;}'); |
| 676 expect(computeFast(), isTrue); | 832 expect(computeFast(), isTrue); |
| 677 assertSuggestKeywords(STMT_START_IN_CLASS); | 833 assertSuggestKeywords(EXPRESSION_START_INSTANCE); |
| 678 } | 834 } |
| 679 | 835 |
| 680 test_method_body4() { | 836 test_method_body4() { |
| 681 addTestSource('class A { foo() => ^;}'); | 837 addTestSource('class A { foo() => ^;}'); |
| 682 expect(computeFast(), isTrue); | 838 expect(computeFast(), isTrue); |
| 683 assertSuggestKeywords(STMT_START_IN_CLASS); | 839 assertSuggestKeywords(EXPRESSION_START_INSTANCE); |
| 684 } | 840 } |
| 685 | 841 |
| 686 test_method_body_async() { | 842 test_method_body_async() { |
| 687 addTestSource('class A { foo() async {^}}'); | 843 addTestSource('class A { foo() async {^}}'); |
| 688 expect(computeFast(), isTrue); | 844 expect(computeFast(), isTrue); |
| 689 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); | 845 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); |
| 690 } | 846 } |
| 691 | 847 |
| 692 test_method_body_async2() { | 848 test_method_body_async2() { |
| 693 addTestSource('class A { foo() async => ^}'); | 849 addTestSource('class A { foo() async => ^}'); |
| 694 expect(computeFast(), isTrue); | 850 expect(computeFast(), isTrue); |
| 695 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); | 851 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']); |
| 696 } | 852 } |
| 697 | 853 |
| 698 test_method_body_async3() { | 854 test_method_body_async3() { |
| 699 addTestSource('class A { foo() async => ^ Foo foo;}'); | 855 addTestSource('class A { foo() async => ^ Foo foo;}'); |
| 700 expect(computeFast(), isTrue); | 856 expect(computeFast(), isTrue); |
| 701 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); | 857 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']); |
| 702 } | 858 } |
| 703 | 859 |
| 704 test_method_body_async4() { | 860 test_method_body_async4() { |
| 705 addTestSource('class A { foo() async => ^;}'); | 861 addTestSource('class A { foo() async => ^;}'); |
| 706 expect(computeFast(), isTrue); | 862 expect(computeFast(), isTrue); |
| 707 assertSuggestKeywords(STMT_START_IN_CLASS, pseudoKeywords: ['await']); | 863 assertSuggestKeywords(EXPRESSION_START_INSTANCE, pseudoKeywords: ['await']); |
| 708 } | 864 } |
| 709 | 865 |
| 710 test_method_param() { | 866 test_method_param() { |
| 711 addTestSource('class A { foo(^) {});}'); | 867 addTestSource('class A { foo(^) {});}'); |
| 712 expect(computeFast(), isTrue); | 868 expect(computeFast(), isTrue); |
| 713 assertNoSuggestions(); | 869 assertNoSuggestions(); |
| 714 } | 870 } |
| 715 | 871 |
| 716 test_method_param2() { | 872 test_method_param2() { |
| 717 addTestSource('class A { foo(t^) {});}'); | 873 addTestSource('class A { foo(t^) {});}'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 739 relevance: DART_RELEVANCE_HIGH); | 895 relevance: DART_RELEVANCE_HIGH); |
| 740 } | 896 } |
| 741 | 897 |
| 742 test_partial_class2() { | 898 test_partial_class2() { |
| 743 addTestSource('library a; cl^'); | 899 addTestSource('library a; cl^'); |
| 744 expect(computeFast(), isTrue); | 900 expect(computeFast(), isTrue); |
| 745 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, | 901 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, |
| 746 relevance: DART_RELEVANCE_HIGH); | 902 relevance: DART_RELEVANCE_HIGH); |
| 747 } | 903 } |
| 748 | 904 |
| 749 void _appendCompletions(StringBuffer msg, Iterable<String> completions) { | 905 test_switch_expression() { |
| 906 addTestSource('main() {switch(^) {}}'); |
| 907 expect(computeFast(), isTrue); |
| 908 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 909 } |
| 910 |
| 911 test_switch_expression2() { |
| 912 addTestSource('main() {switch(n^) {}}'); |
| 913 expect(computeFast(), isTrue); |
| 914 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 915 } |
| 916 |
| 917 test_switch_expression3() { |
| 918 addTestSource('main() {switch(n^)}'); |
| 919 expect(computeFast(), isTrue); |
| 920 assertSuggestKeywords(EXPRESSION_START_NO_INSTANCE); |
| 921 } |
| 922 |
| 923 test_switch_start() { |
| 924 addTestSource('main() {switch(1) {^}}'); |
| 925 expect(computeFast(), isTrue); |
| 926 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT], |
| 927 relevance: DART_RELEVANCE_HIGH); |
| 928 } |
| 929 |
| 930 test_switch_start2() { |
| 931 addTestSource('main() {switch(1) {^ case 1:}}'); |
| 932 expect(computeFast(), isTrue); |
| 933 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT], |
| 934 relevance: DART_RELEVANCE_HIGH); |
| 935 } |
| 936 |
| 937 test_switch_start3() { |
| 938 addTestSource('main() {switch(1) {^default:}}'); |
| 939 expect(computeFast(), isTrue); |
| 940 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT], |
| 941 relevance: DART_RELEVANCE_HIGH); |
| 942 } |
| 943 |
| 944 test_switch_start4() { |
| 945 addTestSource('main() {switch(1) {^ default:}}'); |
| 946 expect(computeFast(), isTrue); |
| 947 assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT], |
| 948 relevance: DART_RELEVANCE_HIGH); |
| 949 } |
| 950 |
| 951 test_switch_statement() { |
| 952 addTestSource('main() {switch(1) {case 1:^}}'); |
| 953 expect(computeFast(), isTrue); |
| 954 assertSuggestKeywords(STMT_START_IN_SWITCH_OUTSIDE_CLASS); |
| 955 } |
| 956 |
| 957 test_switch_statement2() { |
| 958 addTestSource('class A{foo() {switch(1) {case 1:^}}}'); |
| 959 expect(computeFast(), isTrue); |
| 960 assertSuggestKeywords(STMT_START_IN_SWITCH_IN_CLASS); |
| 961 } |
| 962 |
| 963 void _appendCompletions( |
| 964 StringBuffer msg, Iterable<String> completions, Iterable<String> other) { |
| 750 List<String> sorted = completions.toList(); | 965 List<String> sorted = completions.toList(); |
| 751 sorted.sort((c1, c2) => c1.compareTo(c2)); | 966 sorted.sort((c1, c2) => c1.compareTo(c2)); |
| 752 sorted.forEach((c) => msg.writeln(' $c,')); | 967 sorted.forEach( |
| 968 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); |
| 753 } | 969 } |
| 754 | 970 |
| 755 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { | 971 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { |
| 756 if (iter1.length != iter2.length) return false; | 972 if (iter1.length != iter2.length) return false; |
| 757 if (iter1.any((c) => !iter2.contains(c))) return false; | 973 if (iter1.any((c) => !iter2.contains(c))) return false; |
| 758 if (iter2.any((c) => !iter1.contains(c))) return false; | 974 if (iter2.any((c) => !iter1.contains(c))) return false; |
| 759 return true; | 975 return true; |
| 760 } | 976 } |
| 761 } | 977 } |
| OLD | NEW |