| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 @reflectiveTest | 247 @reflectiveTest |
| 248 class CompletionTest extends AbstractAnalysisTest { | 248 class CompletionTest extends AbstractAnalysisTest { |
| 249 String completionId; | 249 String completionId; |
| 250 int completionOffset; | 250 int completionOffset; |
| 251 int replacementOffset; | 251 int replacementOffset; |
| 252 int replacementLength; | 252 int replacementLength; |
| 253 List<CompletionSuggestion> suggestions = []; | 253 List<CompletionSuggestion> suggestions = []; |
| 254 bool suggestionsDone = false; | 254 bool suggestionsDone = false; |
| 255 | 255 |
| 256 String addTestFile(String content) { | 256 String addTestFile(String content, {offset}) { |
| 257 completionOffset = content.indexOf('^'); | 257 completionOffset = content.indexOf('^'); |
| 258 if (offset != null) { |
| 259 expect(completionOffset, -1, reason: 'cannot supply offset and ^'); |
| 260 completionOffset = offset; |
| 261 return super.addTestFile(content); |
| 262 } |
| 258 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 263 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
| 259 int nextOffset = content.indexOf('^', completionOffset + 1); | 264 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 260 expect(nextOffset, equals(-1), reason: 'too many ^'); | 265 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| 261 return super.addTestFile(content.substring(0, completionOffset) + | 266 return super.addTestFile(content.substring(0, completionOffset) + |
| 262 content.substring(completionOffset + 1)); | 267 content.substring(completionOffset + 1)); |
| 263 } | 268 } |
| 264 | 269 |
| 265 void assertHasResult(CompletionSuggestionKind kind, String completion, | 270 void assertHasResult(CompletionSuggestionKind kind, String completion, |
| 266 [int relevance = DART_RELEVANCE_DEFAULT, bool isDeprecated = false, | 271 [int relevance = DART_RELEVANCE_DEFAULT, bool isDeprecated = false, |
| 267 bool isPotential = false]) { | 272 bool isPotential = false]) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 assertHasResult( | 434 assertHasResult( |
| 430 CompletionSuggestionKind.INVOCATION, 'a', DART_RELEVANCE_LOCAL_FIELD); | 435 CompletionSuggestionKind.INVOCATION, 'a', DART_RELEVANCE_LOCAL_FIELD); |
| 431 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b', | 436 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b', |
| 432 DART_RELEVANCE_LOCAL_VARIABLE); | 437 DART_RELEVANCE_LOCAL_VARIABLE); |
| 433 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x', | 438 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x', |
| 434 DART_RELEVANCE_LOCAL_METHOD); | 439 DART_RELEVANCE_LOCAL_METHOD); |
| 435 assertHasResult(CompletionSuggestionKind.INVOCATION, 'DateTime'); | 440 assertHasResult(CompletionSuggestionKind.INVOCATION, 'DateTime'); |
| 436 }); | 441 }); |
| 437 } | 442 } |
| 438 | 443 |
| 444 test_offset_past_eof() { |
| 445 addTestFile('main() { }', offset: 300); |
| 446 return getSuggestions().then((_) { |
| 447 expect(replacementOffset, equals(300)); |
| 448 expect(replacementLength, equals(0)); |
| 449 expect(suggestionsDone, true); |
| 450 expect(suggestions.length, 0); |
| 451 }); |
| 452 } |
| 453 |
| 439 test_overrides() { | 454 test_overrides() { |
| 440 addFile('/libA.dart', 'class A {m() {}}'); | 455 addFile('/libA.dart', 'class A {m() {}}'); |
| 441 addTestFile(''' | 456 addTestFile(''' |
| 442 import '/libA.dart'; | 457 import '/libA.dart'; |
| 443 class B extends A {m() {^}} | 458 class B extends A {m() {^}} |
| 444 '''); | 459 '''); |
| 445 return getSuggestions().then((_) { | 460 return getSuggestions().then((_) { |
| 446 expect(replacementOffset, equals(completionOffset)); | 461 expect(replacementOffset, equals(completionOffset)); |
| 447 expect(replacementLength, equals(0)); | 462 expect(replacementLength, equals(0)); |
| 448 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm', | 463 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm', |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 } | 704 } |
| 690 '''); | 705 '''); |
| 691 await waitForTasksFinished(); | 706 await waitForTasksFinished(); |
| 692 Request request = | 707 Request request = |
| 693 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 708 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 694 Response response = handler.handleRequest(request); | 709 Response response = handler.handleRequest(request); |
| 695 expect(response.error, isNotNull); | 710 expect(response.error, isNotNull); |
| 696 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 711 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 697 } | 712 } |
| 698 } | 713 } |
| OLD | NEW |