OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 6 import 'package:test/test.dart'; |
| 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 8 |
| 9 import '../integration_tests.dart'; |
| 10 |
| 11 main() { |
| 12 defineReflectiveSuite(() { |
| 13 defineReflectiveTests(GetFixesTest); |
| 14 }); |
| 15 } |
| 16 |
| 17 @reflectiveTest |
| 18 class GetFixesTest extends AbstractAnalysisServerIntegrationTest { |
| 19 test_has_fixes() async { |
| 20 String pathname = sourcePath('test.dart'); |
| 21 String text = r''' |
| 22 Future f; |
| 23 '''; |
| 24 writeFile(pathname, text); |
| 25 standardAnalysisSetup(); |
| 26 |
| 27 await analysisFinished; |
| 28 expect(currentAnalysisErrors[pathname], isNotEmpty); |
| 29 |
| 30 EditGetFixesResult result = |
| 31 await sendEditGetFixes(pathname, text.indexOf('Future f')); |
| 32 expect(result.fixes, hasLength(1)); |
| 33 |
| 34 // expect a suggestion to add the dart:async import |
| 35 AnalysisErrorFixes fix = result.fixes.first; |
| 36 expect(fix.error.code, 'undefined_class'); |
| 37 expect(fix.fixes, isNotEmpty); |
| 38 |
| 39 // apply the fix, expect that the new code has no errors |
| 40 SourceChange change = fix.fixes.singleWhere( |
| 41 (SourceChange change) => change.message.startsWith('Import ')); |
| 42 expect(change.edits, hasLength(1)); |
| 43 expect(change.edits.first.edits, hasLength(1)); |
| 44 SourceEdit edit = change.edits.first.edits.first; |
| 45 text = text.replaceRange(edit.offset, edit.end, edit.replacement); |
| 46 writeFile(pathname, text); |
| 47 |
| 48 await analysisFinished; |
| 49 expect(currentAnalysisErrors[pathname], isEmpty); |
| 50 } |
| 51 |
| 52 test_no_fixes() async { |
| 53 String pathname = sourcePath('test.dart'); |
| 54 String text = r''' |
| 55 import 'dart:async'; |
| 56 |
| 57 Future f; |
| 58 '''; |
| 59 writeFile(pathname, text); |
| 60 standardAnalysisSetup(); |
| 61 |
| 62 EditGetFixesResult result = |
| 63 await sendEditGetFixes(pathname, text.indexOf('Future f')); |
| 64 expect(result.fixes, isEmpty); |
| 65 } |
| 66 |
| 67 @override |
| 68 bool get enableNewAnalysisDriver => true; |
| 69 } |
OLD | NEW |