| 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; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import '../../../abstract_context.dart'; | 30 import '../../../abstract_context.dart'; |
| 31 import '../../correction/flutter_util.dart'; | 31 import '../../correction/flutter_util.dart'; |
| 32 | 32 |
| 33 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { | 33 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { |
| 34 String c1 = s1.completion.toLowerCase(); | 34 String c1 = s1.completion.toLowerCase(); |
| 35 String c2 = s2.completion.toLowerCase(); | 35 String c2 = s2.completion.toLowerCase(); |
| 36 return c1.compareTo(c2); | 36 return c1.compareTo(c2); |
| 37 } | 37 } |
| 38 | 38 |
| 39 abstract class DartCompletionContributorTest extends AbstractContextTest { | 39 abstract class DartCompletionContributorTest extends AbstractContextTest { |
| 40 static const String _UNCHECKED = '__UNCHECKED__'; |
| 40 Index index; | 41 Index index; |
| 41 SearchEngineImpl searchEngine; | 42 SearchEngineImpl searchEngine; |
| 42 String testFile = '/completionTest.dart'; | 43 String testFile = '/completionTest.dart'; |
| 43 Source testSource; | 44 Source testSource; |
| 44 int completionOffset; | 45 int completionOffset; |
| 45 int replacementOffset; | 46 int replacementOffset; |
| 46 int replacementLength; | 47 int replacementLength; |
| 47 DartCompletionContributor contributor; | 48 DartCompletionContributor contributor; |
| 48 DartCompletionRequest request; | 49 DartCompletionRequest request; |
| 49 List<CompletionSuggestion> suggestions; | 50 List<CompletionSuggestion> suggestions; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 113 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
| 113 int relevance: DART_RELEVANCE_DEFAULT, | 114 int relevance: DART_RELEVANCE_DEFAULT, |
| 114 String importUri, | 115 String importUri, |
| 115 protocol.ElementKind elemKind: null, | 116 protocol.ElementKind elemKind: null, |
| 116 bool isDeprecated: false, | 117 bool isDeprecated: false, |
| 117 bool isPotential: false, | 118 bool isPotential: false, |
| 118 String elemFile, | 119 String elemFile, |
| 119 int elemOffset, | 120 int elemOffset, |
| 120 String paramName, | 121 String paramName, |
| 121 String paramType, | 122 String paramType, |
| 122 String defaultArgListString, | 123 String defaultArgListString: _UNCHECKED, |
| 123 List<int> defaultArgumentListTextRanges}) { | 124 List<int> defaultArgumentListTextRanges}) { |
| 124 CompletionSuggestion cs = | 125 CompletionSuggestion cs = |
| 125 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 126 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
| 126 if (cs == null) { | 127 if (cs == null) { |
| 127 failedCompletion('expected $completion $csKind $elemKind', suggestions); | 128 failedCompletion('expected $completion $csKind $elemKind', suggestions); |
| 128 } | 129 } |
| 129 expect(cs.kind, equals(csKind)); | 130 expect(cs.kind, equals(csKind)); |
| 130 if (isDeprecated) { | 131 if (isDeprecated) { |
| 131 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 132 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
| 132 } else { | 133 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 150 } | 151 } |
| 151 if (elemOffset != null) { | 152 if (elemOffset != null) { |
| 152 expect(cs.element.location.offset, elemOffset); | 153 expect(cs.element.location.offset, elemOffset); |
| 153 } | 154 } |
| 154 if (paramName != null) { | 155 if (paramName != null) { |
| 155 expect(cs.parameterName, paramName); | 156 expect(cs.parameterName, paramName); |
| 156 } | 157 } |
| 157 if (paramType != null) { | 158 if (paramType != null) { |
| 158 expect(cs.parameterType, paramType); | 159 expect(cs.parameterType, paramType); |
| 159 } | 160 } |
| 160 if (defaultArgListString != null) { | 161 if (defaultArgListString != _UNCHECKED) { |
| 161 expect(cs.defaultArgumentListString, defaultArgListString); | 162 expect(cs.defaultArgumentListString, defaultArgListString); |
| 162 } | 163 } |
| 163 if (defaultArgumentListTextRanges != null) { | 164 if (defaultArgumentListTextRanges != null) { |
| 164 expect(cs.defaultArgumentListTextRanges, defaultArgumentListTextRanges); | 165 expect(cs.defaultArgumentListTextRanges, defaultArgumentListTextRanges); |
| 165 } | 166 } |
| 166 return cs; | 167 return cs; |
| 167 } | 168 } |
| 168 | 169 |
| 169 CompletionSuggestion assertSuggestClass(String name, | 170 CompletionSuggestion assertSuggestClass(String name, |
| 170 {int relevance: DART_RELEVANCE_DEFAULT, | 171 {int relevance: DART_RELEVANCE_DEFAULT, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 expect(element.parameters, isNull); | 204 expect(element.parameters, isNull); |
| 204 expect(element.returnType, isNull); | 205 expect(element.returnType, isNull); |
| 205 assertHasNoParameterInfo(cs); | 206 assertHasNoParameterInfo(cs); |
| 206 return cs; | 207 return cs; |
| 207 } | 208 } |
| 208 | 209 |
| 209 CompletionSuggestion assertSuggestConstructor(String name, | 210 CompletionSuggestion assertSuggestConstructor(String name, |
| 210 {int relevance: DART_RELEVANCE_DEFAULT, | 211 {int relevance: DART_RELEVANCE_DEFAULT, |
| 211 String importUri, | 212 String importUri, |
| 212 int elemOffset, | 213 int elemOffset, |
| 213 String defaultArgListString, | 214 String defaultArgListString: _UNCHECKED, |
| 214 List<int> defaultArgumentListTextRanges}) { | 215 List<int> defaultArgumentListTextRanges}) { |
| 215 CompletionSuggestion cs = assertSuggest(name, | 216 CompletionSuggestion cs = assertSuggest(name, |
| 216 relevance: relevance, | 217 relevance: relevance, |
| 217 importUri: importUri, | 218 importUri: importUri, |
| 218 elemOffset: elemOffset, | 219 elemOffset: elemOffset, |
| 219 defaultArgListString: defaultArgListString, | 220 defaultArgListString: defaultArgListString, |
| 220 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 221 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
| 221 protocol.Element element = cs.element; | 222 protocol.Element element = cs.element; |
| 222 expect(element, isNotNull); | 223 expect(element, isNotNull); |
| 223 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | 224 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 expect(element.returnType, type != null ? type : 'dynamic'); | 268 expect(element.returnType, type != null ? type : 'dynamic'); |
| 268 assertHasNoParameterInfo(cs); | 269 assertHasNoParameterInfo(cs); |
| 269 return cs; | 270 return cs; |
| 270 } | 271 } |
| 271 | 272 |
| 272 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 273 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 273 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 274 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 274 bool isDeprecated: false, | 275 bool isDeprecated: false, |
| 275 int relevance: DART_RELEVANCE_DEFAULT, | 276 int relevance: DART_RELEVANCE_DEFAULT, |
| 276 String importUri, | 277 String importUri, |
| 277 String defaultArgListString, | 278 String defaultArgListString: _UNCHECKED, |
| 278 List<int> defaultArgumentListTextRanges}) { | 279 List<int> defaultArgumentListTextRanges}) { |
| 279 CompletionSuggestion cs = assertSuggest(name, | 280 CompletionSuggestion cs = assertSuggest(name, |
| 280 csKind: kind, | 281 csKind: kind, |
| 281 relevance: relevance, | 282 relevance: relevance, |
| 282 importUri: importUri, | 283 importUri: importUri, |
| 283 isDeprecated: isDeprecated, | 284 isDeprecated: isDeprecated, |
| 284 defaultArgListString: defaultArgListString, | 285 defaultArgListString: defaultArgListString, |
| 285 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 286 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
| 286 if (returnType != null) { | 287 if (returnType != null) { |
| 287 expect(cs.returnType, returnType); | 288 expect(cs.returnType, returnType); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 assertHasNoParameterInfo(cs); | 364 assertHasNoParameterInfo(cs); |
| 364 return cs; | 365 return cs; |
| 365 } | 366 } |
| 366 | 367 |
| 367 CompletionSuggestion assertSuggestMethod( | 368 CompletionSuggestion assertSuggestMethod( |
| 368 String name, String declaringType, String returnType, | 369 String name, String declaringType, String returnType, |
| 369 {int relevance: DART_RELEVANCE_DEFAULT, | 370 {int relevance: DART_RELEVANCE_DEFAULT, |
| 370 String importUri, | 371 String importUri, |
| 371 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 372 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 372 bool isDeprecated: false, | 373 bool isDeprecated: false, |
| 373 String defaultArgListString, | 374 String defaultArgListString: _UNCHECKED, |
| 374 List<int> defaultArgumentListTextRanges}) { | 375 List<int> defaultArgumentListTextRanges}) { |
| 375 CompletionSuggestion cs = assertSuggest(name, | 376 CompletionSuggestion cs = assertSuggest(name, |
| 376 csKind: kind, | 377 csKind: kind, |
| 377 relevance: relevance, | 378 relevance: relevance, |
| 378 importUri: importUri, | 379 importUri: importUri, |
| 379 isDeprecated: isDeprecated, | 380 isDeprecated: isDeprecated, |
| 380 defaultArgListString: defaultArgListString, | 381 defaultArgListString: defaultArgListString, |
| 381 defaultArgumentListTextRanges: defaultArgumentListTextRanges); | 382 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
| 382 expect(cs.declaringType, equals(declaringType)); | 383 expect(cs.declaringType, equals(declaringType)); |
| 383 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 384 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 635 |
| 635 @override | 636 @override |
| 636 void setUp() { | 637 void setUp() { |
| 637 super.setUp(); | 638 super.setUp(); |
| 638 index = createMemoryIndex(); | 639 index = createMemoryIndex(); |
| 639 searchEngine = | 640 searchEngine = |
| 640 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); | 641 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); |
| 641 contributor = createContributor(); | 642 contributor = createContributor(); |
| 642 } | 643 } |
| 643 } | 644 } |
| OLD | NEW |