OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library test.services.correction.assist; | |
6 | |
7 import 'package:analysis_services/correction/assist.dart'; | |
8 import 'package:analysis_services/correction/change.dart'; | |
9 import 'package:analysis_services/index/index.dart'; | |
10 import 'package:analysis_services/index/local_memory_index.dart'; | |
11 import 'package:analysis_services/src/search/search_engine.dart'; | |
12 import 'package:analysis_testing/abstract_single_unit.dart'; | |
13 import 'package:analysis_testing/reflective_tests.dart'; | |
14 import 'package:unittest/unittest.dart'; | |
15 | |
16 | |
17 main() { | |
18 groupSep = ' | '; | |
19 runReflectiveTests(AssistProcessorTest); | |
20 } | |
21 | |
22 | |
23 @ReflectiveTestCase() | |
24 class AssistProcessorTest extends AbstractSingleUnitTest { | |
25 Index index; | |
26 SearchEngineImpl searchEngine; | |
27 | |
28 int offset; | |
29 int length; | |
30 | |
31 Assist assist; | |
32 Change change; | |
33 String resultCode; | |
34 LinkedEditGroup linkedPositionGroup; | |
35 | |
36 /** | |
37 * Asserts that there is an [Assist] of the given [kind] at [offset] which | |
38 * produces the [expected] code when applied to [testCode]. | |
39 */ | |
40 void assertHasAssist(AssistKind kind, String expected) { | |
41 assist = _assertHasAssist(kind); | |
42 change = assist.change; | |
43 // apply to "file" | |
44 List<FileEdit> fileEdits = change.fileEdits; | |
45 expect(fileEdits, hasLength(1)); | |
46 resultCode = Edit.applySequence(testCode, change.fileEdits[0].edits); | |
47 // verify | |
48 expect(resultCode, expected); | |
49 } | |
50 | |
51 /** | |
52 * Calls [assertHasAssist] at the offset of [offsetSearch] in [testCode]. | |
53 */ | |
54 void assertHasAssistAt(String offsetSearch, AssistKind kind, | |
55 String expected) { | |
56 offset = findOffset(offsetSearch); | |
57 assertHasAssist(kind, expected); | |
58 } | |
59 | |
60 void assertHasPositionGroup(String id, int expectedLength, | |
61 List<Position> expectedPositions) { | |
62 List<LinkedEditGroup> linkedPositionGroups = change.linkedEditGroups; | |
63 for (LinkedEditGroup group in linkedPositionGroups) { | |
64 if (group.id == id) { | |
65 expect(group.length, expectedLength); | |
66 expect(group.positions, unorderedEquals(expectedPositions)); | |
67 linkedPositionGroup = group; | |
68 return; | |
69 } | |
70 } | |
71 fail('No PositionGroup with id=$id found in $linkedPositionGroups'); | |
72 } | |
73 | |
74 /** | |
75 * Asserts that there is no [Assist] of the given [kind] at [offset]. | |
76 */ | |
77 void assertNoAssist(AssistKind kind) { | |
78 List<Assist> assists = | |
79 computeAssists(searchEngine, testUnit, offset, length); | |
80 for (Assist assist in assists) { | |
81 if (assist.kind == kind) { | |
82 throw fail('Unexpected assist $kind in\n${assists.join('\n')}'); | |
83 } | |
84 } | |
85 } | |
86 | |
87 /** | |
88 * Calls [assertNoAssist] at the offset of [offsetSearch] in [testCode]. | |
89 */ | |
90 void assertNoAssistAt(String offsetSearch, AssistKind kind) { | |
91 offset = findOffset(offsetSearch); | |
92 assertNoAssist(kind); | |
93 } | |
94 | |
95 Position expectedPosition(String search) { | |
96 int offset = resultCode.indexOf(search); | |
97 return new Position(testFile, offset); | |
98 } | |
99 | |
100 List<Position> expectedPositions(List<String> patterns) { | |
101 List<Position> positions = <Position>[]; | |
102 patterns.forEach((String search) { | |
103 positions.add(expectedPosition(search)); | |
104 }); | |
105 return positions; | |
106 } | |
107 | |
108 List<LinkedEditSuggestion> expectedSuggestions(LinkedEditSuggestionKind kind, | |
109 List<String> values) { | |
110 return values.map((value) { | |
111 return new LinkedEditSuggestion(kind, value); | |
112 }).toList(); | |
113 } | |
114 | |
115 void setUp() { | |
116 super.setUp(); | |
117 index = createLocalMemoryIndex(); | |
118 searchEngine = new SearchEngineImpl(index); | |
119 offset = 0; | |
120 length = 0; | |
121 } | |
122 | |
123 void test_addTypeAnnotation_classField_OK_final() { | |
124 _indexTestUnit(''' | |
125 class A { | |
126 final f = 0; | |
127 } | |
128 '''); | |
129 assertHasAssistAt('final ', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
130 class A { | |
131 final int f = 0; | |
132 } | |
133 '''); | |
134 } | |
135 | |
136 void test_addTypeAnnotation_classField_OK_int() { | |
137 _indexTestUnit(''' | |
138 class A { | |
139 var f = 0; | |
140 } | |
141 '''); | |
142 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
143 class A { | |
144 int f = 0; | |
145 } | |
146 '''); | |
147 } | |
148 | |
149 void test_addTypeAnnotation_local_OK_Function() { | |
150 _indexTestUnit(''' | |
151 main() { | |
152 var v = () => 1; | |
153 } | |
154 '''); | |
155 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
156 main() { | |
157 Function v = () => 1; | |
158 } | |
159 '''); | |
160 } | |
161 | |
162 void test_addTypeAnnotation_local_OK_List() { | |
163 _indexTestUnit(''' | |
164 main() { | |
165 var v = <String>[]; | |
166 } | |
167 '''); | |
168 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
169 main() { | |
170 List<String> v = <String>[]; | |
171 } | |
172 '''); | |
173 } | |
174 | |
175 void test_addTypeAnnotation_local_OK_int() { | |
176 _indexTestUnit(''' | |
177 main() { | |
178 var v = 0; | |
179 } | |
180 '''); | |
181 assertHasAssistAt('v =', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
182 main() { | |
183 int v = 0; | |
184 } | |
185 '''); | |
186 } | |
187 | |
188 void test_addTypeAnnotation_local_OK_onInitializer() { | |
189 _indexTestUnit(''' | |
190 main() { | |
191 var v = 123; | |
192 } | |
193 '''); | |
194 assertHasAssistAt('23', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
195 main() { | |
196 int v = 123; | |
197 } | |
198 '''); | |
199 } | |
200 | |
201 void test_addTypeAnnotation_local_OK_onName() { | |
202 _indexTestUnit(''' | |
203 main() { | |
204 var abc = 0; | |
205 } | |
206 '''); | |
207 assertHasAssistAt('bc', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
208 main() { | |
209 int abc = 0; | |
210 } | |
211 '''); | |
212 } | |
213 | |
214 void test_addTypeAnnotation_local_OK_onVar() { | |
215 _indexTestUnit(''' | |
216 main() { | |
217 var v = 0; | |
218 } | |
219 '''); | |
220 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
221 main() { | |
222 int v = 0; | |
223 } | |
224 '''); | |
225 } | |
226 | |
227 void test_addTypeAnnotation_local_wrong_hasTypeAnnotation() { | |
228 _indexTestUnit(''' | |
229 main() { | |
230 int v = 42; | |
231 } | |
232 '''); | |
233 assertNoAssistAt(' = 42', AssistKind.ADD_TYPE_ANNOTATION); | |
234 } | |
235 | |
236 void test_addTypeAnnotation_local_wrong_multiple() { | |
237 _indexTestUnit(''' | |
238 main() { | |
239 var a = 1, b = ''; | |
240 } | |
241 '''); | |
242 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
243 } | |
244 | |
245 void test_addTypeAnnotation_local_wrong_noValue() { | |
246 verifyNoTestUnitErrors = false; | |
247 _indexTestUnit(''' | |
248 main() { | |
249 var v; | |
250 } | |
251 '''); | |
252 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
253 } | |
254 | |
255 void test_addTypeAnnotation_local_wrong_null() { | |
256 _indexTestUnit(''' | |
257 main() { | |
258 var v = null; | |
259 } | |
260 '''); | |
261 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
262 } | |
263 | |
264 void test_addTypeAnnotation_local_wrong_unknown() { | |
265 verifyNoTestUnitErrors = false; | |
266 _indexTestUnit(''' | |
267 main() { | |
268 var v = unknownVar; | |
269 } | |
270 '''); | |
271 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
272 } | |
273 | |
274 void test_addTypeAnnotation_topLevelField_OK_int() { | |
275 _indexTestUnit(''' | |
276 var V = 0; | |
277 '''); | |
278 assertHasAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION, ''' | |
279 int V = 0; | |
280 '''); | |
281 } | |
282 | |
283 void test_addTypeAnnotation_topLevelField_wrong_multiple() { | |
284 _indexTestUnit(''' | |
285 var A = 1, V = ''; | |
286 '''); | |
287 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
288 } | |
289 | |
290 void test_addTypeAnnotation_topLevelField_wrong_noValue() { | |
291 _indexTestUnit(''' | |
292 var V; | |
293 '''); | |
294 assertNoAssistAt('var ', AssistKind.ADD_TYPE_ANNOTATION); | |
295 } | |
296 | |
297 void test_assignToLocalVariable() { | |
298 _indexTestUnit(''' | |
299 main() { | |
300 List<int> bytes; | |
301 readBytes(); | |
302 } | |
303 List<int> readBytes() => <int>[]; | |
304 '''); | |
305 assertHasAssistAt('readBytes();', AssistKind.ASSIGN_TO_LOCAL_VARIABLE, ''' | |
306 main() { | |
307 List<int> bytes; | |
308 var readBytes = readBytes(); | |
309 } | |
310 List<int> readBytes() => <int>[]; | |
311 '''); | |
312 assertHasPositionGroup('NAME', 9, expectedPositions(['readBytes = '])); | |
313 expect( | |
314 linkedPositionGroup.suggestions, | |
315 unorderedEquals( | |
316 expectedSuggestions( | |
317 LinkedEditSuggestionKind.VARIABLE, | |
318 ['list', 'bytes2', 'readBytes']))); | |
319 } | |
320 | |
321 void test_assignToLocalVariable_alreadyAssignment() { | |
322 _indexTestUnit(''' | |
323 main() { | |
324 var vvv; | |
325 vvv = 42; | |
326 } | |
327 '''); | |
328 assertNoAssistAt('vvv =', AssistKind.ASSIGN_TO_LOCAL_VARIABLE); | |
329 } | |
330 | |
331 void test_assignToLocalVariable_throw() { | |
332 _indexTestUnit(''' | |
333 main() { | |
334 throw 42; | |
335 } | |
336 '''); | |
337 assertNoAssistAt('throw ', AssistKind.ASSIGN_TO_LOCAL_VARIABLE); | |
338 } | |
339 | |
340 void test_assignToLocalVariable_void() { | |
341 _indexTestUnit(''' | |
342 main() { | |
343 f(); | |
344 } | |
345 void f() {} | |
346 '''); | |
347 assertNoAssistAt('f();', AssistKind.ASSIGN_TO_LOCAL_VARIABLE); | |
348 } | |
349 | |
350 void test_convertToBlockBody_OK_closure() { | |
351 _indexTestUnit(''' | |
352 setup(x) {} | |
353 main() { | |
354 setup(() => print('done')); | |
355 } | |
356 '''); | |
357 assertHasAssistAt('() => print', AssistKind.CONVERT_INTO_BLOCK_BODY, ''' | |
358 setup(x) {} | |
359 main() { | |
360 setup(() { | |
361 return print('done'); | |
362 }); | |
363 } | |
364 '''); | |
365 } | |
366 | |
367 void test_convertToBlockBody_OK_method() { | |
368 _indexTestUnit(''' | |
369 class A { | |
370 mmm() => 123; | |
371 } | |
372 '''); | |
373 assertHasAssistAt('mmm()', AssistKind.CONVERT_INTO_BLOCK_BODY, ''' | |
374 class A { | |
375 mmm() { | |
376 return 123; | |
377 } | |
378 } | |
379 '''); | |
380 } | |
381 | |
382 void test_convertToBlockBody_OK_onName() { | |
383 _indexTestUnit(''' | |
384 fff() => 123; | |
385 '''); | |
386 assertHasAssistAt('fff()', AssistKind.CONVERT_INTO_BLOCK_BODY, ''' | |
387 fff() { | |
388 return 123; | |
389 } | |
390 '''); | |
391 } | |
392 | |
393 void test_convertToBlockBody_OK_onValue() { | |
394 _indexTestUnit(''' | |
395 fff() => 123; | |
396 '''); | |
397 assertHasAssistAt('23;', AssistKind.CONVERT_INTO_BLOCK_BODY, ''' | |
398 fff() { | |
399 return 123; | |
400 } | |
401 '''); | |
402 } | |
403 | |
404 void test_convertToBlockBody_wrong_noEnclosingFunction() { | |
405 _indexTestUnit(''' | |
406 var v = 123; | |
407 '''); | |
408 assertNoAssistAt('v =', AssistKind.CONVERT_INTO_BLOCK_BODY); | |
409 } | |
410 | |
411 void test_convertToBlockBody_wrong_notExpressionBlock() { | |
412 _indexTestUnit(''' | |
413 fff() { | |
414 return 123; | |
415 } | |
416 '''); | |
417 assertNoAssistAt('fff() {', AssistKind.CONVERT_INTO_BLOCK_BODY); | |
418 } | |
419 | |
420 void test_convertToExpressionBody_OK_closure() { | |
421 _indexTestUnit(''' | |
422 setup(x) {} | |
423 main() { | |
424 setup(() { | |
425 return 42; | |
426 }); | |
427 } | |
428 '''); | |
429 assertHasAssistAt('42;', AssistKind.CONVERT_INTO_EXPRESSION_BODY, ''' | |
430 setup(x) {} | |
431 main() { | |
432 setup(() => 42); | |
433 } | |
434 '''); | |
435 } | |
436 | |
437 void test_convertToExpressionBody_OK_function_onBlock() { | |
438 _indexTestUnit(''' | |
439 fff() { | |
440 return 42; | |
441 } | |
442 '''); | |
443 assertHasAssistAt('{', AssistKind.CONVERT_INTO_EXPRESSION_BODY, ''' | |
444 fff() => 42; | |
445 '''); | |
446 } | |
447 | |
448 void test_convertToExpressionBody_OK_function_onName() { | |
449 _indexTestUnit(''' | |
450 fff() { | |
451 return 42; | |
452 } | |
453 '''); | |
454 assertHasAssistAt('ff()', AssistKind.CONVERT_INTO_EXPRESSION_BODY, ''' | |
455 fff() => 42; | |
456 '''); | |
457 } | |
458 | |
459 void test_convertToExpressionBody_OK_method_onBlock() { | |
460 _indexTestUnit(''' | |
461 class A { | |
462 m() { // marker | |
463 return 42; | |
464 } | |
465 } | |
466 '''); | |
467 assertHasAssistAt( | |
468 '{ // marker', | |
469 AssistKind.CONVERT_INTO_EXPRESSION_BODY, | |
470 ''' | |
471 class A { | |
472 m() => 42; | |
473 } | |
474 '''); | |
475 } | |
476 | |
477 void test_convertToExpressionBody_OK_topFunction_onReturnStatement() { | |
478 _indexTestUnit(''' | |
479 fff() { | |
480 return 42; | |
481 } | |
482 '''); | |
483 assertHasAssistAt('return', AssistKind.CONVERT_INTO_EXPRESSION_BODY, ''' | |
484 fff() => 42; | |
485 '''); | |
486 } | |
487 | |
488 void test_convertToExpressionBody_wrong_already() { | |
489 _indexTestUnit(''' | |
490 fff() => 42; | |
491 '''); | |
492 assertNoAssistAt('fff()', AssistKind.CONVERT_INTO_EXPRESSION_BODY); | |
493 } | |
494 | |
495 void test_convertToExpressionBody_wrong_moreThanOneStatement() { | |
496 _indexTestUnit(''' | |
497 fff() { | |
498 var v = 42; | |
499 return v; | |
500 } | |
501 '''); | |
502 assertNoAssistAt('fff()', AssistKind.CONVERT_INTO_EXPRESSION_BODY); | |
503 } | |
504 | |
505 void test_convertToExpressionBody_wrong_noEnclosingFunction() { | |
506 _indexTestUnit(''' | |
507 var V = 42; | |
508 '''); | |
509 assertNoAssistAt('V = ', AssistKind.CONVERT_INTO_EXPRESSION_BODY); | |
510 } | |
511 | |
512 void test_convertToExpressionBody_wrong_noReturn() { | |
513 _indexTestUnit(''' | |
514 fff() { | |
515 var v = 42; | |
516 } | |
517 '''); | |
518 assertNoAssistAt('fff()', AssistKind.CONVERT_INTO_EXPRESSION_BODY); | |
519 } | |
520 | |
521 void test_convertToExpressionBody_wrong_noReturnValue() { | |
522 _indexTestUnit(''' | |
523 fff() { | |
524 return; | |
525 } | |
526 '''); | |
527 assertNoAssistAt('fff()', AssistKind.CONVERT_INTO_EXPRESSION_BODY); | |
528 } | |
529 | |
530 void test_convertToIsNotEmpty_OK_on_isEmpty() { | |
531 _indexTestUnit(''' | |
532 main(String str) { | |
533 !str.isEmpty; | |
534 } | |
535 '''); | |
536 assertHasAssistAt('isEmpty', AssistKind.CONVERT_INTO_IS_NOT_EMPTY, ''' | |
537 main(String str) { | |
538 str.isNotEmpty; | |
539 } | |
540 '''); | |
541 } | |
542 | |
543 void test_convertToIsNotEmpty_OK_on_str() { | |
544 _indexTestUnit(''' | |
545 main(String str) { | |
546 !str.isEmpty; | |
547 } | |
548 '''); | |
549 assertHasAssistAt('str.', AssistKind.CONVERT_INTO_IS_NOT_EMPTY, ''' | |
550 main(String str) { | |
551 str.isNotEmpty; | |
552 } | |
553 '''); | |
554 } | |
555 | |
556 void test_convertToIsNotEmpty_OK_propertyAccess() { | |
557 _indexTestUnit(''' | |
558 main(String str) { | |
559 !'text'.isEmpty; | |
560 } | |
561 '''); | |
562 assertHasAssistAt('isEmpty', AssistKind.CONVERT_INTO_IS_NOT_EMPTY, ''' | |
563 main(String str) { | |
564 'text'.isNotEmpty; | |
565 } | |
566 '''); | |
567 } | |
568 | |
569 void test_convertToIsNotEmpty_wrong_notInPrefixExpression() { | |
570 _indexTestUnit(''' | |
571 main(String str) { | |
572 str.isEmpty; | |
573 } | |
574 '''); | |
575 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); | |
576 } | |
577 | |
578 void test_convertToIsNotEmpty_wrong_notIsEmpty() { | |
579 _indexTestUnit(''' | |
580 main(int p) { | |
581 !p.isEven; | |
582 } | |
583 '''); | |
584 assertNoAssistAt('isEven;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); | |
585 } | |
586 | |
587 void test_convertToIsNotEmpty_wrote_noIsNotEmpty() { | |
588 _indexTestUnit(''' | |
589 class A { | |
590 bool get isEmpty => false; | |
591 } | |
592 main(A a) { | |
593 !a.isEmpty; | |
594 } | |
595 '''); | |
596 assertNoAssistAt('isEmpty;', AssistKind.CONVERT_INTO_IS_NOT_EMPTY); | |
597 } | |
598 | |
599 void test_convertToIsNot_OK_childOfIs_left() { | |
600 _indexTestUnit(''' | |
601 main(p) { | |
602 !(p is String); | |
603 } | |
604 '''); | |
605 assertHasAssistAt('p is', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
606 main(p) { | |
607 p is! String; | |
608 } | |
609 '''); | |
610 } | |
611 | |
612 void test_convertToIsNot_OK_childOfIs_right() { | |
613 _indexTestUnit(''' | |
614 main(p) { | |
615 !(p is String); | |
616 } | |
617 '''); | |
618 assertHasAssistAt('String)', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
619 main(p) { | |
620 p is! String; | |
621 } | |
622 '''); | |
623 } | |
624 | |
625 void test_convertToIsNot_OK_is() { | |
626 _indexTestUnit(''' | |
627 main(p) { | |
628 !(p is String); | |
629 } | |
630 '''); | |
631 assertHasAssistAt('is String', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
632 main(p) { | |
633 p is! String; | |
634 } | |
635 '''); | |
636 } | |
637 | |
638 void test_convertToIsNot_OK_is_higherPrecedencePrefix() { | |
639 _indexTestUnit(''' | |
640 main(p) { | |
641 !!(p is String); | |
642 } | |
643 '''); | |
644 assertHasAssistAt('is String', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
645 main(p) { | |
646 !(p is! String); | |
647 } | |
648 '''); | |
649 } | |
650 | |
651 void test_convertToIsNot_OK_is_not_higherPrecedencePrefix() { | |
652 _indexTestUnit(''' | |
653 main(p) { | |
654 !!(p is String); | |
655 } | |
656 '''); | |
657 assertHasAssistAt('!(p', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
658 main(p) { | |
659 !(p is! String); | |
660 } | |
661 '''); | |
662 } | |
663 | |
664 void test_convertToIsNot_OK_not() { | |
665 _indexTestUnit(''' | |
666 main(p) { | |
667 !(p is String); | |
668 } | |
669 '''); | |
670 assertHasAssistAt('!(p', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
671 main(p) { | |
672 p is! String; | |
673 } | |
674 '''); | |
675 } | |
676 | |
677 void test_convertToIsNot_OK_parentheses() { | |
678 _indexTestUnit(''' | |
679 main(p) { | |
680 !(p is String); | |
681 } | |
682 '''); | |
683 assertHasAssistAt('(p is', AssistKind.CONVERT_INTO_IS_NOT, ''' | |
684 main(p) { | |
685 p is! String; | |
686 } | |
687 '''); | |
688 } | |
689 | |
690 void test_convertToIsNot_wrong_is_alreadyIsNot() { | |
691 _indexTestUnit(''' | |
692 main(p) { | |
693 p is! String; | |
694 } | |
695 '''); | |
696 assertNoAssistAt('is!', AssistKind.CONVERT_INTO_IS_NOT); | |
697 } | |
698 | |
699 void test_convertToIsNot_wrong_is_noEnclosingParenthesis() { | |
700 _indexTestUnit(''' | |
701 main(p) { | |
702 p is String; | |
703 } | |
704 '''); | |
705 assertNoAssistAt('is String', AssistKind.CONVERT_INTO_IS_NOT); | |
706 } | |
707 | |
708 void test_convertToIsNot_wrong_is_noPrefix() { | |
709 _indexTestUnit(''' | |
710 main(p) { | |
711 (p is String); | |
712 } | |
713 '''); | |
714 assertNoAssistAt('is String', AssistKind.CONVERT_INTO_IS_NOT); | |
715 } | |
716 | |
717 void test_convertToIsNot_wrong_is_notIsExpression() { | |
718 _indexTestUnit(''' | |
719 main(p) { | |
720 123 + 456; | |
721 } | |
722 '''); | |
723 assertNoAssistAt('123 +', AssistKind.CONVERT_INTO_IS_NOT); | |
724 } | |
725 | |
726 void test_convertToIsNot_wrong_is_notTheNotOperator() { | |
727 verifyNoTestUnitErrors = false; | |
728 _indexTestUnit(''' | |
729 main(p) { | |
730 ++(p is String); | |
731 } | |
732 '''); | |
733 assertNoAssistAt('is String', AssistKind.CONVERT_INTO_IS_NOT); | |
734 } | |
735 | |
736 void test_convertToIsNot_wrong_not_alreadyIsNot() { | |
737 _indexTestUnit(''' | |
738 main(p) { | |
739 !(p is! String); | |
740 } | |
741 '''); | |
742 assertNoAssistAt('!(p', AssistKind.CONVERT_INTO_IS_NOT); | |
743 } | |
744 | |
745 void test_convertToIsNot_wrong_not_noEnclosingParenthesis() { | |
746 _indexTestUnit(''' | |
747 main(p) { | |
748 !p; | |
749 } | |
750 '''); | |
751 assertNoAssistAt('!p', AssistKind.CONVERT_INTO_IS_NOT); | |
752 } | |
753 | |
754 void test_convertToIsNot_wrong_not_notIsExpression() { | |
755 _indexTestUnit(''' | |
756 main(p) { | |
757 !(p == null); | |
758 } | |
759 '''); | |
760 assertNoAssistAt('!(p', AssistKind.CONVERT_INTO_IS_NOT); | |
761 } | |
762 | |
763 void test_convertToIsNot_wrong_not_notTheNotOperator() { | |
764 verifyNoTestUnitErrors = false; | |
765 _indexTestUnit(''' | |
766 main(p) { | |
767 ++(p is String); | |
768 } | |
769 '''); | |
770 assertNoAssistAt('++(', AssistKind.CONVERT_INTO_IS_NOT); | |
771 } | |
772 | |
773 void test_exchangeBinaryExpressionArguments_OK_extended_mixOperator_1() { | |
774 _indexTestUnit(''' | |
775 main() { | |
776 1 * 2 * 3 + 4; | |
777 } | |
778 '''); | |
779 assertHasAssistAt('* 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
780 main() { | |
781 2 * 3 * 1 + 4; | |
782 } | |
783 '''); | |
784 } | |
785 | |
786 void test_exchangeBinaryExpressionArguments_OK_extended_mixOperator_2() { | |
787 _indexTestUnit(''' | |
788 main() { | |
789 1 + 2 - 3 + 4; | |
790 } | |
791 '''); | |
792 assertHasAssistAt('+ 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
793 main() { | |
794 2 + 1 - 3 + 4; | |
795 } | |
796 '''); | |
797 } | |
798 | |
799 void | |
800 test_exchangeBinaryExpressionArguments_OK_extended_sameOperator_afterFirst
() { | |
801 _indexTestUnit(''' | |
802 main() { | |
803 1 + 2 + 3; | |
804 } | |
805 '''); | |
806 assertHasAssistAt('+ 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
807 main() { | |
808 2 + 3 + 1; | |
809 } | |
810 '''); | |
811 } | |
812 | |
813 void | |
814 test_exchangeBinaryExpressionArguments_OK_extended_sameOperator_afterSecon
d() { | |
815 _indexTestUnit(''' | |
816 main() { | |
817 1 + 2 + 3; | |
818 } | |
819 '''); | |
820 assertHasAssistAt('+ 3', AssistKind.EXCHANGE_OPERANDS, ''' | |
821 main() { | |
822 3 + 1 + 2; | |
823 } | |
824 '''); | |
825 } | |
826 | |
827 void test_exchangeBinaryExpressionArguments_OK_simple_afterOperator() { | |
828 _indexTestUnit(''' | |
829 main() { | |
830 1 + 2; | |
831 } | |
832 '''); | |
833 assertHasAssistAt(' 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
834 main() { | |
835 2 + 1; | |
836 } | |
837 '''); | |
838 } | |
839 | |
840 void test_exchangeBinaryExpressionArguments_OK_simple_beforeOperator() { | |
841 _indexTestUnit(''' | |
842 main() { | |
843 1 + 2; | |
844 } | |
845 '''); | |
846 assertHasAssistAt('+ 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
847 main() { | |
848 2 + 1; | |
849 } | |
850 '''); | |
851 } | |
852 | |
853 void test_exchangeBinaryExpressionArguments_OK_simple_fullSelection() { | |
854 _indexTestUnit(''' | |
855 main() { | |
856 1 + 2; | |
857 } | |
858 '''); | |
859 length = '1 + 2'.length; | |
860 assertHasAssistAt('1 + 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
861 main() { | |
862 2 + 1; | |
863 } | |
864 '''); | |
865 } | |
866 | |
867 void test_exchangeBinaryExpressionArguments_OK_simple_withLength() { | |
868 _indexTestUnit(''' | |
869 main() { | |
870 1 + 2; | |
871 } | |
872 '''); | |
873 length = 2; | |
874 assertHasAssistAt('+ 2', AssistKind.EXCHANGE_OPERANDS, ''' | |
875 main() { | |
876 2 + 1; | |
877 } | |
878 '''); | |
879 } | |
880 | |
881 void test_exchangeBinaryExpressionArguments_wrong_extraLength() { | |
882 _indexTestUnit(''' | |
883 main() { | |
884 111 + 222; | |
885 } | |
886 '''); | |
887 length = 3; | |
888 assertNoAssistAt('+ 222', AssistKind.EXCHANGE_OPERANDS); | |
889 } | |
890 | |
891 void test_exchangeBinaryExpressionArguments_wrong_onOperand() { | |
892 _indexTestUnit(''' | |
893 main() { | |
894 111 + 222; | |
895 } | |
896 '''); | |
897 length = 3; | |
898 assertNoAssistAt('11 +', AssistKind.EXCHANGE_OPERANDS); | |
899 } | |
900 | |
901 void test_exchangeBinaryExpressionArguments_wrong_selectionWithBinary() { | |
902 _indexTestUnit(''' | |
903 main() { | |
904 1 + 2 + 3; | |
905 } | |
906 '''); | |
907 length = '1 + 2 + 3'.length; | |
908 assertNoAssistAt('1 + 2 + 3', AssistKind.EXCHANGE_OPERANDS); | |
909 } | |
910 | |
911 void test_importAddShow_BAD_hasShow() { | |
912 _indexTestUnit(''' | |
913 import 'dart:math' show PI; | |
914 main() { | |
915 PI; | |
916 } | |
917 '''); | |
918 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); | |
919 } | |
920 | |
921 void test_importAddShow_BAD_unused() { | |
922 _indexTestUnit(''' | |
923 import 'dart:math'; | |
924 '''); | |
925 assertNoAssistAt('import ', AssistKind.IMPORT_ADD_SHOW); | |
926 } | |
927 | |
928 void test_importAddShow_OK_onDirective() { | |
929 _indexTestUnit(''' | |
930 import 'dart:math'; | |
931 main() { | |
932 PI; | |
933 E; | |
934 max(1, 2); | |
935 } | |
936 '''); | |
937 assertHasAssistAt('import ', AssistKind.IMPORT_ADD_SHOW, ''' | |
938 import 'dart:math' show E, PI, max; | |
939 main() { | |
940 PI; | |
941 E; | |
942 max(1, 2); | |
943 } | |
944 '''); | |
945 } | |
946 | |
947 void test_importAddShow_OK_onUri() { | |
948 _indexTestUnit(''' | |
949 import 'dart:math'; | |
950 main() { | |
951 PI; | |
952 E; | |
953 max(1, 2); | |
954 } | |
955 '''); | |
956 assertHasAssistAt('art:math', AssistKind.IMPORT_ADD_SHOW, ''' | |
957 import 'dart:math' show E, PI, max; | |
958 main() { | |
959 PI; | |
960 E; | |
961 max(1, 2); | |
962 } | |
963 '''); | |
964 } | |
965 | |
966 void test_invertIfStatement_blocks() { | |
967 _indexTestUnit(''' | |
968 main() { | |
969 if (true) { | |
970 0; | |
971 } else { | |
972 1; | |
973 } | |
974 } | |
975 '''); | |
976 assertHasAssistAt('if (', AssistKind.INVERT_IF_STATEMENT, ''' | |
977 main() { | |
978 if (false) { | |
979 1; | |
980 } else { | |
981 0; | |
982 } | |
983 } | |
984 '''); | |
985 } | |
986 | |
987 void test_invertIfStatement_statements() { | |
988 _indexTestUnit(''' | |
989 main() { | |
990 if (true) | |
991 0; | |
992 else | |
993 1; | |
994 } | |
995 '''); | |
996 assertHasAssistAt('if (', AssistKind.INVERT_IF_STATEMENT, ''' | |
997 main() { | |
998 if (false) | |
999 1; | |
1000 else | |
1001 0; | |
1002 } | |
1003 '''); | |
1004 } | |
1005 | |
1006 void test_joinIfStatementInner_OK_conditionAndOr() { | |
1007 _indexTestUnit(''' | |
1008 main() { | |
1009 if (1 == 1) { | |
1010 if (2 == 2 || 3 == 3) { | |
1011 print(0); | |
1012 } | |
1013 } | |
1014 } | |
1015 '''); | |
1016 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1017 main() { | |
1018 if (1 == 1 && (2 == 2 || 3 == 3)) { | |
1019 print(0); | |
1020 } | |
1021 } | |
1022 '''); | |
1023 } | |
1024 | |
1025 void test_joinIfStatementInner_OK_conditionInvocation() { | |
1026 _indexTestUnit(''' | |
1027 main() { | |
1028 if (isCheck()) { | |
1029 if (2 == 2) { | |
1030 print(0); | |
1031 } | |
1032 } | |
1033 } | |
1034 bool isCheck() => false; | |
1035 '''); | |
1036 assertHasAssistAt('if (isCheck', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1037 main() { | |
1038 if (isCheck() && 2 == 2) { | |
1039 print(0); | |
1040 } | |
1041 } | |
1042 bool isCheck() => false; | |
1043 '''); | |
1044 } | |
1045 | |
1046 void test_joinIfStatementInner_OK_conditionOrAnd() { | |
1047 _indexTestUnit(''' | |
1048 main() { | |
1049 if (1 == 1 || 2 == 2) { | |
1050 if (3 == 3) { | |
1051 print(0); | |
1052 } | |
1053 } | |
1054 } | |
1055 '''); | |
1056 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1057 main() { | |
1058 if ((1 == 1 || 2 == 2) && 3 == 3) { | |
1059 print(0); | |
1060 } | |
1061 } | |
1062 '''); | |
1063 } | |
1064 | |
1065 void test_joinIfStatementInner_OK_onCondition() { | |
1066 _indexTestUnit(''' | |
1067 main() { | |
1068 if (1 == 1) { | |
1069 if (2 == 2) { | |
1070 print(0); | |
1071 } | |
1072 } | |
1073 } | |
1074 '''); | |
1075 assertHasAssistAt('1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1076 main() { | |
1077 if (1 == 1 && 2 == 2) { | |
1078 print(0); | |
1079 } | |
1080 } | |
1081 '''); | |
1082 } | |
1083 | |
1084 void test_joinIfStatementInner_OK_simpleConditions_block_block() { | |
1085 _indexTestUnit(''' | |
1086 main() { | |
1087 if (1 == 1) { | |
1088 if (2 == 2) { | |
1089 print(0); | |
1090 } | |
1091 } | |
1092 } | |
1093 '''); | |
1094 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1095 main() { | |
1096 if (1 == 1 && 2 == 2) { | |
1097 print(0); | |
1098 } | |
1099 } | |
1100 '''); | |
1101 } | |
1102 | |
1103 void test_joinIfStatementInner_OK_simpleConditions_block_single() { | |
1104 _indexTestUnit(''' | |
1105 main() { | |
1106 if (1 == 1) { | |
1107 if (2 == 2) | |
1108 print(0); | |
1109 } | |
1110 } | |
1111 '''); | |
1112 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1113 main() { | |
1114 if (1 == 1 && 2 == 2) { | |
1115 print(0); | |
1116 } | |
1117 } | |
1118 '''); | |
1119 } | |
1120 | |
1121 void test_joinIfStatementInner_OK_simpleConditions_single_blockMulti() { | |
1122 _indexTestUnit(''' | |
1123 main() { | |
1124 if (1 == 1) { | |
1125 if (2 == 2) { | |
1126 print(1); | |
1127 print(2); | |
1128 print(3); | |
1129 } | |
1130 } | |
1131 } | |
1132 '''); | |
1133 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1134 main() { | |
1135 if (1 == 1 && 2 == 2) { | |
1136 print(1); | |
1137 print(2); | |
1138 print(3); | |
1139 } | |
1140 } | |
1141 '''); | |
1142 } | |
1143 | |
1144 void test_joinIfStatementInner_OK_simpleConditions_single_blockOne() { | |
1145 _indexTestUnit(''' | |
1146 main() { | |
1147 if (1 == 1) | |
1148 if (2 == 2) { | |
1149 print(0); | |
1150 } | |
1151 } | |
1152 '''); | |
1153 assertHasAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER, ''' | |
1154 main() { | |
1155 if (1 == 1 && 2 == 2) { | |
1156 print(0); | |
1157 } | |
1158 } | |
1159 '''); | |
1160 } | |
1161 | |
1162 void test_joinIfStatementInner_wrong_innerNotIf() { | |
1163 _indexTestUnit(''' | |
1164 main() { | |
1165 if (1 == 1) { | |
1166 print(0); | |
1167 } | |
1168 } | |
1169 '''); | |
1170 assertNoAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER); | |
1171 } | |
1172 | |
1173 void test_joinIfStatementInner_wrong_innerWithElse() { | |
1174 _indexTestUnit(''' | |
1175 main() { | |
1176 if (1 == 1) { | |
1177 if (2 == 2) { | |
1178 print(0); | |
1179 } else { | |
1180 print(1); | |
1181 } | |
1182 } | |
1183 } | |
1184 '''); | |
1185 assertNoAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER); | |
1186 } | |
1187 | |
1188 void test_joinIfStatementInner_wrong_targetNotIf() { | |
1189 _indexTestUnit(''' | |
1190 main() { | |
1191 print(0); | |
1192 } | |
1193 '''); | |
1194 assertNoAssistAt('print', AssistKind.JOIN_IF_WITH_INNER); | |
1195 } | |
1196 | |
1197 void test_joinIfStatementInner_wrong_targetWithElse() { | |
1198 _indexTestUnit(''' | |
1199 main() { | |
1200 if (1 == 1) { | |
1201 if (2 == 2) { | |
1202 print(0); | |
1203 } | |
1204 } else { | |
1205 print(1); | |
1206 } | |
1207 } | |
1208 '''); | |
1209 assertNoAssistAt('if (1 ==', AssistKind.JOIN_IF_WITH_INNER); | |
1210 } | |
1211 | |
1212 void test_joinIfStatementOuter_OK_conditionAndOr() { | |
1213 _indexTestUnit(''' | |
1214 main() { | |
1215 if (1 == 1) { | |
1216 if (2 == 2 || 3 == 3) { | |
1217 print(0); | |
1218 } | |
1219 } | |
1220 } | |
1221 '''); | |
1222 assertHasAssistAt('if (2 ==', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1223 main() { | |
1224 if (1 == 1 && (2 == 2 || 3 == 3)) { | |
1225 print(0); | |
1226 } | |
1227 } | |
1228 '''); | |
1229 } | |
1230 | |
1231 void test_joinIfStatementOuter_OK_conditionInvocation() { | |
1232 _indexTestUnit(''' | |
1233 main() { | |
1234 if (1 == 1) { | |
1235 if (isCheck()) { | |
1236 print(0); | |
1237 } | |
1238 } | |
1239 } | |
1240 bool isCheck() => false; | |
1241 '''); | |
1242 assertHasAssistAt('if (isCheck', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1243 main() { | |
1244 if (1 == 1 && isCheck()) { | |
1245 print(0); | |
1246 } | |
1247 } | |
1248 bool isCheck() => false; | |
1249 '''); | |
1250 } | |
1251 | |
1252 void test_joinIfStatementOuter_OK_conditionOrAnd() { | |
1253 _indexTestUnit(''' | |
1254 main() { | |
1255 if (1 == 1 || 2 == 2) { | |
1256 if (3 == 3) { | |
1257 print(0); | |
1258 } | |
1259 } | |
1260 } | |
1261 '''); | |
1262 assertHasAssistAt('if (3 == 3', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1263 main() { | |
1264 if ((1 == 1 || 2 == 2) && 3 == 3) { | |
1265 print(0); | |
1266 } | |
1267 } | |
1268 '''); | |
1269 } | |
1270 | |
1271 void test_joinIfStatementOuter_OK_onCondition() { | |
1272 _indexTestUnit(''' | |
1273 main() { | |
1274 if (1 == 1) { | |
1275 if (2 == 2) { | |
1276 print(0); | |
1277 } | |
1278 } | |
1279 } | |
1280 '''); | |
1281 assertHasAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1282 main() { | |
1283 if (1 == 1 && 2 == 2) { | |
1284 print(0); | |
1285 } | |
1286 } | |
1287 '''); | |
1288 } | |
1289 | |
1290 void test_joinIfStatementOuter_OK_simpleConditions_block_block() { | |
1291 _indexTestUnit(''' | |
1292 main() { | |
1293 if (1 == 1) { | |
1294 if (2 == 2) { | |
1295 print(0); | |
1296 } | |
1297 } | |
1298 } | |
1299 '''); | |
1300 assertHasAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1301 main() { | |
1302 if (1 == 1 && 2 == 2) { | |
1303 print(0); | |
1304 } | |
1305 } | |
1306 '''); | |
1307 } | |
1308 | |
1309 void test_joinIfStatementOuter_OK_simpleConditions_block_single() { | |
1310 _indexTestUnit(''' | |
1311 main() { | |
1312 if (1 == 1) { | |
1313 if (2 == 2) | |
1314 print(0); | |
1315 } | |
1316 } | |
1317 '''); | |
1318 assertHasAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1319 main() { | |
1320 if (1 == 1 && 2 == 2) { | |
1321 print(0); | |
1322 } | |
1323 } | |
1324 '''); | |
1325 } | |
1326 | |
1327 void test_joinIfStatementOuter_OK_simpleConditions_single_blockMulti() { | |
1328 _indexTestUnit(''' | |
1329 main() { | |
1330 if (1 == 1) { | |
1331 if (2 == 2) { | |
1332 print(1); | |
1333 print(2); | |
1334 print(3); | |
1335 } | |
1336 } | |
1337 } | |
1338 '''); | |
1339 assertHasAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1340 main() { | |
1341 if (1 == 1 && 2 == 2) { | |
1342 print(1); | |
1343 print(2); | |
1344 print(3); | |
1345 } | |
1346 } | |
1347 '''); | |
1348 } | |
1349 | |
1350 void test_joinIfStatementOuter_OK_simpleConditions_single_blockOne() { | |
1351 _indexTestUnit(''' | |
1352 main() { | |
1353 if (1 == 1) | |
1354 if (2 == 2) { | |
1355 print(0); | |
1356 } | |
1357 } | |
1358 '''); | |
1359 assertHasAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER, ''' | |
1360 main() { | |
1361 if (1 == 1 && 2 == 2) { | |
1362 print(0); | |
1363 } | |
1364 } | |
1365 '''); | |
1366 } | |
1367 | |
1368 void test_joinIfStatementOuter_wrong_outerNotIf() { | |
1369 _indexTestUnit(''' | |
1370 main() { | |
1371 if (1 == 1) { | |
1372 print(0); | |
1373 } | |
1374 } | |
1375 '''); | |
1376 assertNoAssistAt('if (1 == 1', AssistKind.JOIN_IF_WITH_OUTER); | |
1377 } | |
1378 | |
1379 void test_joinIfStatementOuter_wrong_outerWithElse() { | |
1380 _indexTestUnit(''' | |
1381 main() { | |
1382 if (1 == 1) { | |
1383 if (2 == 2) { | |
1384 print(0); | |
1385 } | |
1386 } else { | |
1387 print(1); | |
1388 } | |
1389 } | |
1390 '''); | |
1391 assertNoAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER); | |
1392 } | |
1393 | |
1394 void test_joinIfStatementOuter_wrong_targetNotIf() { | |
1395 _indexTestUnit(''' | |
1396 main() { | |
1397 print(0); | |
1398 } | |
1399 '''); | |
1400 assertNoAssistAt('print', AssistKind.JOIN_IF_WITH_OUTER); | |
1401 } | |
1402 | |
1403 void test_joinIfStatementOuter_wrong_targetWithElse() { | |
1404 _indexTestUnit(''' | |
1405 main() { | |
1406 if (1 == 1) { | |
1407 if (2 == 2) { | |
1408 print(0); | |
1409 } else { | |
1410 print(1); | |
1411 } | |
1412 } | |
1413 } | |
1414 '''); | |
1415 assertNoAssistAt('if (2 == 2', AssistKind.JOIN_IF_WITH_OUTER); | |
1416 } | |
1417 | |
1418 void test_joinVariableDeclaration_onAssignment_OK() { | |
1419 _indexTestUnit(''' | |
1420 main() { | |
1421 var v; | |
1422 v = 1; | |
1423 } | |
1424 '''); | |
1425 assertHasAssistAt('v =', AssistKind.JOIN_VARIABLE_DECLARATION, ''' | |
1426 main() { | |
1427 var v = 1; | |
1428 } | |
1429 '''); | |
1430 } | |
1431 | |
1432 void test_joinVariableDeclaration_onAssignment_wrong_hasInitializer() { | |
1433 _indexTestUnit(''' | |
1434 main() { | |
1435 var v = 1; | |
1436 v = 2; | |
1437 } | |
1438 '''); | |
1439 assertNoAssistAt('v = 2', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1440 } | |
1441 | |
1442 void test_joinVariableDeclaration_onAssignment_wrong_notAdjacent() { | |
1443 _indexTestUnit(''' | |
1444 main() { | |
1445 var v; | |
1446 var bar; | |
1447 v = 1; | |
1448 } | |
1449 '''); | |
1450 assertNoAssistAt('v = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1451 } | |
1452 | |
1453 void test_joinVariableDeclaration_onAssignment_wrong_notAssignment() { | |
1454 _indexTestUnit(''' | |
1455 main() { | |
1456 var v; | |
1457 v += 1; | |
1458 } | |
1459 '''); | |
1460 assertNoAssistAt('v += 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1461 } | |
1462 | |
1463 void test_joinVariableDeclaration_onAssignment_wrong_notDeclaration() { | |
1464 _indexTestUnit(''' | |
1465 main(var v) { | |
1466 v = 1; | |
1467 } | |
1468 '''); | |
1469 assertNoAssistAt('v = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1470 } | |
1471 | |
1472 void test_joinVariableDeclaration_onAssignment_wrong_notLeftArgument() { | |
1473 _indexTestUnit(''' | |
1474 main() { | |
1475 var v; | |
1476 1 + v; // marker | |
1477 } | |
1478 '''); | |
1479 assertNoAssistAt('v; // marker', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1480 } | |
1481 | |
1482 void test_joinVariableDeclaration_onAssignment_wrong_notOneVariable() { | |
1483 _indexTestUnit(''' | |
1484 main() { | |
1485 var v, v2; | |
1486 v = 1; | |
1487 } | |
1488 '''); | |
1489 assertNoAssistAt('v = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1490 } | |
1491 | |
1492 void test_joinVariableDeclaration_onAssignment_wrong_notResolved() { | |
1493 verifyNoTestUnitErrors = false; | |
1494 _indexTestUnit(''' | |
1495 main() { | |
1496 var v; | |
1497 x = 1; | |
1498 } | |
1499 '''); | |
1500 assertNoAssistAt('x = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1501 } | |
1502 | |
1503 void test_joinVariableDeclaration_onAssignment_wrong_notSameBlock() { | |
1504 _indexTestUnit(''' | |
1505 main() { | |
1506 var v; | |
1507 { | |
1508 v = 1; | |
1509 } | |
1510 } | |
1511 '''); | |
1512 assertNoAssistAt('v = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1513 } | |
1514 | |
1515 void test_joinVariableDeclaration_onDeclaration_OK_onName() { | |
1516 _indexTestUnit(''' | |
1517 main() { | |
1518 var v; | |
1519 v = 1; | |
1520 } | |
1521 '''); | |
1522 assertHasAssistAt('v;', AssistKind.JOIN_VARIABLE_DECLARATION, ''' | |
1523 main() { | |
1524 var v = 1; | |
1525 } | |
1526 '''); | |
1527 } | |
1528 | |
1529 void test_joinVariableDeclaration_onDeclaration_OK_onType() { | |
1530 _indexTestUnit(''' | |
1531 main() { | |
1532 int v; | |
1533 v = 1; | |
1534 } | |
1535 '''); | |
1536 assertHasAssistAt('int v', AssistKind.JOIN_VARIABLE_DECLARATION, ''' | |
1537 main() { | |
1538 int v = 1; | |
1539 } | |
1540 '''); | |
1541 } | |
1542 | |
1543 void test_joinVariableDeclaration_onDeclaration_OK_onVar() { | |
1544 _indexTestUnit(''' | |
1545 main() { | |
1546 var v; | |
1547 v = 1; | |
1548 } | |
1549 '''); | |
1550 assertHasAssistAt('var v', AssistKind.JOIN_VARIABLE_DECLARATION, ''' | |
1551 main() { | |
1552 var v = 1; | |
1553 } | |
1554 '''); | |
1555 } | |
1556 | |
1557 void test_joinVariableDeclaration_onDeclaration_wrong_hasInitializer() { | |
1558 _indexTestUnit(''' | |
1559 main() { | |
1560 var v = 1; | |
1561 v = 2; | |
1562 } | |
1563 '''); | |
1564 assertNoAssistAt('v = 1', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1565 } | |
1566 | |
1567 void test_joinVariableDeclaration_onDeclaration_wrong_lastStatement() { | |
1568 _indexTestUnit(''' | |
1569 main() { | |
1570 if (true) | |
1571 var v; | |
1572 } | |
1573 '''); | |
1574 assertNoAssistAt('v;', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1575 } | |
1576 | |
1577 void | |
1578 test_joinVariableDeclaration_onDeclaration_wrong_nextNotAssignmentExpressi
on() { | |
1579 _indexTestUnit(''' | |
1580 main() { | |
1581 var v; | |
1582 42; | |
1583 } | |
1584 '''); | |
1585 assertNoAssistAt('v;', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1586 } | |
1587 | |
1588 void | |
1589 test_joinVariableDeclaration_onDeclaration_wrong_nextNotExpressionStatemen
t() { | |
1590 _indexTestUnit(''' | |
1591 main() { | |
1592 var v; | |
1593 if (true) return; | |
1594 } | |
1595 '''); | |
1596 assertNoAssistAt('v;', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1597 } | |
1598 | |
1599 void | |
1600 test_joinVariableDeclaration_onDeclaration_wrong_nextNotPureAssignment() { | |
1601 _indexTestUnit(''' | |
1602 main() { | |
1603 var v; | |
1604 v += 1; | |
1605 } | |
1606 '''); | |
1607 assertNoAssistAt('v;', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1608 } | |
1609 | |
1610 void test_joinVariableDeclaration_onDeclaration_wrong_notOneVariable() { | |
1611 _indexTestUnit(''' | |
1612 main() { | |
1613 var v, v2; | |
1614 v = 1; | |
1615 } | |
1616 '''); | |
1617 assertNoAssistAt('v, ', AssistKind.JOIN_VARIABLE_DECLARATION); | |
1618 } | |
1619 | |
1620 void test_removeTypeAnnotation_classField_OK() { | |
1621 _indexTestUnit(''' | |
1622 class A { | |
1623 int v = 1; | |
1624 } | |
1625 '''); | |
1626 assertHasAssistAt('v = ', AssistKind.REMOVE_TYPE_ANNOTATION, ''' | |
1627 class A { | |
1628 var v = 1; | |
1629 } | |
1630 '''); | |
1631 } | |
1632 | |
1633 void test_removeTypeAnnotation_localVariable_OK() { | |
1634 _indexTestUnit(''' | |
1635 main() { | |
1636 int a = 1, b = 2; | |
1637 } | |
1638 '''); | |
1639 assertHasAssistAt('int ', AssistKind.REMOVE_TYPE_ANNOTATION, ''' | |
1640 main() { | |
1641 var a = 1, b = 2; | |
1642 } | |
1643 '''); | |
1644 } | |
1645 | |
1646 void test_removeTypeAnnotation_topLevelVariable_OK() { | |
1647 _indexTestUnit(''' | |
1648 int V = 1; | |
1649 '''); | |
1650 assertHasAssistAt('int ', AssistKind.REMOVE_TYPE_ANNOTATION, ''' | |
1651 var V = 1; | |
1652 '''); | |
1653 } | |
1654 | |
1655 void test_replaceConditionalWithIfElse_OK_assignment() { | |
1656 _indexTestUnit(''' | |
1657 main() { | |
1658 var v; | |
1659 v = true ? 111 : 222; | |
1660 } | |
1661 '''); | |
1662 // on conditional | |
1663 assertHasAssistAt('11 :', AssistKind.REPLACE_CONDITIONAL_WITH_IF_ELSE, ''' | |
1664 main() { | |
1665 var v; | |
1666 if (true) { | |
1667 v = 111; | |
1668 } else { | |
1669 v = 222; | |
1670 } | |
1671 } | |
1672 '''); | |
1673 // on variable | |
1674 assertHasAssistAt('v =', AssistKind.REPLACE_CONDITIONAL_WITH_IF_ELSE, ''' | |
1675 main() { | |
1676 var v; | |
1677 if (true) { | |
1678 v = 111; | |
1679 } else { | |
1680 v = 222; | |
1681 } | |
1682 } | |
1683 '''); | |
1684 } | |
1685 | |
1686 void test_replaceConditionalWithIfElse_OK_return() { | |
1687 _indexTestUnit(''' | |
1688 main() { | |
1689 return true ? 111 : 222; | |
1690 } | |
1691 '''); | |
1692 assertHasAssistAt( | |
1693 'return ', | |
1694 AssistKind.REPLACE_CONDITIONAL_WITH_IF_ELSE, | |
1695 ''' | |
1696 main() { | |
1697 if (true) { | |
1698 return 111; | |
1699 } else { | |
1700 return 222; | |
1701 } | |
1702 } | |
1703 '''); | |
1704 } | |
1705 | |
1706 void test_replaceConditionalWithIfElse_OK_variableDeclaration() { | |
1707 _indexTestUnit(''' | |
1708 main() { | |
1709 int a = 1, vvv = true ? 111 : 222, b = 2; | |
1710 } | |
1711 '''); | |
1712 assertHasAssistAt('11 :', AssistKind.REPLACE_CONDITIONAL_WITH_IF_ELSE, ''' | |
1713 main() { | |
1714 int a = 1, vvv, b = 2; | |
1715 if (true) { | |
1716 vvv = 111; | |
1717 } else { | |
1718 vvv = 222; | |
1719 } | |
1720 } | |
1721 '''); | |
1722 } | |
1723 | |
1724 void test_replaceConditionalWithIfElse_wrong_noEnclosingStatement() { | |
1725 _indexTestUnit(''' | |
1726 var v = true ? 111 : 222; | |
1727 '''); | |
1728 assertNoAssistAt('? 111', AssistKind.REPLACE_CONDITIONAL_WITH_IF_ELSE); | |
1729 } | |
1730 | |
1731 void test_replaceIfElseWithConditional_OK_assignment() { | |
1732 _indexTestUnit(''' | |
1733 main() { | |
1734 int vvv; | |
1735 if (true) { | |
1736 vvv = 111; | |
1737 } else { | |
1738 vvv = 222; | |
1739 } | |
1740 } | |
1741 '''); | |
1742 assertHasAssistAt( | |
1743 'if (true)', | |
1744 AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL, | |
1745 ''' | |
1746 main() { | |
1747 int vvv; | |
1748 vvv = true ? 111 : 222; | |
1749 } | |
1750 '''); | |
1751 } | |
1752 | |
1753 void test_replaceIfElseWithConditional_OK_return() { | |
1754 _indexTestUnit(''' | |
1755 main() { | |
1756 if (true) { | |
1757 return 111; | |
1758 } else { | |
1759 return 222; | |
1760 } | |
1761 } | |
1762 '''); | |
1763 assertHasAssistAt( | |
1764 'if (true)', | |
1765 AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL, | |
1766 ''' | |
1767 main() { | |
1768 return true ? 111 : 222; | |
1769 } | |
1770 '''); | |
1771 } | |
1772 | |
1773 void test_replaceIfElseWithConditional_wrong_notIfStatement() { | |
1774 _indexTestUnit(''' | |
1775 main() { | |
1776 print(0); | |
1777 } | |
1778 '''); | |
1779 assertNoAssistAt('print', AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL); | |
1780 } | |
1781 | |
1782 void test_replaceIfElseWithConditional_wrong_notSingleStatememt() { | |
1783 _indexTestUnit(''' | |
1784 main() { | |
1785 int vvv; | |
1786 if (true) { | |
1787 print(0); | |
1788 vvv = 111; | |
1789 } else { | |
1790 print(0); | |
1791 vvv = 222; | |
1792 } | |
1793 } | |
1794 '''); | |
1795 assertNoAssistAt('if (true)', AssistKind.REPLACE_IF_ELSE_WITH_CONDITIONAL); | |
1796 } | |
1797 | |
1798 void test_splitAndCondition_OK_innerAndExpression() { | |
1799 _indexTestUnit(''' | |
1800 main() { | |
1801 if (1 == 1 && 2 == 2 && 3 == 3) { | |
1802 print(0); | |
1803 } | |
1804 } | |
1805 '''); | |
1806 assertHasAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION, ''' | |
1807 main() { | |
1808 if (1 == 1) { | |
1809 if (2 == 2 && 3 == 3) { | |
1810 print(0); | |
1811 } | |
1812 } | |
1813 } | |
1814 '''); | |
1815 } | |
1816 | |
1817 void test_splitAndCondition_OK_thenBlock() { | |
1818 _indexTestUnit(''' | |
1819 main() { | |
1820 if (true && false) { | |
1821 print(0); | |
1822 if (3 == 3) { | |
1823 print(1); | |
1824 } | |
1825 } | |
1826 } | |
1827 '''); | |
1828 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, ''' | |
1829 main() { | |
1830 if (true) { | |
1831 if (false) { | |
1832 print(0); | |
1833 if (3 == 3) { | |
1834 print(1); | |
1835 } | |
1836 } | |
1837 } | |
1838 } | |
1839 '''); | |
1840 } | |
1841 | |
1842 void test_splitAndCondition_OK_thenBlock_elseBlock() { | |
1843 _indexTestUnit(''' | |
1844 main() { | |
1845 if (true && false) { | |
1846 print(0); | |
1847 } else { | |
1848 print(1); | |
1849 if (2 == 2) { | |
1850 print(2); | |
1851 } | |
1852 } | |
1853 } | |
1854 '''); | |
1855 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, ''' | |
1856 main() { | |
1857 if (true) { | |
1858 if (false) { | |
1859 print(0); | |
1860 } else { | |
1861 print(1); | |
1862 if (2 == 2) { | |
1863 print(2); | |
1864 } | |
1865 } | |
1866 } | |
1867 } | |
1868 '''); | |
1869 } | |
1870 | |
1871 void test_splitAndCondition_OK_thenStatement() { | |
1872 _indexTestUnit(''' | |
1873 main() { | |
1874 if (true && false) | |
1875 print(0); | |
1876 } | |
1877 '''); | |
1878 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, ''' | |
1879 main() { | |
1880 if (true) | |
1881 if (false) | |
1882 print(0); | |
1883 } | |
1884 '''); | |
1885 } | |
1886 | |
1887 void test_splitAndCondition_OK_thenStatement_elseStatement() { | |
1888 _indexTestUnit(''' | |
1889 main() { | |
1890 if (true && false) | |
1891 print(0); | |
1892 else | |
1893 print(1); | |
1894 } | |
1895 '''); | |
1896 assertHasAssistAt('&& false', AssistKind.SPLIT_AND_CONDITION, ''' | |
1897 main() { | |
1898 if (true) | |
1899 if (false) | |
1900 print(0); | |
1901 else | |
1902 print(1); | |
1903 } | |
1904 '''); | |
1905 } | |
1906 | |
1907 void test_splitAndCondition_wrong() { | |
1908 _indexTestUnit(''' | |
1909 main() { | |
1910 if (1 == 1 && 2 == 2) { | |
1911 print(0); | |
1912 } | |
1913 print(3 == 3 && 4 == 4); | |
1914 } | |
1915 '''); | |
1916 // not binary expression | |
1917 assertNoAssistAt('main() {', AssistKind.SPLIT_AND_CONDITION); | |
1918 // selection is not empty and includes more than just operator | |
1919 { | |
1920 length = 5; | |
1921 assertNoAssistAt('&& 2 == 2', AssistKind.SPLIT_AND_CONDITION); | |
1922 } | |
1923 } | |
1924 | |
1925 void test_splitAndCondition_wrong_notAnd() { | |
1926 _indexTestUnit(''' | |
1927 main() { | |
1928 if (1 == 1 || 2 == 2) { | |
1929 print(0); | |
1930 } | |
1931 } | |
1932 '''); | |
1933 assertNoAssistAt('|| 2', AssistKind.SPLIT_AND_CONDITION); | |
1934 } | |
1935 | |
1936 void test_splitAndCondition_wrong_notPartOfIf() { | |
1937 _indexTestUnit(''' | |
1938 main() { | |
1939 print(1 == 1 && 2 == 2); | |
1940 } | |
1941 '''); | |
1942 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION); | |
1943 } | |
1944 | |
1945 void test_splitAndCondition_wrong_notTopLevelAnd() { | |
1946 _indexTestUnit(''' | |
1947 main() { | |
1948 if (true || (1 == 1 && 2 == 2)) { | |
1949 print(0); | |
1950 } | |
1951 if (true && (3 == 3 && 4 == 4)) { | |
1952 print(0); | |
1953 } | |
1954 } | |
1955 '''); | |
1956 assertNoAssistAt('&& 2', AssistKind.SPLIT_AND_CONDITION); | |
1957 assertNoAssistAt('&& 4', AssistKind.SPLIT_AND_CONDITION); | |
1958 } | |
1959 | |
1960 void test_splitVariableDeclaration_OK_onName() { | |
1961 _indexTestUnit(''' | |
1962 main() { | |
1963 var v = 1; | |
1964 } | |
1965 '''); | |
1966 assertHasAssistAt('v =', AssistKind.SPLIT_VARIABLE_DECLARATION, ''' | |
1967 main() { | |
1968 var v; | |
1969 v = 1; | |
1970 } | |
1971 '''); | |
1972 } | |
1973 | |
1974 void test_splitVariableDeclaration_OK_onType() { | |
1975 _indexTestUnit(''' | |
1976 main() { | |
1977 int v = 1; | |
1978 } | |
1979 '''); | |
1980 assertHasAssistAt('int ', AssistKind.SPLIT_VARIABLE_DECLARATION, ''' | |
1981 main() { | |
1982 int v; | |
1983 v = 1; | |
1984 } | |
1985 '''); | |
1986 } | |
1987 | |
1988 void test_splitVariableDeclaration_OK_onVar() { | |
1989 _indexTestUnit(''' | |
1990 main() { | |
1991 var v = 1; | |
1992 } | |
1993 '''); | |
1994 assertHasAssistAt('var ', AssistKind.SPLIT_VARIABLE_DECLARATION, ''' | |
1995 main() { | |
1996 var v; | |
1997 v = 1; | |
1998 } | |
1999 '''); | |
2000 } | |
2001 | |
2002 void test_splitVariableDeclaration_wrong_notOneVariable() { | |
2003 _indexTestUnit(''' | |
2004 main() { | |
2005 var v = 1, v2; | |
2006 } | |
2007 '''); | |
2008 assertNoAssistAt('v = 1', AssistKind.SPLIT_VARIABLE_DECLARATION); | |
2009 } | |
2010 | |
2011 void test_surroundWith_block() { | |
2012 _indexTestUnit(''' | |
2013 main() { | |
2014 // start | |
2015 print(0); | |
2016 print(1); | |
2017 // end | |
2018 } | |
2019 '''); | |
2020 _setStartEndSelection(); | |
2021 assertHasAssist(AssistKind.SURROUND_WITH_BLOCK, ''' | |
2022 main() { | |
2023 // start | |
2024 { | |
2025 print(0); | |
2026 print(1); | |
2027 } | |
2028 // end | |
2029 } | |
2030 '''); | |
2031 } | |
2032 | |
2033 void test_surroundWith_doWhile() { | |
2034 _indexTestUnit(''' | |
2035 main() { | |
2036 // start | |
2037 print(0); | |
2038 print(1); | |
2039 // end | |
2040 } | |
2041 '''); | |
2042 _setStartEndSelection(); | |
2043 assertHasAssist(AssistKind.SURROUND_WITH_DO_WHILE, ''' | |
2044 main() { | |
2045 // start | |
2046 do { | |
2047 print(0); | |
2048 print(1); | |
2049 } while (condition); | |
2050 // end | |
2051 } | |
2052 '''); | |
2053 } | |
2054 | |
2055 void test_surroundWith_for() { | |
2056 _indexTestUnit(''' | |
2057 main() { | |
2058 // start | |
2059 print(0); | |
2060 print(1); | |
2061 // end | |
2062 } | |
2063 '''); | |
2064 _setStartEndSelection(); | |
2065 assertHasAssist(AssistKind.SURROUND_WITH_FOR, ''' | |
2066 main() { | |
2067 // start | |
2068 for (var v = init; condition; increment) { | |
2069 print(0); | |
2070 print(1); | |
2071 } | |
2072 // end | |
2073 } | |
2074 '''); | |
2075 } | |
2076 | |
2077 void test_surroundWith_forIn() { | |
2078 _indexTestUnit(''' | |
2079 main() { | |
2080 // start | |
2081 print(0); | |
2082 print(1); | |
2083 // end | |
2084 } | |
2085 '''); | |
2086 _setStartEndSelection(); | |
2087 assertHasAssist(AssistKind.SURROUND_WITH_FOR_IN, ''' | |
2088 main() { | |
2089 // start | |
2090 for (var item in iterable) { | |
2091 print(0); | |
2092 print(1); | |
2093 } | |
2094 // end | |
2095 } | |
2096 '''); | |
2097 } | |
2098 | |
2099 void test_surroundWith_if() { | |
2100 _indexTestUnit(''' | |
2101 main() { | |
2102 // start | |
2103 print(0); | |
2104 print(1); | |
2105 // end | |
2106 } | |
2107 '''); | |
2108 _setStartEndSelection(); | |
2109 assertHasAssist(AssistKind.SURROUND_WITH_IF, ''' | |
2110 main() { | |
2111 // start | |
2112 if (condition) { | |
2113 print(0); | |
2114 print(1); | |
2115 } | |
2116 // end | |
2117 } | |
2118 '''); | |
2119 } | |
2120 | |
2121 void test_surroundWith_tryCatch() { | |
2122 _indexTestUnit(''' | |
2123 main() { | |
2124 // start | |
2125 print(0); | |
2126 print(1); | |
2127 // end | |
2128 } | |
2129 '''); | |
2130 _setStartEndSelection(); | |
2131 assertHasAssist(AssistKind.SURROUND_WITH_TRY_CATCH, ''' | |
2132 main() { | |
2133 // start | |
2134 try { | |
2135 print(0); | |
2136 print(1); | |
2137 } on Exception catch (e) { | |
2138 // TODO | |
2139 } | |
2140 // end | |
2141 } | |
2142 '''); | |
2143 } | |
2144 | |
2145 void test_surroundWith_tryFinally() { | |
2146 _indexTestUnit(''' | |
2147 main() { | |
2148 // start | |
2149 print(0); | |
2150 print(1); | |
2151 // end | |
2152 } | |
2153 '''); | |
2154 _setStartEndSelection(); | |
2155 assertHasAssist(AssistKind.SURROUND_WITH_TRY_FINALLY, ''' | |
2156 main() { | |
2157 // start | |
2158 try { | |
2159 print(0); | |
2160 print(1); | |
2161 } finally { | |
2162 // TODO | |
2163 } | |
2164 // end | |
2165 } | |
2166 '''); | |
2167 } | |
2168 | |
2169 void test_surroundWith_while() { | |
2170 _indexTestUnit(''' | |
2171 main() { | |
2172 // start | |
2173 print(0); | |
2174 print(1); | |
2175 // end | |
2176 } | |
2177 '''); | |
2178 _setStartEndSelection(); | |
2179 assertHasAssist(AssistKind.SURROUND_WITH_WHILE, ''' | |
2180 main() { | |
2181 // start | |
2182 while (condition) { | |
2183 print(0); | |
2184 print(1); | |
2185 } | |
2186 // end | |
2187 } | |
2188 '''); | |
2189 } | |
2190 | |
2191 /** | |
2192 * Computes assists and verifies that there is an assist of the given kind. | |
2193 */ | |
2194 Assist _assertHasAssist(AssistKind kind) { | |
2195 List<Assist> assists = | |
2196 computeAssists(searchEngine, testUnit, offset, length); | |
2197 for (Assist assist in assists) { | |
2198 if (assist.kind == kind) { | |
2199 return assist; | |
2200 } | |
2201 } | |
2202 throw fail('Expected to find assist $kind in\n${assists.join('\n')}'); | |
2203 } | |
2204 | |
2205 void _assertHasLinkedPositions(String groupId, List<String> expectedStrings) { | |
2206 List<Position> expectedPositions = _findResultPositions(expectedStrings); | |
2207 List<LinkedEditGroup> groups = change.linkedEditGroups; | |
2208 for (LinkedEditGroup group in groups) { | |
2209 if (group.id == groupId) { | |
2210 List<Position> actualPositions = group.positions; | |
2211 expect(actualPositions, unorderedEquals(expectedPositions)); | |
2212 return; | |
2213 } | |
2214 } | |
2215 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); | |
2216 } | |
2217 | |
2218 void _assertHasLinkedProposals(String groupId, List<String> expected) { | |
2219 List<LinkedEditGroup> groups = change.linkedEditGroups; | |
2220 for (LinkedEditGroup group in groups) { | |
2221 if (group.id == groupId) { | |
2222 expect(group.suggestions, expected); | |
2223 return; | |
2224 } | |
2225 } | |
2226 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); | |
2227 } | |
2228 | |
2229 List<Position> _findResultPositions(List<String> searchStrings) { | |
2230 List<Position> positions = <Position>[]; | |
2231 for (String search in searchStrings) { | |
2232 int offset = resultCode.indexOf(search); | |
2233 positions.add(new Position(testFile, offset)); | |
2234 } | |
2235 return positions; | |
2236 } | |
2237 | |
2238 void _indexTestUnit(String code) { | |
2239 resolveTestUnit(code); | |
2240 index.indexUnit(context, testUnit); | |
2241 } | |
2242 | |
2243 void _setStartEndSelection() { | |
2244 offset = findOffset('// start\n') + '// start\n'.length; | |
2245 length = findOffset('// end') - offset; | |
2246 } | |
2247 } | |
OLD | NEW |