| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 108 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
| 109 int relevance: DART_RELEVANCE_DEFAULT, | 109 int relevance: DART_RELEVANCE_DEFAULT, |
| 110 String importUri, | 110 String importUri, |
| 111 protocol.ElementKind elemKind: null, | 111 protocol.ElementKind elemKind: null, |
| 112 bool isDeprecated: false, | 112 bool isDeprecated: false, |
| 113 bool isPotential: false, | 113 bool isPotential: false, |
| 114 String elemFile, | 114 String elemFile, |
| 115 int elemOffset, | 115 int elemOffset, |
| 116 String paramName, | 116 String paramName, |
| 117 String paramType, | 117 String paramType, |
| 118 String defaultArgListString}) { | 118 String defaultArgListString, |
| 119 List<int> defaultArgumentListTextRanges}) { |
| 119 CompletionSuggestion cs = | 120 CompletionSuggestion cs = |
| 120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 121 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
| 121 if (cs == null) { | 122 if (cs == null) { |
| 122 failedCompletion('expected $completion $csKind $elemKind', suggestions); | 123 failedCompletion('expected $completion $csKind $elemKind', suggestions); |
| 123 } | 124 } |
| 124 expect(cs.kind, equals(csKind)); | 125 expect(cs.kind, equals(csKind)); |
| 125 if (isDeprecated) { | 126 if (isDeprecated) { |
| 126 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 127 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
| 127 } else { | 128 } else { |
| 128 expect(cs.relevance, equals(relevance), reason: completion); | 129 expect(cs.relevance, equals(relevance), reason: completion); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 148 } | 149 } |
| 149 if (paramName != null) { | 150 if (paramName != null) { |
| 150 expect(cs.parameterName, paramName); | 151 expect(cs.parameterName, paramName); |
| 151 } | 152 } |
| 152 if (paramType != null) { | 153 if (paramType != null) { |
| 153 expect(cs.parameterType, paramType); | 154 expect(cs.parameterType, paramType); |
| 154 } | 155 } |
| 155 if (defaultArgListString != null) { | 156 if (defaultArgListString != null) { |
| 156 expect(cs.defaultArgumentListString, defaultArgListString); | 157 expect(cs.defaultArgumentListString, defaultArgListString); |
| 157 } | 158 } |
| 159 if (defaultArgumentListTextRanges != null) { |
| 160 expect(cs.defaultArgumentListTextRanges, defaultArgumentListTextRanges); |
| 161 } |
| 158 return cs; | 162 return cs; |
| 159 } | 163 } |
| 160 | 164 |
| 161 CompletionSuggestion assertSuggestClass(String name, | 165 CompletionSuggestion assertSuggestClass(String name, |
| 162 {int relevance: DART_RELEVANCE_DEFAULT, | 166 {int relevance: DART_RELEVANCE_DEFAULT, |
| 163 String importUri, | 167 String importUri, |
| 164 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 168 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 165 bool isDeprecated: false, | 169 bool isDeprecated: false, |
| 166 String elemFile, | 170 String elemFile, |
| 167 String elemName, | 171 String elemName, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 197 assertHasNoParameterInfo(cs); | 201 assertHasNoParameterInfo(cs); |
| 198 return cs; | 202 return cs; |
| 199 } | 203 } |
| 200 | 204 |
| 201 CompletionSuggestion assertSuggestConstructor(String name, | 205 CompletionSuggestion assertSuggestConstructor(String name, |
| 202 {int relevance: DART_RELEVANCE_DEFAULT, | 206 {int relevance: DART_RELEVANCE_DEFAULT, |
| 203 String importUri, | 207 String importUri, |
| 204 int elemOffset, | 208 int elemOffset, |
| 205 String defaultArgListString}) { | 209 String defaultArgListString}) { |
| 206 CompletionSuggestion cs = assertSuggest(name, | 210 CompletionSuggestion cs = assertSuggest(name, |
| 207 relevance: relevance, importUri: importUri, elemOffset: elemOffset, | 211 relevance: relevance, |
| 212 importUri: importUri, |
| 213 elemOffset: elemOffset, |
| 208 defaultArgListString: defaultArgListString); | 214 defaultArgListString: defaultArgListString); |
| 209 protocol.Element element = cs.element; | 215 protocol.Element element = cs.element; |
| 210 expect(element, isNotNull); | 216 expect(element, isNotNull); |
| 211 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | 217 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); |
| 212 int index = name.indexOf('.'); | 218 int index = name.indexOf('.'); |
| 213 expect(element.name, index >= 0 ? name.substring(index + 1) : ''); | 219 expect(element.name, index >= 0 ? name.substring(index + 1) : ''); |
| 214 return cs; | 220 return cs; |
| 215 } | 221 } |
| 216 | 222 |
| 217 CompletionSuggestion assertSuggestEnum(String completion, | 223 CompletionSuggestion assertSuggestEnum(String completion, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 expect(element.returnType, type != null ? type : 'dynamic'); | 261 expect(element.returnType, type != null ? type : 'dynamic'); |
| 256 assertHasNoParameterInfo(cs); | 262 assertHasNoParameterInfo(cs); |
| 257 return cs; | 263 return cs; |
| 258 } | 264 } |
| 259 | 265 |
| 260 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 266 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 261 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 267 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 262 bool isDeprecated: false, | 268 bool isDeprecated: false, |
| 263 int relevance: DART_RELEVANCE_DEFAULT, | 269 int relevance: DART_RELEVANCE_DEFAULT, |
| 264 String importUri, | 270 String importUri, |
| 265 String defaultArgListString}) { | 271 String defaultArgListString, |
| 272 List<int> defaultArgumentListTextRanges}) { |
| 266 CompletionSuggestion cs = assertSuggest(name, | 273 CompletionSuggestion cs = assertSuggest(name, |
| 267 csKind: kind, | 274 csKind: kind, |
| 268 relevance: relevance, | 275 relevance: relevance, |
| 269 importUri: importUri, | 276 importUri: importUri, |
| 270 isDeprecated: isDeprecated, | 277 isDeprecated: isDeprecated, |
| 271 defaultArgListString: defaultArgListString); | 278 defaultArgListString: defaultArgListString, |
| 279 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
| 272 if (returnType != null) { | 280 if (returnType != null) { |
| 273 expect(cs.returnType, returnType); | 281 expect(cs.returnType, returnType); |
| 274 } else if (isNullExpectedReturnTypeConsideredDynamic) { | 282 } else if (isNullExpectedReturnTypeConsideredDynamic) { |
| 275 expect(cs.returnType, 'dynamic'); | 283 expect(cs.returnType, 'dynamic'); |
| 276 } | 284 } |
| 277 protocol.Element element = cs.element; | 285 protocol.Element element = cs.element; |
| 278 expect(element, isNotNull); | 286 expect(element, isNotNull); |
| 279 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 287 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
| 280 expect(element.name, equals(name)); | 288 expect(element.name, equals(name)); |
| 281 expect(element.isDeprecated, equals(isDeprecated)); | 289 expect(element.isDeprecated, equals(isDeprecated)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 assertHasNoParameterInfo(cs); | 357 assertHasNoParameterInfo(cs); |
| 350 return cs; | 358 return cs; |
| 351 } | 359 } |
| 352 | 360 |
| 353 CompletionSuggestion assertSuggestMethod( | 361 CompletionSuggestion assertSuggestMethod( |
| 354 String name, String declaringType, String returnType, | 362 String name, String declaringType, String returnType, |
| 355 {int relevance: DART_RELEVANCE_DEFAULT, | 363 {int relevance: DART_RELEVANCE_DEFAULT, |
| 356 String importUri, | 364 String importUri, |
| 357 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 365 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 358 bool isDeprecated: false, | 366 bool isDeprecated: false, |
| 359 String defaultArgListString}) { | 367 String defaultArgListString, |
| 368 List<int> defaultArgumentListTextRanges}) { |
| 360 CompletionSuggestion cs = assertSuggest(name, | 369 CompletionSuggestion cs = assertSuggest(name, |
| 361 csKind: kind, | 370 csKind: kind, |
| 362 relevance: relevance, | 371 relevance: relevance, |
| 363 importUri: importUri, | 372 importUri: importUri, |
| 364 isDeprecated: isDeprecated, | 373 isDeprecated: isDeprecated, |
| 365 defaultArgListString: defaultArgListString); | 374 defaultArgListString: defaultArgListString, |
| 375 defaultArgumentListTextRanges: defaultArgumentListTextRanges); |
| 366 expect(cs.declaringType, equals(declaringType)); | 376 expect(cs.declaringType, equals(declaringType)); |
| 367 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 377 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 368 protocol.Element element = cs.element; | 378 protocol.Element element = cs.element; |
| 369 expect(element, isNotNull); | 379 expect(element, isNotNull); |
| 370 expect(element.kind, equals(protocol.ElementKind.METHOD)); | 380 expect(element.kind, equals(protocol.ElementKind.METHOD)); |
| 371 expect(element.name, equals(name)); | 381 expect(element.name, equals(name)); |
| 372 String param = element.parameters; | 382 String param = element.parameters; |
| 373 expect(param, isNotNull); | 383 expect(param, isNotNull); |
| 374 expect(param[0], equals('(')); | 384 expect(param[0], equals('(')); |
| 375 expect(param[param.length - 1], equals(')')); | 385 expect(param[param.length - 1], equals(')')); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 599 |
| 590 @override | 600 @override |
| 591 void setUp() { | 601 void setUp() { |
| 592 super.setUp(); | 602 super.setUp(); |
| 593 index = createMemoryIndex(); | 603 index = createMemoryIndex(); |
| 594 searchEngine = | 604 searchEngine = |
| 595 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); | 605 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); |
| 596 contributor = createContributor(); | 606 contributor = createContributor(); |
| 597 } | 607 } |
| 598 } | 608 } |
| OLD | NEW |