| 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_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> CLASS_BODY_KEYWORDS = const [ |
| 24 Keyword.CONST, |
| 25 Keyword.DYNAMIC, |
| 26 Keyword.FACTORY, |
| 27 Keyword.FINAL, |
| 28 Keyword.GET, |
| 29 Keyword.OPERATOR, |
| 30 Keyword.SET, |
| 31 Keyword.STATIC, |
| 32 Keyword.VAR, |
| 33 Keyword.VOID |
| 34 ]; |
| 35 |
| 23 static const List<Keyword> IN_BLOCK_IN_CLASS = const [ | 36 static const List<Keyword> IN_BLOCK_IN_CLASS = const [ |
| 24 Keyword.ASSERT, | 37 Keyword.ASSERT, |
| 25 Keyword.CASE, | 38 Keyword.CASE, |
| 26 Keyword.CONTINUE, | 39 Keyword.CONTINUE, |
| 27 Keyword.DO, | 40 Keyword.DO, |
| 28 Keyword.FINAL, | 41 Keyword.FINAL, |
| 29 Keyword.FOR, | 42 Keyword.FOR, |
| 30 Keyword.IF, | 43 Keyword.IF, |
| 31 Keyword.NEW, | 44 Keyword.NEW, |
| 32 Keyword.RETHROW, | 45 Keyword.RETHROW, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 addTestSource('^ import foo;'); | 184 addTestSource('^ import foo;'); |
| 172 expect(computeFast(), isTrue); | 185 expect(computeFast(), isTrue); |
| 173 assertSuggestKeywords([ | 186 assertSuggestKeywords([ |
| 174 Keyword.EXPORT, | 187 Keyword.EXPORT, |
| 175 Keyword.IMPORT, | 188 Keyword.IMPORT, |
| 176 Keyword.LIBRARY, | 189 Keyword.LIBRARY, |
| 177 Keyword.PART | 190 Keyword.PART |
| 178 ], DART_RELEVANCE_HIGH); | 191 ], DART_RELEVANCE_HIGH); |
| 179 } | 192 } |
| 180 | 193 |
| 181 test_class4() { | 194 test_class() { |
| 182 addTestSource('class A e^ { }'); | 195 addTestSource('class A e^ { }'); |
| 183 expect(computeFast(), isTrue); | 196 expect(computeFast(), isTrue); |
| 184 assertSuggestKeywords( | 197 assertSuggestKeywords( |
| 185 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH); | 198 [Keyword.EXTENDS, Keyword.IMPLEMENTS], DART_RELEVANCE_HIGH); |
| 186 } | 199 } |
| 187 | 200 |
| 201 test_class_body() { |
| 202 addTestSource('class A {^}'); |
| 203 expect(computeFast(), isTrue); |
| 204 assertSuggestKeywords(CLASS_BODY_KEYWORDS); |
| 205 } |
| 206 |
| 207 test_class_body_beginning() { |
| 208 addTestSource('class A {^ var foo;}'); |
| 209 expect(computeFast(), isTrue); |
| 210 assertSuggestKeywords(CLASS_BODY_KEYWORDS); |
| 211 } |
| 212 |
| 213 test_class_body_between() { |
| 214 addTestSource('class A {var bar; ^ var foo;}'); |
| 215 expect(computeFast(), isTrue); |
| 216 assertSuggestKeywords(CLASS_BODY_KEYWORDS); |
| 217 } |
| 218 |
| 219 test_class_body_end() { |
| 220 addTestSource('class A {var foo; ^}'); |
| 221 expect(computeFast(), isTrue); |
| 222 assertSuggestKeywords(CLASS_BODY_KEYWORDS); |
| 223 } |
| 224 |
| 188 test_class_extends() { | 225 test_class_extends() { |
| 189 addTestSource('class A extends foo ^'); | 226 addTestSource('class A extends foo ^'); |
| 190 expect(computeFast(), isTrue); | 227 expect(computeFast(), isTrue); |
| 191 assertSuggestKeywords( | 228 assertSuggestKeywords( |
| 192 [Keyword.IMPLEMENTS, Keyword.WITH], DART_RELEVANCE_HIGH); | 229 [Keyword.IMPLEMENTS, Keyword.WITH], DART_RELEVANCE_HIGH); |
| 193 } | 230 } |
| 194 | 231 |
| 195 test_class_extends2() { | 232 test_class_extends2() { |
| 196 addTestSource('class A extends foo i^'); | 233 addTestSource('class A extends foo i^'); |
| 197 expect(computeFast(), isTrue); | 234 expect(computeFast(), isTrue); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 expect(computeFast(), isTrue); | 398 expect(computeFast(), isTrue); |
| 362 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 399 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); |
| 363 } | 400 } |
| 364 | 401 |
| 365 test_function_body_inUnit_afterBlock() { | 402 test_function_body_inUnit_afterBlock() { |
| 366 addTestSource('main() {{}^}'); | 403 addTestSource('main() {{}^}'); |
| 367 expect(computeFast(), isTrue); | 404 expect(computeFast(), isTrue); |
| 368 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); | 405 assertSuggestKeywords(IN_BLOCK_NOT_IN_CLASS); |
| 369 } | 406 } |
| 370 | 407 |
| 371 test_in_class() { | |
| 372 addTestSource('class A {^}'); | |
| 373 expect(computeFast(), isTrue); | |
| 374 assertSuggestKeywords([ | |
| 375 Keyword.CONST, | |
| 376 Keyword.DYNAMIC, | |
| 377 Keyword.FACTORY, | |
| 378 Keyword.FINAL, | |
| 379 Keyword.GET, | |
| 380 Keyword.OPERATOR, | |
| 381 Keyword.SET, | |
| 382 Keyword.STATIC, | |
| 383 Keyword.VAR, | |
| 384 Keyword.VOID | |
| 385 ]); | |
| 386 } | |
| 387 | |
| 388 test_library() { | 408 test_library() { |
| 389 addTestSource('library foo;^'); | 409 addTestSource('library foo;^'); |
| 390 expect(computeFast(), isTrue); | 410 expect(computeFast(), isTrue); |
| 391 assertSuggestKeywords([ | 411 assertSuggestKeywords([ |
| 392 Keyword.ABSTRACT, | 412 Keyword.ABSTRACT, |
| 393 Keyword.CLASS, | 413 Keyword.CLASS, |
| 394 Keyword.CONST, | 414 Keyword.CONST, |
| 395 Keyword.EXPORT, | 415 Keyword.EXPORT, |
| 396 Keyword.FINAL, | 416 Keyword.FINAL, |
| 397 Keyword.IMPORT, | 417 Keyword.IMPORT, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); | 494 sorted.forEach((k) => msg.writeln(' Keyword.${k.name},')); |
| 475 } | 495 } |
| 476 | 496 |
| 477 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { | 497 bool _equalSets(Iterable<Keyword> iter1, Iterable<Keyword> iter2) { |
| 478 if (iter1.length != iter2.length) return false; | 498 if (iter1.length != iter2.length) return false; |
| 479 if (iter1.any((k) => !iter2.contains(k))) return false; | 499 if (iter1.any((k) => !iter2.contains(k))) return false; |
| 480 if (iter2.any((k) => !iter1.contains(k))) return false; | 500 if (iter2.any((k) => !iter1.contains(k))) return false; |
| 481 return true; | 501 return true; |
| 482 } | 502 } |
| 483 } | 503 } |
| OLD | NEW |