Skip to content

Commit b9b1252

Browse files
srawlinsCommit Bot
authored andcommitted
For existing fixes, add super-parameter and named-args-anywhere tests
Bug: #48067, #47578 Change-Id: Iaef317459c7e6901296475163959ad92a6c880b2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231070 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 64001ab commit b9b1252

8 files changed

+131
-7
lines changed

pkg/analysis_server/test/src/services/correction/fix/add_required_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ void function({required String param}) {}
8181
''');
8282
}
8383

84+
Future<void> test_nonNullable_superParameter() async {
85+
await resolveTestCode('''
86+
class C {
87+
C({required int param});
88+
}
89+
class D extends C {
90+
D({super.param});
91+
}
92+
''');
93+
await assertHasFix('''
94+
class C {
95+
C({required int param});
96+
}
97+
class D extends C {
98+
D({required super.param});
99+
}
100+
''');
101+
}
102+
84103
Future<void> test_withRequiredAnnotation() async {
85104
writeTestPackageConfig(meta: true);
86105

pkg/analysis_server/test/src/services/correction/fix/add_trailing_comma_test.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,22 @@ class AddTrailingCommaTest extends FixProcessorLintTest {
7272
@override
7373
String get lintCode => LintNames.require_trailing_commas;
7474

75-
Future<void> test_comma() async {
75+
Future<void> test_named() async {
76+
await resolveTestCode('''
77+
void f({a, b}) {
78+
f(a: 'a',
79+
b: 'b');
80+
}
81+
''');
82+
await assertHasFix('''
83+
void f({a, b}) {
84+
f(a: 'a',
85+
b: 'b',);
86+
}
87+
''');
88+
}
89+
90+
Future<void> test_positional() async {
7691
await resolveTestCode('''
7792
void f(a, b) {
7893
f('a',

pkg/analysis_server/test/src/services/correction/fix/convert_to_generic_function_syntax_test.dart

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,29 @@ g(String Function(int Function() h) f) {}
114114
}
115115

116116
@reflectiveTest
117-
class UseFunctionTypeSyntaxForParametersTest extends FixProcessorLintTest
118-
with WithNullSafetyLintMixin {
117+
class UseFunctionTypeSyntaxForParametersTest extends FixProcessorLintTest {
119118
@override
120119
FixKind get kind => DartFixKind.CONVERT_TO_GENERIC_FUNCTION_SYNTAX;
121120

122121
@override
123122
String get lintCode => LintNames.use_function_type_syntax_for_parameters;
124123

124+
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3212')
125+
Future<void> test_functionTypedParameter_fieldFormal() async {
126+
await resolveTestCode('''
127+
class C {
128+
String Function(int) f;
129+
C(String this.f(int x));
130+
}
131+
''');
132+
await assertHasFix('''
133+
class C {
134+
String Function(int) f;
135+
C(String Function(int x) this.f);
136+
}
137+
''');
138+
}
139+
125140
Future<void> test_functionTypedParameter_noParameterTypes() async {
126141
await resolveTestCode('''
127142
g(String f(x)) {}
@@ -153,6 +168,26 @@ g(String f(int x)) {}
153168
''');
154169
await assertHasFix('''
155170
g(String Function(int x) f) {}
171+
''');
172+
}
173+
174+
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3212')
175+
Future<void> test_functionTypedParameter_superParameter() async {
176+
await resolveTestCode('''
177+
class C {
178+
C(String Function(int x) f);
179+
}
180+
class D extends C {
181+
D(String super.f(int x));
182+
}
183+
''');
184+
await assertHasFix('''
185+
class C {
186+
C(String Function(int x) f);
187+
}
188+
class D extends C {
189+
D(String Function(int x) super.f);
190+
}
156191
''');
157192
}
158193
}

pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ abstract class FixProcessorLintTest extends FixProcessorTest {
236236
void setUp() {
237237
super.setUp();
238238
createAnalysisOptionsFile(
239+
experiments: experiments,
239240
lints: [lintCode],
240241
);
241242
}

pkg/analysis_server/test/src/services/correction/fix/remove_argument_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ void main() {
107107
''');
108108
}
109109

110-
@FailingTest(
111-
issue: 'https://github.com/dart-lang/linter/issues/3082',
112-
)
113110
Future<void> test_named_betweenRequiredPositional() async {
114111
await resolveTestCode('''
115112
void foo(int a, int b, {bool c = true}) {}

pkg/analysis_server/test/src/services/correction/fix/remove_initializer_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ void f([String? s]) {}
106106
''');
107107
}
108108

109+
Future<void> test_parameter_super() async {
110+
await resolveTestCode('''
111+
class C {
112+
C({String? s});
113+
}
114+
class D extends C {
115+
D({super.s = null});
116+
}
117+
''');
118+
await assertHasFix('''
119+
class C {
120+
C({String? s});
121+
}
122+
class D extends C {
123+
D({super.s});
124+
}
125+
''');
126+
}
127+
109128
Future<void> test_topLevel() async {
110129
await resolveTestCode('''
111130
var x = null;

pkg/analysis_server/test/src/services/correction/fix/remove_type_annotation_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class TypeInitFormalsTest extends RemoveTypeAnnotationTest {
231231
@override
232232
String get lintCode => LintNames.type_init_formals;
233233

234-
Future<void> test_void() async {
234+
Future<void> test_formalFieldParameter() async {
235235
await resolveTestCode('''
236236
class C {
237237
int f;
@@ -243,6 +243,25 @@ class C {
243243
int f;
244244
C(this.f);
245245
}
246+
''');
247+
}
248+
249+
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3210')
250+
Future<void> test_superParameter() async {
251+
// If this issue gets closed as "won't fix," remove this test.
252+
await resolveTestCode('''
253+
class C {
254+
C(int f);
255+
}
256+
class D extends C {
257+
D(int super.f);
258+
}
259+
''');
260+
await assertHasFix('''
261+
class C {
262+
int f;
263+
C(super.f);
264+
}
246265
''');
247266
}
248267
}

pkg/analysis_server/test/src/services/correction/fix/replace_colon_with_equals_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ void f({int a: 1}) => null;
5353
''');
5454
await assertHasFix('''
5555
void f({int a = 1}) => null;
56+
''');
57+
}
58+
59+
Future<void> test_superParameter() async {
60+
await resolveTestCode('''
61+
class C {
62+
C({int? i});
63+
}
64+
class D extends C {
65+
D({int? super.i: 1});
66+
}
67+
''');
68+
await assertHasFix('''
69+
class C {
70+
C({int? i});
71+
}
72+
class D extends C {
73+
D({int? super.i = 1});
74+
}
5675
''');
5776
}
5877
}

0 commit comments

Comments
 (0)