diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart index d727774ee8e..7b838561814 100644 --- a/pkg/analysis_server/test/abstract_context.dart +++ b/pkg/analysis_server/test/abstract_context.dart @@ -65,6 +65,13 @@ class AbstractContextTest with ResourceProviderMixin { throw 0; } + /// Return a list of the experiments that are to be enabled for tests in this + /// class, an empty list if there are no experiments that should be enabled. + List get experiments => [ + EnableString.constructor_tearoffs, + EnableString.named_arguments_anywhere, + ]; + String get latestLanguageVersion => '${ExperimentStatus.currentVersion.major}.' '${ExperimentStatus.currentVersion.minor}'; @@ -192,6 +199,10 @@ class AbstractContextTest with ResourceProviderMixin { ); writeTestPackageConfig(); + + createAnalysisOptionsFile( + experiments: experiments, + ); } void setupResourceProvider() {} diff --git a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart index 5c430326810..5650a38c262 100644 --- a/pkg/analysis_server/test/services/refactoring/rename_local_test.dart +++ b/pkg/analysis_server/test/services/refactoring/rename_local_test.dart @@ -442,6 +442,35 @@ void f() { '''); } + Future test_createChange_parameter_named_anywhere() async { + await indexTestUnit(''' +myFunction(int a, int b, {required int test}) { + test = 1; + test += 2; + print(test); +} +void f() { + myFunction(0, test: 2, 1); +} +'''); + // configure refactoring + createRenameRefactoringAtString('test}) {'); + expect(refactoring.refactoringName, 'Rename Parameter'); + expect(refactoring.elementKindName, 'parameter'); + refactoring.newName = 'newName'; + // validate change + return assertSuccessfulRefactoring(''' +myFunction(int a, int b, {required int newName}) { + newName = 1; + newName += 2; + print(newName); +} +void f() { + myFunction(0, newName: 2, 1); +} +'''); + } + Future test_createChange_parameter_named_inOtherFile() async { var a = convertPath('/home/test/lib/a.dart'); var b = convertPath('/home/test/lib/b.dart'); diff --git a/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart b/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart index dc08b797e74..9cb60e670a0 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart @@ -338,6 +338,28 @@ main() { '''); } + Future test_constructor_single_namedAnywhere() async { + addSource('/home/test/lib/a.dart', r''' +class A { + A(int a, int b, {int? c, required int d}) {} +} +'''); + await resolveTestCode(''' +import 'package:test/a.dart'; + +void f() { + A(0, c: 1, 2); +} +'''); + await assertHasFix(''' +import 'package:test/a.dart'; + +void f() { + A(0, c: 1, 2, d: null); +} +'''); + } + Future test_multiple() async { await resolveTestCode(''' test({required int a, required int bcd}) {} diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart index 44650b08744..50411cbdf2b 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart @@ -90,9 +90,8 @@ abstract class BulkFixProcessorTest extends AbstractSingleUnitTest { /// The processor used to compute bulk fixes. late BulkFixProcessor processor; - /// Return a list of the experiments that are to be enabled for tests in this - /// class, or `null` if there are no experiments that should be enabled. - List? get experiments => null; + @override + List get experiments => const []; /// Return the lint code being tested. String? get lintCode => null; diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_argument_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_argument_test.dart index 2bfbc3e97f0..9d279447399 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_argument_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_argument_test.dart @@ -90,7 +90,7 @@ class RemoveArgumentTest extends FixProcessorLintTest { @override String get lintCode => LintNames.avoid_redundant_argument_values; - Future test_named_param() async { + Future test_named() async { await resolveTestCode(''' void f({bool valWithDefault = true, bool? val}) {} @@ -107,7 +107,27 @@ void main() { '''); } - Future test_named_param_2() async { + @FailingTest( + issue: 'https://github.com/dart-lang/linter/issues/3082', + ) + Future test_named_betweenRequiredPositional() async { + await resolveTestCode(''' +void foo(int a, int b, {bool c = true}) {} + +void f() { + foo(0, c: true, 1); +} +'''); + await assertHasFix(''' +void foo(int a, int b, {bool c = true}) {} + +void f() { + foo(0, 1); +} +'''); + } + + Future test_named_hasOtherNamed() async { await resolveTestCode(''' void f({bool valWithDefault = true, bool? val}) {}