| 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 5255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5266 | 5266 |
| 5267 Future applyFix(FixKind kind) async { | 5267 Future applyFix(FixKind kind) async { |
| 5268 fix = await _assertHasFix(kind, error); | 5268 fix = await _assertHasFix(kind, error); |
| 5269 change = fix.change; | 5269 change = fix.change; |
| 5270 // apply to "file" | 5270 // apply to "file" |
| 5271 List<SourceFileEdit> fileEdits = change.edits; | 5271 List<SourceFileEdit> fileEdits = change.edits; |
| 5272 expect(fileEdits, hasLength(1)); | 5272 expect(fileEdits, hasLength(1)); |
| 5273 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 5273 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 5274 } | 5274 } |
| 5275 | 5275 |
| 5276 void findLint(String src, String lintCode) { | 5276 void findLint(String src, String lintCode, {int length: 1}) { |
| 5277 int errorOffset = src.indexOf('/*LINT*/'); | 5277 int errorOffset = src.indexOf('/*LINT*/'); |
| 5278 resolveTestUnit(src.replaceAll('/*LINT*/', '')); | 5278 resolveTestUnit(src.replaceAll('/*LINT*/', '')); |
| 5279 error = new AnalysisError(testUnit.element.source, errorOffset, 1, | 5279 error = new AnalysisError(testUnit.element.source, errorOffset, length, |
| 5280 new LintCode(lintCode, '<ignored>')); | 5280 new LintCode(lintCode, '<ignored>')); |
| 5281 } | 5281 } |
| 5282 | 5282 |
| 5283 test_lint_addMissingOverride_field() async { | 5283 test_lint_addMissingOverride_field() async { |
| 5284 String src = ''' | 5284 String src = ''' |
| 5285 class abstract Test { | 5285 class abstract Test { |
| 5286 int get t; | 5286 int get t; |
| 5287 } | 5287 } |
| 5288 class Sub extends Test { | 5288 class Sub extends Test { |
| 5289 int /*LINT*/t = 42; | 5289 int /*LINT*/t = 42; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5455 void t() { } | 5455 void t() { } |
| 5456 } | 5456 } |
| 5457 class Sub extends Test { | 5457 class Sub extends Test { |
| 5458 // Non-doc comment. | 5458 // Non-doc comment. |
| 5459 @override | 5459 @override |
| 5460 void t() { } | 5460 void t() { } |
| 5461 } | 5461 } |
| 5462 '''); | 5462 '''); |
| 5463 } | 5463 } |
| 5464 | 5464 |
| 5465 test_lint_removeInterpolationBraces() async { |
| 5466 String src = r''' |
| 5467 main() { |
| 5468 var v = 42; |
| 5469 print('v: /*LINT*/${ v}'); |
| 5470 } |
| 5471 '''; |
| 5472 findLint(src, LintNames.unnecessary_brace_in_string_interp, length: 4); |
| 5473 await applyFix(DartFixKind.LINT_REMOVE_INTERPOLATION_BRACES); |
| 5474 verifyResult(r''' |
| 5475 main() { |
| 5476 var v = 42; |
| 5477 print('v: $v'); |
| 5478 } |
| 5479 '''); |
| 5480 } |
| 5481 |
| 5465 void verifyResult(String expectedResult) { | 5482 void verifyResult(String expectedResult) { |
| 5466 expect(resultCode, expectedResult); | 5483 expect(resultCode, expectedResult); |
| 5467 } | 5484 } |
| 5468 } | 5485 } |
| OLD | NEW |