| 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.domain.completion; | 5 library test.domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/channel/channel.dart'; | 10 import 'package:analysis_server/src/channel/channel.dart'; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 '''); | 357 '''); |
| 358 return getSuggestions().then((_) { | 358 return getSuggestions().then((_) { |
| 359 expect(replacementOffset, equals(completionOffset)); | 359 expect(replacementOffset, equals(completionOffset)); |
| 360 expect(replacementLength, equals(0)); | 360 expect(replacementLength, equals(0)); |
| 361 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); | 361 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 362 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); | 362 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 363 assertNoResult('test'); | 363 assertNoResult('test'); |
| 364 }); | 364 }); |
| 365 } | 365 } |
| 366 | 366 |
| 367 test_partFile() { | |
| 368 addFile('/project/bin/testA.dart', ''' | |
| 369 library libA; | |
| 370 part "$testFile"; | |
| 371 import 'dart:html'; | |
| 372 class A { } | |
| 373 '''); | |
| 374 addTestFile(''' | |
| 375 part of libA; | |
| 376 main() {^}'''); | |
| 377 return getSuggestions().then((_) { | |
| 378 expect(replacementOffset, equals(completionOffset)); | |
| 379 expect(replacementLength, equals(0)); | |
| 380 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); | |
| 381 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); | |
| 382 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); | |
| 383 assertNoResult('test'); | |
| 384 }); | |
| 385 } | |
| 386 | |
| 387 test_partFile2() { | |
| 388 addFile('/testA.dart', ''' | |
| 389 part of libA; | |
| 390 class A { }'''); | |
| 391 addTestFile(''' | |
| 392 library libA; | |
| 393 part "/testA.dart"; | |
| 394 import 'dart:html'; | |
| 395 main() {^} | |
| 396 '''); | |
| 397 return getSuggestions().then((_) { | |
| 398 expect(replacementOffset, equals(completionOffset)); | |
| 399 expect(replacementLength, equals(0)); | |
| 400 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); | |
| 401 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); | |
| 402 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); | |
| 403 assertNoResult('test'); | |
| 404 }); | |
| 405 } | |
| 406 | |
| 407 test_imports_prefixed() { | 367 test_imports_prefixed() { |
| 408 addTestFile(''' | 368 addTestFile(''' |
| 409 import 'dart:html' as foo; | 369 import 'dart:html' as foo; |
| 410 main() {^} | 370 main() {^} |
| 411 '''); | 371 '''); |
| 412 return getSuggestions().then((_) { | 372 return getSuggestions().then((_) { |
| 413 expect(replacementOffset, equals(completionOffset)); | 373 expect(replacementOffset, equals(completionOffset)); |
| 414 expect(replacementLength, equals(0)); | 374 expect(replacementLength, equals(0)); |
| 415 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); | 375 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 416 assertHasResult(CompletionSuggestionKind.INVOCATION, 'foo'); | 376 assertHasResult(CompletionSuggestionKind.INVOCATION, 'foo'); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 CompletionSuggestionKind.INVOCATION, | 437 CompletionSuggestionKind.INVOCATION, |
| 478 'b', | 438 'b', |
| 479 DART_RELEVANCE_LOCAL_VARIABLE); | 439 DART_RELEVANCE_LOCAL_VARIABLE); |
| 480 assertHasResult( | 440 assertHasResult( |
| 481 CompletionSuggestionKind.INVOCATION, | 441 CompletionSuggestionKind.INVOCATION, |
| 482 'x', | 442 'x', |
| 483 DART_RELEVANCE_LOCAL_METHOD); | 443 DART_RELEVANCE_LOCAL_METHOD); |
| 484 }); | 444 }); |
| 485 } | 445 } |
| 486 | 446 |
| 447 test_partFile() { |
| 448 addFile('/project/bin/testA.dart', ''' |
| 449 library libA; |
| 450 part "$testFile"; |
| 451 import 'dart:html'; |
| 452 class A { } |
| 453 '''); |
| 454 addTestFile(''' |
| 455 part of libA; |
| 456 main() {^}'''); |
| 457 return getSuggestions().then((_) { |
| 458 expect(replacementOffset, equals(completionOffset)); |
| 459 expect(replacementLength, equals(0)); |
| 460 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 461 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 462 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); |
| 463 assertNoResult('test'); |
| 464 }); |
| 465 } |
| 466 |
| 467 test_partFile2() { |
| 468 addFile('/testA.dart', ''' |
| 469 part of libA; |
| 470 class A { }'''); |
| 471 addTestFile(''' |
| 472 library libA; |
| 473 part "/testA.dart"; |
| 474 import 'dart:html'; |
| 475 main() {^} |
| 476 '''); |
| 477 return getSuggestions().then((_) { |
| 478 expect(replacementOffset, equals(completionOffset)); |
| 479 expect(replacementLength, equals(0)); |
| 480 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 481 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 482 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); |
| 483 assertNoResult('test'); |
| 484 }); |
| 485 } |
| 486 |
| 487 test_simple() { |
| 488 addTestFile(''' |
| 489 void main() { |
| 490 ^ |
| 491 } |
| 492 '''); |
| 493 return getSuggestions().then((_) { |
| 494 expect(replacementOffset, equals(completionOffset)); |
| 495 expect(replacementLength, equals(0)); |
| 496 assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); |
| 497 assertNoResult('HtmlElement'); |
| 498 assertNoResult('test'); |
| 499 }); |
| 500 } |
| 501 |
| 487 test_topLevel() { | 502 test_topLevel() { |
| 488 addTestFile(''' | 503 addTestFile(''' |
| 489 typedef foo(); | 504 typedef foo(); |
| 490 var test = ''; | 505 var test = ''; |
| 491 main() {tes^t} | 506 main() {tes^t} |
| 492 '''); | 507 '''); |
| 493 return getSuggestions().then((_) { | 508 return getSuggestions().then((_) { |
| 494 expect(replacementOffset, equals(completionOffset - 3)); | 509 expect(replacementOffset, equals(completionOffset - 3)); |
| 495 expect(replacementLength, equals(4)); | 510 expect(replacementLength, equals(4)); |
| 496 // Suggestions based upon imported elements are partially filtered | 511 // Suggestions based upon imported elements are partially filtered |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 658 |
| 644 void contextsChangedRaw(ContextsChangedEvent newEvent) { | 659 void contextsChangedRaw(ContextsChangedEvent newEvent) { |
| 645 super.contextsChanged(newEvent); | 660 super.contextsChanged(newEvent); |
| 646 } | 661 } |
| 647 | 662 |
| 648 CompletionManager createCompletionManager(AnalysisContext context, | 663 CompletionManager createCompletionManager(AnalysisContext context, |
| 649 Source source, SearchEngine searchEngine) { | 664 Source source, SearchEngine searchEngine) { |
| 650 return new MockCompletionManager(mockContext, source, searchEngine); | 665 return new MockCompletionManager(mockContext, source, searchEngine); |
| 651 } | 666 } |
| 652 } | 667 } |
| OLD | NEW |