| 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.util; | 5 library test.services.completion.dart.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| 11 import 'package:analysis_server/plugin/protocol/protocol.dart' | 11 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 12 hide Element, ElementKind; | 12 hide Element, ElementKind; |
| 13 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 13 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 14 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
| 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
| 16 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' | 16 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' |
| 17 show DartCompletionRequestImpl; | 17 show DartCompletionRequestImpl; |
| 18 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' | 18 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' |
| 19 show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOW; | 19 show DART_RELEVANCE_DEFAULT, DART_RELEVANCE_LOW, ReplacementRange; |
| 20 import 'package:analysis_server/src/services/index/index.dart'; | 20 import 'package:analysis_server/src/services/index/index.dart'; |
| 21 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 21 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| 22 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 22 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:unittest/unittest.dart'; | 24 import 'package:unittest/unittest.dart'; |
| 25 | 25 |
| 26 import '../../../abstract_context.dart'; | 26 import '../../../abstract_context.dart'; |
| 27 | 27 |
| 28 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { | 28 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { |
| 29 String c1 = s1.completion.toLowerCase(); | 29 String c1 = s1.completion.toLowerCase(); |
| 30 String c2 = s2.completion.toLowerCase(); | 30 String c2 = s2.completion.toLowerCase(); |
| 31 return c1.compareTo(c2); | 31 return c1.compareTo(c2); |
| 32 } | 32 } |
| 33 | 33 |
| 34 abstract class DartCompletionContributorTest extends AbstractContextTest { | 34 abstract class DartCompletionContributorTest extends AbstractContextTest { |
| 35 Index index; | 35 Index index; |
| 36 SearchEngineImpl searchEngine; | 36 SearchEngineImpl searchEngine; |
| 37 String testFile = '/completionTest.dart'; | 37 String testFile = '/completionTest.dart'; |
| 38 Source testSource; | 38 Source testSource; |
| 39 int completionOffset; | 39 int completionOffset; |
| 40 int replacementOffset; |
| 41 int replacementLength; |
| 40 DartCompletionContributor contributor; | 42 DartCompletionContributor contributor; |
| 41 DartCompletionRequest request; | 43 DartCompletionRequest request; |
| 42 List<CompletionSuggestion> suggestions; | 44 List<CompletionSuggestion> suggestions; |
| 43 | 45 |
| 44 void addTestSource(String content) { | 46 void addTestSource(String content) { |
| 45 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); | 47 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
| 46 completionOffset = content.indexOf('^'); | 48 completionOffset = content.indexOf('^'); |
| 47 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 49 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
| 48 int nextOffset = content.indexOf('^', completionOffset + 1); | 50 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 49 expect(nextOffset, equals(-1), reason: 'too many ^'); | 51 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // would therefore not wait for microtask callbacks that are scheduled after | 144 // would therefore not wait for microtask callbacks that are scheduled after |
| 143 // invoking this method. | 145 // invoking this method. |
| 144 return new Future.delayed( | 146 return new Future.delayed( |
| 145 Duration.ZERO, () => computeLibrariesContaining(times - 1)); | 147 Duration.ZERO, () => computeLibrariesContaining(times - 1)); |
| 146 } | 148 } |
| 147 | 149 |
| 148 Future computeSuggestions([int times = 200]) async { | 150 Future computeSuggestions([int times = 200]) async { |
| 149 CompletionRequestImpl baseRequest = new CompletionRequestImpl( | 151 CompletionRequestImpl baseRequest = new CompletionRequestImpl( |
| 150 context, provider, searchEngine, testSource, completionOffset); | 152 context, provider, searchEngine, testSource, completionOffset); |
| 151 request = new DartCompletionRequestImpl.forRequest(baseRequest); | 153 request = new DartCompletionRequestImpl.forRequest(baseRequest); |
| 154 var range = new ReplacementRange.compute(request.offset, request.target); |
| 155 replacementOffset = range.offset; |
| 156 replacementLength = range.length; |
| 152 Completer<List<CompletionSuggestion>> completer = | 157 Completer<List<CompletionSuggestion>> completer = |
| 153 new Completer<List<CompletionSuggestion>>(); | 158 new Completer<List<CompletionSuggestion>>(); |
| 154 | 159 |
| 155 // Request completions | 160 // Request completions |
| 156 contributor | 161 contributor |
| 157 .computeSuggestions(request) | 162 .computeSuggestions(request) |
| 158 .then((List<CompletionSuggestion> computedSuggestions) { | 163 .then((List<CompletionSuggestion> computedSuggestions) { |
| 159 completer.complete(computedSuggestions); | 164 completer.complete(computedSuggestions); |
| 160 }); | 165 }); |
| 161 | 166 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 229 } |
| 225 | 230 |
| 226 @override | 231 @override |
| 227 void setUp() { | 232 void setUp() { |
| 228 super.setUp(); | 233 super.setUp(); |
| 229 index = createLocalMemoryIndex(); | 234 index = createLocalMemoryIndex(); |
| 230 searchEngine = new SearchEngineImpl(index); | 235 searchEngine = new SearchEngineImpl(index); |
| 231 contributor = createContributor(); | 236 contributor = createContributor(); |
| 232 } | 237 } |
| 233 } | 238 } |
| OLD | NEW |