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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); | 47 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
48 completionOffset = content.indexOf('^'); | 48 completionOffset = content.indexOf('^'); |
49 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 49 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
50 int nextOffset = content.indexOf('^', completionOffset + 1); | 50 int nextOffset = content.indexOf('^', completionOffset + 1); |
51 expect(nextOffset, equals(-1), reason: 'too many ^'); | 51 expect(nextOffset, equals(-1), reason: 'too many ^'); |
52 content = content.substring(0, completionOffset) + | 52 content = content.substring(0, completionOffset) + |
53 content.substring(completionOffset + 1); | 53 content.substring(completionOffset + 1); |
54 testSource = addSource(testFile, content); | 54 testSource = addSource(testFile, content); |
55 } | 55 } |
56 | 56 |
| 57 void assertHasNoParameterInfo(CompletionSuggestion suggestion) { |
| 58 expect(suggestion.parameterNames, isNull); |
| 59 expect(suggestion.parameterTypes, isNull); |
| 60 expect(suggestion.requiredParameterCount, isNull); |
| 61 expect(suggestion.hasNamedParameters, isNull); |
| 62 } |
| 63 |
57 void assertHasParameterInfo(CompletionSuggestion suggestion) { | 64 void assertHasParameterInfo(CompletionSuggestion suggestion) { |
58 expect(suggestion.parameterNames, isNotNull); | 65 expect(suggestion.parameterNames, isNotNull); |
59 expect(suggestion.parameterTypes, isNotNull); | 66 expect(suggestion.parameterTypes, isNotNull); |
60 expect(suggestion.parameterNames.length, suggestion.parameterTypes.length); | 67 expect(suggestion.parameterNames.length, suggestion.parameterTypes.length); |
61 expect(suggestion.requiredParameterCount, | 68 expect(suggestion.requiredParameterCount, |
62 lessThanOrEqualTo(suggestion.parameterNames.length)); | 69 lessThanOrEqualTo(suggestion.parameterNames.length)); |
63 expect(suggestion.hasNamedParameters, isNotNull); | 70 expect(suggestion.hasNamedParameters, isNotNull); |
64 } | 71 } |
65 | 72 |
66 void assertNoSuggestions({CompletionSuggestionKind kind: null}) { | 73 void assertNoSuggestions({CompletionSuggestionKind kind: null}) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 129 } |
123 if (elemFile != null) { | 130 if (elemFile != null) { |
124 expect(cs.element.location.file, elemFile); | 131 expect(cs.element.location.file, elemFile); |
125 } | 132 } |
126 if (elemOffset != null) { | 133 if (elemOffset != null) { |
127 expect(cs.element.location.offset, elemOffset); | 134 expect(cs.element.location.offset, elemOffset); |
128 } | 135 } |
129 return cs; | 136 return cs; |
130 } | 137 } |
131 | 138 |
| 139 CompletionSuggestion assertSuggestClass(String name, |
| 140 {int relevance: DART_RELEVANCE_DEFAULT, |
| 141 String importUri, |
| 142 CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 143 bool isDeprecated: false, |
| 144 String elemFile, |
| 145 int elemOffset}) { |
| 146 CompletionSuggestion cs = assertSuggest(name, |
| 147 csKind: kind, |
| 148 relevance: relevance, |
| 149 importUri: importUri, |
| 150 isDeprecated: isDeprecated, |
| 151 elemFile: elemFile, |
| 152 elemOffset: elemOffset); |
| 153 protocol.Element element = cs.element; |
| 154 expect(element, isNotNull); |
| 155 expect(element.kind, equals(protocol.ElementKind.CLASS)); |
| 156 expect(element.name, equals(name)); |
| 157 expect(element.parameters, isNull); |
| 158 expect(element.returnType, isNull); |
| 159 assertHasNoParameterInfo(cs); |
| 160 return cs; |
| 161 } |
| 162 |
| 163 CompletionSuggestion assertSuggestFunction(String name, String returnType, |
| 164 {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION, |
| 165 bool deprecated: false, |
| 166 int relevance: DART_RELEVANCE_DEFAULT, |
| 167 String importUri}) { |
| 168 CompletionSuggestion cs = assertSuggest(name, |
| 169 csKind: kind, |
| 170 relevance: relevance, |
| 171 importUri: importUri, |
| 172 isDeprecated: deprecated); |
| 173 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 174 protocol.Element element = cs.element; |
| 175 expect(element, isNotNull); |
| 176 expect(element.kind, equals(protocol.ElementKind.FUNCTION)); |
| 177 expect(element.name, equals(name)); |
| 178 expect(element.isDeprecated, equals(deprecated)); |
| 179 String param = element.parameters; |
| 180 expect(param, isNotNull); |
| 181 expect(param[0], equals('(')); |
| 182 expect(param[param.length - 1], equals(')')); |
| 183 expect(element.returnType, |
| 184 equals(returnType != null ? returnType : 'dynamic')); |
| 185 assertHasParameterInfo(cs); |
| 186 return cs; |
| 187 } |
| 188 |
| 189 CompletionSuggestion assertSuggestFunctionTypeAlias( |
| 190 String name, String returnType, bool isDeprecated, |
| 191 [int relevance = DART_RELEVANCE_DEFAULT, |
| 192 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION, |
| 193 String importUri]) { |
| 194 CompletionSuggestion cs = assertSuggest(name, |
| 195 csKind: kind, |
| 196 relevance: relevance, |
| 197 importUri: importUri, |
| 198 isDeprecated: isDeprecated); |
| 199 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 200 protocol.Element element = cs.element; |
| 201 expect(element, isNotNull); |
| 202 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); |
| 203 expect(element.name, equals(name)); |
| 204 expect(element.isDeprecated, equals(isDeprecated)); |
| 205 // TODO (danrubel) Determine why params are null |
| 206 // String param = element.parameters; |
| 207 // expect(param, isNotNull); |
| 208 // expect(param[0], equals('(')); |
| 209 // expect(param[param.length - 1], equals(')')); |
| 210 expect(element.returnType, |
| 211 equals(returnType != null ? returnType : 'dynamic')); |
| 212 // TODO (danrubel) Determine why param info is missing |
| 213 // assertHasParameterInfo(cs); |
| 214 return cs; |
| 215 } |
| 216 |
| 217 CompletionSuggestion assertSuggestTopLevelVar(String name, String returnType, |
| 218 [int relevance = DART_RELEVANCE_DEFAULT, |
| 219 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION, |
| 220 String importUri]) { |
| 221 CompletionSuggestion cs = assertSuggest(name, |
| 222 csKind: kind, relevance: relevance, importUri: importUri); |
| 223 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 224 protocol.Element element = cs.element; |
| 225 expect(element, isNotNull); |
| 226 expect(element.kind, equals(protocol.ElementKind.TOP_LEVEL_VARIABLE)); |
| 227 expect(element.name, equals(name)); |
| 228 expect(element.parameters, isNull); |
| 229 expect(element.returnType, returnType != null ? returnType : 'dynamic'); |
| 230 assertHasNoParameterInfo(cs); |
| 231 return cs; |
| 232 } |
| 233 |
132 /** | 234 /** |
133 * Return a [Future] that completes with the containing library information | 235 * Return a [Future] that completes with the containing library information |
134 * after it is accessible via [context.getLibrariesContaining]. | 236 * after it is accessible via [context.getLibrariesContaining]. |
135 */ | 237 */ |
136 Future computeLibrariesContaining([int times = 200]) { | 238 Future computeLibrariesContaining([int times = 200]) { |
137 List<Source> libraries = context.getLibrariesContaining(testSource); | 239 List<Source> libraries = context.getLibrariesContaining(testSource); |
138 if (libraries.isNotEmpty) { | 240 if (libraries.isNotEmpty) { |
139 return new Future.value(libraries); | 241 return new Future.value(libraries); |
140 } | 242 } |
141 context.performAnalysisTask(); | 243 context.performAnalysisTask(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 331 } |
230 | 332 |
231 @override | 333 @override |
232 void setUp() { | 334 void setUp() { |
233 super.setUp(); | 335 super.setUp(); |
234 index = createLocalMemoryIndex(); | 336 index = createLocalMemoryIndex(); |
235 searchEngine = new SearchEngineImpl(index); | 337 searchEngine = new SearchEngineImpl(index); |
236 contributor = createContributor(); | 338 contributor = createContributor(); |
237 } | 339 } |
238 } | 340 } |
OLD | NEW |