blob: dc6e2665dec4fc350a04d8b08736fcf61c04c3c1 [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'fix_processor.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(AddReturnTypeLintTest);
});
}
@reflectiveTest
class AddReturnTypeLintTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.ADD_RETURN_TYPE;
@override
String get lintCode => LintNames.always_declare_return_types;
Future<void> test_localFunction_block() async {
await resolveTestUnit('''
class A {
void m() {
/*LINT*/f() {
return '';
}
}
}
''');
await assertHasFix('''
class A {
void m() {
String f() {
return '';
}
}
}
''');
}
Future<void> test_localFunction_expression() async {
await resolveTestUnit('''
class A {
void m() {
/*LINT*/f() => '';
}
}
''');
await assertHasFix('''
class A {
void m() {
String f() => '';
}
}
''');
}
Future<void> test_method_block_noReturn() async {
await resolveTestUnit('''
class A {
/*LINT*/m() {
}
}
''');
await assertNoFix();
}
Future<void> test_method_block_returnDynamic() async {
await resolveTestUnit('''
class A {
/*LINT*/m(p) {
return p;
}
}
''');
await assertNoFix();
}
Future<void> test_method_block_returnNoValue() async {
await resolveTestUnit('''
class A {
/*LINT*/m() {
return;
}
}
''');
await assertHasFix('''
class A {
void m() {
return;
}
}
''');
}
Future<void> test_method_block_singleReturn() async {
await resolveTestUnit('''
class A {
/*LINT*/m() {
return '';
}
}
''');
await assertHasFix('''
class A {
String m() {
return '';
}
}
''');
}
Future<void> test_method_expression() async {
await resolveTestUnit('''
class A {
/*LINT*/m() => '';
}
''');
await assertHasFix('''
class A {
String m() => '';
}
''');
}
Future<void> test_topLevelFunction_block() async {
await resolveTestUnit('''
/*LINT*/f() {
return '';
}
''');
await assertHasFix('''
String f() {
return '';
}
''');
}
Future<void> test_topLevelFunction_expression() async {
await resolveTestUnit('''
/*LINT*/f() => '';
''');
await assertHasFix('''
String f() => '';
''');
}
}