| 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.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart' as protocol | 10 import 'package:analysis_server/src/protocol.dart' as protocol |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 CompletionSuggestion assertSuggest(String completion, | 115 CompletionSuggestion assertSuggest(String completion, |
| 116 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 116 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
| 117 int relevance: DART_RELEVANCE_DEFAULT, | 117 int relevance: DART_RELEVANCE_DEFAULT, |
| 118 String importUri, | 118 String importUri, |
| 119 protocol.ElementKind elemKind: null, | 119 protocol.ElementKind elemKind: null, |
| 120 bool isDeprecated: false, | 120 bool isDeprecated: false, |
| 121 bool isPotential: false, | 121 bool isPotential: false, |
| 122 String elemFile, | 122 String elemFile, |
| 123 int elemOffset, | 123 int elemOffset}) { |
| 124 docCompleteMatcher, | |
| 125 docSummaryMatcher}) { | |
| 126 CompletionSuggestion cs = | 124 CompletionSuggestion cs = |
| 127 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 125 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
| 128 if (cs == null) { | 126 if (cs == null) { |
| 129 failedCompletion( | 127 failedCompletion( |
| 130 'expected $completion $csKind $elemKind', request.suggestions); | 128 'expected $completion $csKind $elemKind', request.suggestions); |
| 131 } | 129 } |
| 132 expect(cs.kind, equals(csKind)); | 130 expect(cs.kind, equals(csKind)); |
| 133 if (isDeprecated) { | 131 if (isDeprecated) { |
| 134 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 132 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
| 135 } else { | 133 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 147 expect(cs.element.location.length, isNotNull); | 145 expect(cs.element.location.length, isNotNull); |
| 148 expect(cs.element.location.startColumn, isNotNull); | 146 expect(cs.element.location.startColumn, isNotNull); |
| 149 expect(cs.element.location.startLine, isNotNull); | 147 expect(cs.element.location.startLine, isNotNull); |
| 150 } | 148 } |
| 151 if (elemFile != null) { | 149 if (elemFile != null) { |
| 152 expect(cs.element.location.file, elemFile); | 150 expect(cs.element.location.file, elemFile); |
| 153 } | 151 } |
| 154 if (elemOffset != null) { | 152 if (elemOffset != null) { |
| 155 expect(cs.element.location.offset, elemOffset); | 153 expect(cs.element.location.offset, elemOffset); |
| 156 } | 154 } |
| 157 if (docCompleteMatcher != null) { | |
| 158 expect(cs.docComplete, docCompleteMatcher); | |
| 159 } | |
| 160 if (docSummaryMatcher != null) { | |
| 161 expect(cs.docSummary, docSummaryMatcher); | |
| 162 } | |
| 163 return cs; | 155 return cs; |
| 164 } | 156 } |
| 165 | 157 |
| 166 CompletionSuggestion assertSuggestClass(String name, | 158 CompletionSuggestion assertSuggestClass(String name, |
| 167 {int relevance: DART_RELEVANCE_DEFAULT, | 159 {int relevance: DART_RELEVANCE_DEFAULT, |
| 168 String importUri, | 160 String importUri, |
| 169 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 161 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 170 bool isDeprecated: false, | 162 bool isDeprecated: false, |
| 171 String elemFile, | 163 String elemFile, |
| 172 int elemOffset, | 164 int elemOffset}) { |
| 173 docCompleteMatcher, | |
| 174 docSummaryMatcher}) { | |
| 175 CompletionSuggestion cs = assertSuggest(name, | 165 CompletionSuggestion cs = assertSuggest(name, |
| 176 csKind: kind, | 166 csKind: kind, |
| 177 relevance: relevance, | 167 relevance: relevance, |
| 178 importUri: importUri, | 168 importUri: importUri, |
| 179 isDeprecated: isDeprecated, | 169 isDeprecated: isDeprecated, |
| 180 elemFile: elemFile, | 170 elemFile: elemFile, |
| 181 elemOffset: elemOffset, | 171 elemOffset: elemOffset); |
| 182 docCompleteMatcher: docCompleteMatcher, | |
| 183 docSummaryMatcher: docSummaryMatcher); | |
| 184 protocol.Element element = cs.element; | 172 protocol.Element element = cs.element; |
| 185 expect(element, isNotNull); | 173 expect(element, isNotNull); |
| 186 expect(element.kind, equals(protocol.ElementKind.CLASS)); | 174 expect(element.kind, equals(protocol.ElementKind.CLASS)); |
| 187 expect(element.name, equals(name)); | 175 expect(element.name, equals(name)); |
| 188 expect(element.parameters, isNull); | 176 expect(element.parameters, isNull); |
| 189 expect(element.returnType, isNull); | 177 expect(element.returnType, isNull); |
| 190 assertHasNoParameterInfo(cs); | 178 assertHasNoParameterInfo(cs); |
| 191 return cs; | 179 return cs; |
| 192 } | 180 } |
| 193 | 181 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // The returnType represents the type of a field | 229 // The returnType represents the type of a field |
| 242 expect(element.returnType, type != null ? type : 'dynamic'); | 230 expect(element.returnType, type != null ? type : 'dynamic'); |
| 243 assertHasNoParameterInfo(cs); | 231 assertHasNoParameterInfo(cs); |
| 244 return cs; | 232 return cs; |
| 245 } | 233 } |
| 246 | 234 |
| 247 CompletionSuggestion assertSuggestFunction(String name, String returnType, | 235 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 248 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 236 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 249 bool deprecated: false, | 237 bool deprecated: false, |
| 250 int relevance: DART_RELEVANCE_DEFAULT, | 238 int relevance: DART_RELEVANCE_DEFAULT, |
| 251 String importUri, | 239 String importUri}) { |
| 252 docCompleteMatcher, | |
| 253 docSummaryMatcher}) { | |
| 254 CompletionSuggestion cs = assertSuggest(name, | 240 CompletionSuggestion cs = assertSuggest(name, |
| 255 csKind: kind, | 241 csKind: kind, |
| 256 relevance: relevance, | 242 relevance: relevance, |
| 257 importUri: importUri, | 243 importUri: importUri, |
| 258 isDeprecated: deprecated, | 244 isDeprecated: deprecated); |
| 259 docCompleteMatcher: docCompleteMatcher, | |
| 260 docSummaryMatcher: docSummaryMatcher); | |
| 261 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 245 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 262 protocol.Element element = cs.element; | 246 protocol.Element element = cs.element; |
| 263 expect(element, isNotNull); | 247 expect(element, isNotNull); |
| 264 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); | 248 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
| 265 expect(element.name, equals(name)); | 249 expect(element.name, equals(name)); |
| 266 expect(element.isDeprecated, equals(deprecated)); | 250 expect(element.isDeprecated, equals(deprecated)); |
| 267 String param = element.parameters; | 251 String param = element.parameters; |
| 268 expect(param, isNotNull); | 252 expect(param, isNotNull); |
| 269 expect(param[0], equals('(')); | 253 expect(param[0], equals('(')); |
| 270 expect(param[param.length - 1], equals(')')); | 254 expect(param[param.length - 1], equals(')')); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { | 331 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
| 348 // Library prefix should only be suggested by ImportedReferenceContributor | 332 // Library prefix should only be suggested by ImportedReferenceContributor |
| 349 return assertNotSuggested(prefix); | 333 return assertNotSuggested(prefix); |
| 350 } | 334 } |
| 351 | 335 |
| 352 CompletionSuggestion assertSuggestMethod( | 336 CompletionSuggestion assertSuggestMethod( |
| 353 String name, String declaringType, String returnType, | 337 String name, String declaringType, String returnType, |
| 354 {int relevance: DART_RELEVANCE_DEFAULT, | 338 {int relevance: DART_RELEVANCE_DEFAULT, |
| 355 String importUri, | 339 String importUri, |
| 356 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, | 340 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 357 bool isDeprecated: false, | 341 bool isDeprecated: false}) { |
| 358 docCompleteMatcher, | |
| 359 docSummaryMatcher}) { | |
| 360 CompletionSuggestion cs = assertSuggest(name, | 342 CompletionSuggestion cs = assertSuggest(name, |
| 361 csKind: kind, | 343 csKind: kind, |
| 362 relevance: relevance, | 344 relevance: relevance, |
| 363 importUri: importUri, | 345 importUri: importUri, |
| 364 isDeprecated: isDeprecated, | 346 isDeprecated: isDeprecated); |
| 365 docCompleteMatcher: docCompleteMatcher, | |
| 366 docSummaryMatcher: docSummaryMatcher); | |
| 367 expect(cs.declaringType, equals(declaringType)); | 347 expect(cs.declaringType, equals(declaringType)); |
| 368 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 348 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 369 protocol.Element element = cs.element; | 349 protocol.Element element = cs.element; |
| 370 expect(element, isNotNull); | 350 expect(element, isNotNull); |
| 371 expect(element.kind, equals(protocol.ElementKind.METHOD)); | 351 expect(element.kind, equals(protocol.ElementKind.METHOD)); |
| 372 expect(element.name, equals(name)); | 352 expect(element.name, equals(name)); |
| 373 String param = element.parameters; | 353 String param = element.parameters; |
| 374 expect(param, isNotNull); | 354 expect(param, isNotNull); |
| 375 expect(param[0], equals('(')); | 355 expect(param[0], equals('(')); |
| 376 expect(param[param.length - 1], equals(')')); | 356 expect(param[param.length - 1], equals(')')); |
| (...skipping 4346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4723 assertNotSuggested('bar2'); | 4703 assertNotSuggested('bar2'); |
| 4724 assertNotSuggested('_B'); | 4704 assertNotSuggested('_B'); |
| 4725 assertSuggestLocalClass('Y'); | 4705 assertSuggestLocalClass('Y'); |
| 4726 assertSuggestLocalClass('C'); | 4706 assertSuggestLocalClass('C'); |
| 4727 assertSuggestLocalVariable('f', null); | 4707 assertSuggestLocalVariable('f', null); |
| 4728 assertNotSuggested('x'); | 4708 assertNotSuggested('x'); |
| 4729 assertNotSuggested('e'); | 4709 assertNotSuggested('e'); |
| 4730 }); | 4710 }); |
| 4731 } | 4711 } |
| 4732 } | 4712 } |
| OLD | NEW |