| 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/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | 10 import 'package:analysis_server/src/domain_completion.dart'; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 main() {foo.^} | 204 main() {foo.^} |
| 205 '''); | 205 '''); |
| 206 return getSuggestions().then((_) { | 206 return getSuggestions().then((_) { |
| 207 expect(replacementOffset, equals(completionOffset)); | 207 expect(replacementOffset, equals(completionOffset)); |
| 208 expect(replacementLength, equals(0)); | 208 expect(replacementLength, equals(0)); |
| 209 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); | 209 assertHasResult(CompletionSuggestionKind.INVOCATION, 'HtmlElement'); |
| 210 assertNoResult('test'); | 210 assertNoResult('test'); |
| 211 }); | 211 }); |
| 212 } | 212 } |
| 213 | 213 |
| 214 test_invocation() { | |
| 215 addTestFile('class A {b() {}} main() {A a; a.^}'); | |
| 216 return getSuggestions().then((_) { | |
| 217 expect(replacementOffset, equals(completionOffset)); | |
| 218 expect(replacementLength, equals(0)); | |
| 219 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); | |
| 220 }); | |
| 221 } | |
| 222 | |
| 223 test_invocation_sdk_relevancy_off() { | |
| 224 var originalSorter = DartCompletionManager.contributionSorter; | |
| 225 var mockSorter = new MockRelevancySorter(); | |
| 226 DartCompletionManager.contributionSorter = mockSorter; | |
| 227 addTestFile('main() {Map m; m.^}'); | |
| 228 return getSuggestions().then((_) { | |
| 229 // Assert that the CommonUsageComputer has been replaced | |
| 230 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), | |
| 231 isFalse); | |
| 232 DartCompletionManager.contributionSorter = originalSorter; | |
| 233 mockSorter.enabled = false; | |
| 234 }); | |
| 235 } | |
| 236 | |
| 237 test_invocation_sdk_relevancy_on() { | |
| 238 addTestFile('main() {Map m; m.^}'); | |
| 239 return getSuggestions().then((_) { | |
| 240 // Assert that the CommonUsageComputer is working | |
| 241 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), | |
| 242 isTrue); | |
| 243 }); | |
| 244 } | |
| 245 | |
| 246 test_invocation_withTrailingStmt() { | |
| 247 addTestFile('class A {b() {}} main() {A a; a.^ int x = 7;}'); | |
| 248 return getSuggestions().then((_) { | |
| 249 expect(replacementOffset, equals(completionOffset)); | |
| 250 expect(replacementLength, equals(0)); | |
| 251 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); | |
| 252 }); | |
| 253 } | |
| 254 | |
| 255 test_inComment_block_beforeNode() async { | 214 test_inComment_block_beforeNode() async { |
| 256 addTestFile(''' | 215 addTestFile(''' |
| 257 main(aaa, bbb) { | 216 main(aaa, bbb) { |
| 258 /* text ^ */ | 217 /* text ^ */ |
| 259 print(42); | 218 print(42); |
| 260 } | 219 } |
| 261 '''); | 220 '''); |
| 262 await getSuggestions(); | 221 await getSuggestions(); |
| 263 expect(suggestions, isEmpty); | 222 expect(suggestions, isEmpty); |
| 264 } | 223 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 x() {^} | 300 x() {^} |
| 342 } | 301 } |
| 343 '''); | 302 '''); |
| 344 return getSuggestions().then((_) { | 303 return getSuggestions().then((_) { |
| 345 expect(replacementOffset, equals(completionOffset)); | 304 expect(replacementOffset, equals(completionOffset)); |
| 346 expect(replacementLength, equals(0)); | 305 expect(replacementLength, equals(0)); |
| 347 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm'); | 306 assertHasResult(CompletionSuggestionKind.INVOCATION, 'm'); |
| 348 }); | 307 }); |
| 349 } | 308 } |
| 350 | 309 |
| 310 test_invocation() { |
| 311 addTestFile('class A {b() {}} main() {A a; a.^}'); |
| 312 return getSuggestions().then((_) { |
| 313 expect(replacementOffset, equals(completionOffset)); |
| 314 expect(replacementLength, equals(0)); |
| 315 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 316 }); |
| 317 } |
| 318 |
| 319 test_invocation_sdk_relevancy_off() { |
| 320 var originalSorter = DartCompletionManager.contributionSorter; |
| 321 var mockSorter = new MockRelevancySorter(); |
| 322 DartCompletionManager.contributionSorter = mockSorter; |
| 323 addTestFile('main() {Map m; m.^}'); |
| 324 return getSuggestions().then((_) { |
| 325 // Assert that the CommonUsageComputer has been replaced |
| 326 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), |
| 327 isFalse); |
| 328 DartCompletionManager.contributionSorter = originalSorter; |
| 329 mockSorter.enabled = false; |
| 330 }); |
| 331 } |
| 332 |
| 333 test_invocation_sdk_relevancy_on() { |
| 334 addTestFile('main() {Map m; m.^}'); |
| 335 return getSuggestions().then((_) { |
| 336 // Assert that the CommonUsageComputer is working |
| 337 expect(suggestions.any((s) => s.relevance == DART_RELEVANCE_COMMON_USAGE), |
| 338 isTrue); |
| 339 }); |
| 340 } |
| 341 |
| 342 test_invocation_withTrailingStmt() { |
| 343 addTestFile('class A {b() {}} main() {A a; a.^ int x = 7;}'); |
| 344 return getSuggestions().then((_) { |
| 345 expect(replacementOffset, equals(completionOffset)); |
| 346 expect(replacementLength, equals(0)); |
| 347 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); |
| 348 }); |
| 349 } |
| 350 |
| 351 test_keyword() { | 351 test_keyword() { |
| 352 addTestFile('library A; cl^'); | 352 addTestFile('library A; cl^'); |
| 353 return getSuggestions().then((_) { | 353 return getSuggestions().then((_) { |
| 354 expect(replacementOffset, equals(completionOffset - 2)); | 354 expect(replacementOffset, equals(completionOffset - 2)); |
| 355 expect(replacementLength, equals(2)); | 355 expect(replacementLength, equals(2)); |
| 356 assertHasResult(CompletionSuggestionKind.KEYWORD, 'export', | 356 assertHasResult(CompletionSuggestionKind.KEYWORD, 'export', |
| 357 relevance: DART_RELEVANCE_HIGH); | 357 relevance: DART_RELEVANCE_HIGH); |
| 358 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class', | 358 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class', |
| 359 relevance: DART_RELEVANCE_HIGH); | 359 relevance: DART_RELEVANCE_HIGH); |
| 360 }); | 360 }); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } | 543 } |
| 544 '''); | 544 '''); |
| 545 await waitForTasksFinished(); | 545 await waitForTasksFinished(); |
| 546 Request request = | 546 Request request = |
| 547 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); | 547 new CompletionGetSuggestionsParams(testFile, 0).toRequest('0'); |
| 548 Response response = handler.handleRequest(request); | 548 Response response = handler.handleRequest(request); |
| 549 expect(response.error, isNotNull); | 549 expect(response.error, isNotNull); |
| 550 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 550 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
| 551 } | 551 } |
| 552 } | 552 } |
| OLD | NEW |