OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.statement; | 5 library test.services.completion.statement; |
6 | 6 |
7 import 'package:analysis_server/src/protocol_server.dart'; | 7 import 'package:analysis_server/src/protocol_server.dart'; |
8 import 'package:analysis_server/src/services/completion/statement/statement_comp letion.dart'; | 8 import 'package:analysis_server/src/services/completion/statement/statement_comp letion.dart'; |
9 import 'package:analyzer/src/dart/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 'Complete do-statement', | 123 'Complete do-statement', |
124 ''' | 124 ''' |
125 main() { | 125 main() { |
126 do { | 126 do { |
127 } while (); | 127 } while (); |
128 } | 128 } |
129 ''', | 129 ''', |
130 (s) => s.indexOf('while (') + 'while ('.length); | 130 (s) => s.indexOf('while (') + 'while ('.length); |
131 } | 131 } |
132 | 132 |
133 test_completeForEmptyCond() async { | |
Brian Wilkerson
2017/04/18 17:28:50
Just a suggestion: you could put each statement ki
messick
2017/04/18 18:05:52
Good idea, thanks.
messick
2017/04/18 21:35:40
Done.
| |
134 await _prepareCompletion( | |
135 '}', | |
136 ''' | |
137 main() { | |
138 for (int i = 0;) { | |
139 } | |
140 } | |
141 ''', | |
142 atEnd: true); | |
143 _assertHasChange( | |
144 'Complete for-statement', | |
145 ''' | |
146 main() { | |
147 for (int i = 0; ) { | |
Brian Wilkerson
2017/04/18 17:28:50
Not knowing exactly how this is suppose to work, I
messick
2017/04/18 18:05:52
I considered that. Two factors dissuaded me. Doing
| |
148 } | |
149 } | |
150 ''', | |
151 (s) => s.indexOf('0; ') + '0; '.length); | |
152 } | |
153 | |
154 test_completeForEmptyInit() async { | |
155 await _prepareCompletion( | |
156 '}', | |
157 ''' | |
158 main() { | |
159 for () { | |
160 } | |
161 } | |
162 ''', | |
163 atEnd: true); | |
164 _assertHasChange( | |
165 'Complete for-statement', | |
166 ''' | |
167 main() { | |
168 for () { | |
Brian Wilkerson
2017/04/18 17:28:50
This, on the other hand, looks right, because we d
messick
2017/04/18 18:05:52
Acknowledged.
| |
169 } | |
170 } | |
171 ''', | |
172 (s) => s.indexOf('for (') + 'for ('.length); | |
173 } | |
174 | |
175 test_completeForEmptyInitEmptyCond() async { | |
176 await _prepareCompletion( | |
177 '}', | |
178 ''' | |
179 main() { | |
180 for (;/**/) { | |
181 } | |
182 } | |
183 ''', | |
184 atEnd: true); | |
185 _assertHasChange( | |
186 'Complete for-statement', | |
187 ''' | |
188 main() { | |
189 for (;/**/) { | |
190 } | |
191 } | |
192 ''', | |
193 (s) => s.indexOf('/**/') + '/**/'.length); | |
194 } | |
195 | |
196 test_completeForEmptyParts() async { | |
197 await _prepareCompletion( | |
198 ';)', | |
199 ''' | |
200 main() { | |
201 for (;;) | |
202 } | |
203 ''', | |
204 atEnd: true); | |
205 _assertHasChange( | |
206 'Complete for-statement', | |
207 ''' | |
208 main() { | |
209 for (;;) { | |
210 //// | |
211 } | |
212 } | |
213 ''', | |
214 (s) => s.indexOf(' ') + ' '.length); | |
215 } | |
216 | |
217 test_completeForKeywordOnly() async { | |
218 await _prepareCompletion( | |
219 'for', | |
220 ''' | |
221 main() { | |
222 for | |
223 } | |
224 ''', | |
225 atEnd: true); | |
226 _assertHasChange( | |
227 'Complete for-statement', | |
228 ''' | |
229 main() { | |
230 for () { | |
231 //// | |
232 } | |
233 } | |
234 ''', | |
235 (s) => s.indexOf('for (') + 'for ('.length); | |
236 } | |
237 | |
238 test_completeForMissingLeftSep() async { | |
239 await _prepareCompletion( | |
240 '}', | |
241 ''' | |
242 main() { | |
243 for (int i = 0) { | |
244 } | |
245 } | |
246 ''', | |
247 atEnd: true); | |
248 _assertHasChange( | |
249 'Complete for-statement', | |
250 ''' | |
251 main() { | |
252 for (int i = 0; ) { | |
253 } | |
254 } | |
255 ''', | |
256 (s) => s.indexOf('0; ') + '0; '.length); | |
257 } | |
Brian Wilkerson
2017/04/18 17:28:50
Add a test for having both an initializer and a co
messick
2017/04/18 18:05:52
Thanks for catching that. I lost track of that bra
messick
2017/04/18 21:35:40
Done.
| |
258 | |
133 test_completeIfAfterCondition_BAD() async { | 259 test_completeIfAfterCondition_BAD() async { |
134 // TODO(messick): Fix the code to make this like test_completeIfWithConditio n. | 260 // TODO(messick): Fix the code to make this like test_completeIfWithConditio n. |
135 // Recap: Finding the node at the selectionOffset returns the block, not the | 261 // Recap: Finding the node at the selectionOffset returns the block, not the |
136 // if-statement. Need to understand if that only happens when the if-stateme nt | 262 // if-statement. Need to understand if that only happens when the if-stateme nt |
137 // is the only statement in the block, or perhaps first or last? And what | 263 // is the only statement in the block, or perhaps first or last? And what |
138 // happens when it is in the middle of other statements? | 264 // happens when it is in the middle of other statements? |
139 await _prepareCompletion( | 265 await _prepareCompletion( |
140 'if (true) ', // Trigger completion after space. | 266 'if (true) ', // Trigger completion after space. |
141 ''' | 267 ''' |
142 main() { | 268 main() { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 } | 497 } |
372 await _prepareCompletionAt(offset + delta, testCode); | 498 await _prepareCompletionAt(offset + delta, testCode); |
373 } | 499 } |
374 | 500 |
375 _prepareCompletionAt(int offset, String sourceCode) async { | 501 _prepareCompletionAt(int offset, String sourceCode) async { |
376 verifyNoTestUnitErrors = false; | 502 verifyNoTestUnitErrors = false; |
377 await resolveTestUnit(sourceCode); | 503 await resolveTestUnit(sourceCode); |
378 await _computeCompletion(offset); | 504 await _computeCompletion(offset); |
379 } | 505 } |
380 } | 506 } |
OLD | NEW |