| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 int elemOffset}) { | 105 int elemOffset}) { |
| 106 CompletionSuggestion cs = | 106 CompletionSuggestion cs = |
| 107 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 107 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
| 108 if (cs == null) { | 108 if (cs == null) { |
| 109 failedCompletion('expected $completion $csKind $elemKind', suggestions); | 109 failedCompletion('expected $completion $csKind $elemKind', suggestions); |
| 110 } | 110 } |
| 111 expect(cs.kind, equals(csKind)); | 111 expect(cs.kind, equals(csKind)); |
| 112 if (isDeprecated) { | 112 if (isDeprecated) { |
| 113 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 113 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
| 114 } else { | 114 } else { |
| 115 expect(cs.relevance, equals(relevance)); | 115 expect(cs.relevance, equals(relevance), reason: completion); |
| 116 } | 116 } |
| 117 expect(cs.importUri, importUri); | 117 expect(cs.importUri, importUri); |
| 118 expect(cs.selectionOffset, equals(completion.length)); | 118 expect(cs.selectionOffset, equals(completion.length)); |
| 119 expect(cs.selectionLength, equals(0)); | 119 expect(cs.selectionLength, equals(0)); |
| 120 expect(cs.isDeprecated, equals(isDeprecated)); | 120 expect(cs.isDeprecated, equals(isDeprecated)); |
| 121 expect(cs.isPotential, equals(isPotential)); | 121 expect(cs.isPotential, equals(isPotential)); |
| 122 if (cs.element != null) { | 122 if (cs.element != null) { |
| 123 expect(cs.element.location, isNotNull); | 123 expect(cs.element.location, isNotNull); |
| 124 expect(cs.element.location.file, isNotNull); | 124 expect(cs.element.location.file, isNotNull); |
| 125 expect(cs.element.location.offset, isNotNull); | 125 expect(cs.element.location.offset, isNotNull); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 153 protocol.Element element = cs.element; | 153 protocol.Element element = cs.element; |
| 154 expect(element, isNotNull); | 154 expect(element, isNotNull); |
| 155 expect(element.kind, equals(protocol.ElementKind.CLASS)); | 155 expect(element.kind, equals(protocol.ElementKind.CLASS)); |
| 156 expect(element.name, equals(name)); | 156 expect(element.name, equals(name)); |
| 157 expect(element.parameters, isNull); | 157 expect(element.parameters, isNull); |
| 158 expect(element.returnType, isNull); | 158 expect(element.returnType, isNull); |
| 159 assertHasNoParameterInfo(cs); | 159 assertHasNoParameterInfo(cs); |
| 160 return cs; | 160 return cs; |
| 161 } | 161 } |
| 162 | 162 |
| 163 CompletionSuggestion assertSuggestClassTypeAlias(String name, |
| 164 {int relevance: DART_RELEVANCE_DEFAULT, |
| 165 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { |
| 166 CompletionSuggestion cs = |
| 167 assertSuggest(name, csKind: kind, relevance: relevance); |
| 168 protocol.Element element = cs.element; |
| 169 expect(element, isNotNull); |
| 170 expect(element.kind, equals(protocol.ElementKind.CLASS_TYPE_ALIAS)); |
| 171 expect(element.name, equals(name)); |
| 172 expect(element.parameters, isNull); |
| 173 expect(element.returnType, isNull); |
| 174 assertHasNoParameterInfo(cs); |
| 175 return cs; |
| 176 } |
| 177 |
| 163 CompletionSuggestion assertSuggestConstructor(String name, | 178 CompletionSuggestion assertSuggestConstructor(String name, |
| 164 {int relevance: DART_RELEVANCE_DEFAULT, | 179 {int relevance: DART_RELEVANCE_DEFAULT, |
| 165 String importUri, | 180 String importUri, |
| 166 int elemOffset}) { | 181 int elemOffset}) { |
| 167 CompletionSuggestion cs = assertSuggest(name, | 182 CompletionSuggestion cs = assertSuggest(name, |
| 168 relevance: relevance, importUri: importUri, elemOffset: elemOffset); | 183 relevance: relevance, importUri: importUri, elemOffset: elemOffset); |
| 169 protocol.Element element = cs.element; | 184 protocol.Element element = cs.element; |
| 170 expect(element, isNotNull); | 185 expect(element, isNotNull); |
| 171 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); | 186 expect(element.kind, equals(protocol.ElementKind.CONSTRUCTOR)); |
| 172 int index = name.indexOf('.'); | 187 int index = name.indexOf('.'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 expect(element.name, equals(name)); | 226 expect(element.name, equals(name)); |
| 212 expect(element.parameters, isNull); | 227 expect(element.parameters, isNull); |
| 213 // The returnType represents the type of a field | 228 // The returnType represents the type of a field |
| 214 expect(element.returnType, type != null ? type : 'dynamic'); | 229 expect(element.returnType, type != null ? type : 'dynamic'); |
| 215 assertHasNoParameterInfo(cs); | 230 assertHasNoParameterInfo(cs); |
| 216 return cs; | 231 return cs; |
| 217 } | 232 } |
| 218 | 233 |
| 219 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 234 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 220 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 235 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 221 bool deprecated: false, | 236 bool isDeprecated: false, |
| 222 int relevance: DART_RELEVANCE_DEFAULT, | 237 int relevance: DART_RELEVANCE_DEFAULT, |
| 223 String importUri}) { | 238 String importUri}) { |
| 224 CompletionSuggestion cs = assertSuggest(name, | 239 CompletionSuggestion cs = assertSuggest(name, |
| 225 csKind: kind, | 240 csKind: kind, |
| 226 relevance: relevance, | 241 relevance: relevance, |
| 227 importUri: importUri, | 242 importUri: importUri, |
| 228 isDeprecated: deprecated); | 243 isDeprecated: isDeprecated); |
| 229 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 244 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 230 protocol.Element element = cs.element; | 245 protocol.Element element = cs.element; |
| 231 expect(element, isNotNull); | 246 expect(element, isNotNull); |
| 232 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 247 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
| 233 expect(element.name, equals(name)); | 248 expect(element.name, equals(name)); |
| 234 expect(element.isDeprecated, equals(deprecated)); | 249 expect(element.isDeprecated, equals(isDeprecated)); |
| 235 String param = element.parameters; | 250 String param = element.parameters; |
| 236 expect(param, isNotNull); | 251 expect(param, isNotNull); |
| 237 expect(param[0], equals('(')); | 252 expect(param[0], equals('(')); |
| 238 expect(param[param.length - 1], equals(')')); | 253 expect(param[param.length - 1], equals(')')); |
| 239 expect(element.returnType, | 254 expect(element.returnType, |
| 240 equals(returnType != null ? returnType : 'dynamic')); | 255 equals(returnType != null ? returnType : 'dynamic')); |
| 241 assertHasParameterInfo(cs); | 256 assertHasParameterInfo(cs); |
| 242 return cs; | 257 return cs; |
| 243 } | 258 } |
| 244 | 259 |
| 245 CompletionSuggestion assertSuggestFunctionTypeAlias( | 260 CompletionSuggestion assertSuggestFunctionTypeAlias( |
| 246 String name, String returnType, bool isDeprecated, | 261 String name, String returnType, {bool isDeprecated: false, |
| 247 [int relevance = DART_RELEVANCE_DEFAULT, | 262 int relevance: DART_RELEVANCE_DEFAULT, |
| 248 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION, | 263 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 249 String importUri]) { | 264 String importUri}) { |
| 250 CompletionSuggestion cs = assertSuggest(name, | 265 CompletionSuggestion cs = assertSuggest(name, |
| 251 csKind: kind, | 266 csKind: kind, |
| 252 relevance: relevance, | 267 relevance: relevance, |
| 253 importUri: importUri, | 268 importUri: importUri, |
| 254 isDeprecated: isDeprecated); | 269 isDeprecated: isDeprecated); |
| 255 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 270 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 256 protocol.Element element = cs.element; | 271 protocol.Element element = cs.element; |
| 257 expect(element, isNotNull); | 272 expect(element, isNotNull); |
| 258 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); | 273 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); |
| 259 expect(element.name, equals(name)); | 274 expect(element.name, equals(name)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 String param = element.parameters; | 328 String param = element.parameters; |
| 314 expect(param, isNotNull); | 329 expect(param, isNotNull); |
| 315 expect(param[0], equals('(')); | 330 expect(param[0], equals('(')); |
| 316 expect(param[param.length - 1], equals(')')); | 331 expect(param[param.length - 1], equals(')')); |
| 317 expect(element.returnType, returnType != null ? returnType : 'dynamic'); | 332 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
| 318 assertHasParameterInfo(cs); | 333 assertHasParameterInfo(cs); |
| 319 return cs; | 334 return cs; |
| 320 } | 335 } |
| 321 | 336 |
| 322 CompletionSuggestion assertSuggestSetter(String name, | 337 CompletionSuggestion assertSuggestSetter(String name, |
| 323 [int relevance = DART_RELEVANCE_DEFAULT, | 338 {int relevance: DART_RELEVANCE_DEFAULT, |
| 324 String importUri, | 339 String importUri, |
| 325 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 340 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) { |
| 326 CompletionSuggestion cs = assertSuggest(name, | 341 CompletionSuggestion cs = assertSuggest(name, |
| 327 csKind: kind, | 342 csKind: kind, |
| 328 relevance: relevance, | 343 relevance: relevance, |
| 329 importUri: importUri, | 344 importUri: importUri, |
| 330 elemKind: protocol.ElementKind.SETTER); | 345 elemKind: protocol.ElementKind.SETTER); |
| 331 protocol.Element element = cs.element; | 346 protocol.Element element = cs.element; |
| 332 expect(element, isNotNull); | 347 expect(element, isNotNull); |
| 333 expect(element.kind, equals(protocol.ElementKind.SETTER)); | 348 expect(element.kind, equals(protocol.ElementKind.SETTER)); |
| 334 expect(element.name, equals(name)); | 349 expect(element.name, equals(name)); |
| 335 // TODO (danrubel) assert setter param | 350 // TODO (danrubel) assert setter param |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 487 } |
| 473 | 488 |
| 474 @override | 489 @override |
| 475 void setUp() { | 490 void setUp() { |
| 476 super.setUp(); | 491 super.setUp(); |
| 477 index = createLocalMemoryIndex(); | 492 index = createLocalMemoryIndex(); |
| 478 searchEngine = new SearchEngineImpl(index); | 493 searchEngine = new SearchEngineImpl(index); |
| 479 contributor = createContributor(); | 494 contributor = createContributor(); |
| 480 } | 495 } |
| 481 } | 496 } |
| OLD | NEW |