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.correction.fix; | 5 library test.services.correction.fix; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 main() { | 70 main() { |
71 bool b = true; | 71 bool b = true; |
72 $lineWithTest | 72 $lineWithTest |
73 } | 73 } |
74 | 74 |
75 bool test() { | 75 bool test() { |
76 } | 76 } |
77 '''); | 77 '''); |
78 } | 78 } |
79 | 79 |
80 assertHasFix(FixKind kind, String expected) async { | 80 assertHasFix(FixKind kind, String expected, {String target}) async { |
81 AnalysisError error = await _findErrorToFix(); | 81 AnalysisError error = await _findErrorToFix(); |
82 fix = await _assertHasFix(kind, error); | 82 fix = await _assertHasFix(kind, error); |
83 change = fix.change; | 83 change = fix.change; |
| 84 |
84 // apply to "file" | 85 // apply to "file" |
85 List<SourceFileEdit> fileEdits = change.edits; | 86 List<SourceFileEdit> fileEdits = change.edits; |
86 expect(fileEdits, hasLength(1)); | 87 expect(fileEdits, hasLength(1)); |
| 88 |
| 89 if (target != null) { |
| 90 expect(target, fileEdits.first.file); |
| 91 } |
| 92 |
87 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 93 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
88 // verify | 94 // verify |
89 expect(resultCode, expected); | 95 expect(resultCode, expected); |
90 } | 96 } |
91 | 97 |
92 assertNoFix(FixKind kind) async { | 98 assertNoFix(FixKind kind) async { |
93 AnalysisError error = await _findErrorToFix(); | 99 AnalysisError error = await _findErrorToFix(); |
94 List<Fix> fixes = await _computeFixes(error); | 100 List<Fix> fixes = await _computeFixes(error); |
95 for (Fix fix in fixes) { | 101 for (Fix fix in fixes) { |
96 if (fix.kind == kind) { | 102 if (fix.kind == kind) { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 test(int i) {} | 428 test(int i) {} |
423 main() { | 429 main() { |
424 test(1); | 430 test(1); |
425 } | 431 } |
426 } | 432 } |
427 '''); | 433 '''); |
428 } | 434 } |
429 | 435 |
430 test_addMissingRequiredArg_cons_single() async { | 436 test_addMissingRequiredArg_cons_single() async { |
431 _addMetaPackageSource(); | 437 _addMetaPackageSource(); |
432 | 438 addSource( |
433 await resolveTestUnit(''' | 439 '/libA.dart', |
| 440 r''' |
| 441 library libA; |
434 import 'package:meta/meta.dart'; | 442 import 'package:meta/meta.dart'; |
435 | 443 |
436 class A { | 444 class A { |
437 A({@required int a}) {} | 445 A({@required int a}) {} |
438 } | 446 } |
| 447 '''); |
| 448 |
| 449 await resolveTestUnit(''' |
| 450 import 'libA.dart'; |
| 451 |
439 main() { | 452 main() { |
440 A a = new A(); | 453 A a = new A(); |
441 } | 454 } |
442 '''); | 455 '''); |
443 await assertHasFix( | 456 await assertHasFix( |
444 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, | 457 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
445 ''' | 458 ''' |
446 import 'package:meta/meta.dart'; | 459 import 'libA.dart'; |
447 | 460 |
448 class A { | |
449 A({@required int a}) {} | |
450 } | |
451 main() { | 461 main() { |
452 A a = new A(a: null); | 462 A a = new A(a: null); |
453 } | 463 } |
454 '''); | 464 ''', |
| 465 target: '/test.dart'); |
455 } | 466 } |
456 | 467 |
457 test_addMissingRequiredArg_multiple() async { | 468 test_addMissingRequiredArg_multiple() async { |
458 _addMetaPackageSource(); | 469 _addMetaPackageSource(); |
459 | 470 |
460 await resolveTestUnit(''' | 471 await resolveTestUnit(''' |
461 import 'package:meta/meta.dart'; | 472 import 'package:meta/meta.dart'; |
462 | 473 |
463 test({@required int a, @required int bcd}) {} | 474 test({@required int a, @required int bcd}) {} |
464 main() { | 475 main() { |
(...skipping 5366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5831 | 5842 |
5832 @override | 5843 @override |
5833 final CompilationUnit unit; | 5844 final CompilationUnit unit; |
5834 | 5845 |
5835 @override | 5846 @override |
5836 final AnalysisError error; | 5847 final AnalysisError error; |
5837 | 5848 |
5838 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, | 5849 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, |
5839 this.analysisContext, this.astProvider, this.unit, this.error); | 5850 this.analysisContext, this.astProvider, this.unit, this.error); |
5840 } | 5851 } |
OLD | NEW |