Skip to content

Commit

Permalink
For existing fixes, add super-parameter and named-args-anywhere tests
Browse files Browse the repository at this point in the history
Bug: #48067, #47578
Change-Id: Iaef317459c7e6901296475163959ad92a6c880b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231070
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and Commit Bot committed Feb 2, 2022
1 parent 64001ab commit b9b1252
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ void function({required String param}) {}
''');
}

Future<void> test_nonNullable_superParameter() async {
await resolveTestCode('''
class C {
C({required int param});
}
class D extends C {
D({super.param});
}
''');
await assertHasFix('''
class C {
C({required int param});
}
class D extends C {
D({required super.param});
}
''');
}

Future<void> test_withRequiredAnnotation() async {
writeTestPackageConfig(meta: true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,22 @@ class AddTrailingCommaTest extends FixProcessorLintTest {
@override
String get lintCode => LintNames.require_trailing_commas;

Future<void> test_comma() async {
Future<void> test_named() async {
await resolveTestCode('''
void f({a, b}) {
f(a: 'a',
b: 'b');
}
''');
await assertHasFix('''
void f({a, b}) {
f(a: 'a',
b: 'b',);
}
''');
}

Future<void> test_positional() async {
await resolveTestCode('''
void f(a, b) {
f('a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,29 @@ g(String Function(int Function() h) f) {}
}

@reflectiveTest
class UseFunctionTypeSyntaxForParametersTest extends FixProcessorLintTest
with WithNullSafetyLintMixin {
class UseFunctionTypeSyntaxForParametersTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.CONVERT_TO_GENERIC_FUNCTION_SYNTAX;

@override
String get lintCode => LintNames.use_function_type_syntax_for_parameters;

@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3212')
Future<void> test_functionTypedParameter_fieldFormal() async {
await resolveTestCode('''
class C {
String Function(int) f;
C(String this.f(int x));
}
''');
await assertHasFix('''
class C {
String Function(int) f;
C(String Function(int x) this.f);
}
''');
}

Future<void> test_functionTypedParameter_noParameterTypes() async {
await resolveTestCode('''
g(String f(x)) {}
Expand Down Expand Up @@ -153,6 +168,26 @@ g(String f(int x)) {}
''');
await assertHasFix('''
g(String Function(int x) f) {}
''');
}

@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3212')
Future<void> test_functionTypedParameter_superParameter() async {
await resolveTestCode('''
class C {
C(String Function(int x) f);
}
class D extends C {
D(String super.f(int x));
}
''');
await assertHasFix('''
class C {
C(String Function(int x) f);
}
class D extends C {
D(String Function(int x) super.f);
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ abstract class FixProcessorLintTest extends FixProcessorTest {
void setUp() {
super.setUp();
createAnalysisOptionsFile(
experiments: experiments,
lints: [lintCode],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ void main() {
''');
}

@FailingTest(
issue: 'https://github.com/dart-lang/linter/issues/3082',
)
Future<void> test_named_betweenRequiredPositional() async {
await resolveTestCode('''
void foo(int a, int b, {bool c = true}) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ void f([String? s]) {}
''');
}

Future<void> test_parameter_super() async {
await resolveTestCode('''
class C {
C({String? s});
}
class D extends C {
D({super.s = null});
}
''');
await assertHasFix('''
class C {
C({String? s});
}
class D extends C {
D({super.s});
}
''');
}

Future<void> test_topLevel() async {
await resolveTestCode('''
var x = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class TypeInitFormalsTest extends RemoveTypeAnnotationTest {
@override
String get lintCode => LintNames.type_init_formals;

Future<void> test_void() async {
Future<void> test_formalFieldParameter() async {
await resolveTestCode('''
class C {
int f;
Expand All @@ -243,6 +243,25 @@ class C {
int f;
C(this.f);
}
''');
}

@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3210')
Future<void> test_superParameter() async {
// If this issue gets closed as "won't fix," remove this test.
await resolveTestCode('''
class C {
C(int f);
}
class D extends C {
D(int super.f);
}
''');
await assertHasFix('''
class C {
int f;
C(super.f);
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ void f({int a: 1}) => null;
''');
await assertHasFix('''
void f({int a = 1}) => null;
''');
}

Future<void> test_superParameter() async {
await resolveTestCode('''
class C {
C({int? i});
}
class D extends C {
D({int? super.i: 1});
}
''');
await assertHasFix('''
class C {
C({int? i});
}
class D extends C {
D({int? super.i = 1});
}
''');
}
}

0 comments on commit b9b1252

Please sign in to comment.