mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
Enable experiments for DAS tests, test rename and quick fixes for named arguments anywhere.
Change-Id: Ibc062c2a9e42e67673f9843bcae608befc8f93ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221986 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
bc8133c3fb
commit
3e826ca64b
|
@ -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<String> 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() {}
|
||||
|
|
|
@ -442,6 +442,35 @@ void f() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> 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<void> test_createChange_parameter_named_inOtherFile() async {
|
||||
var a = convertPath('/home/test/lib/a.dart');
|
||||
var b = convertPath('/home/test/lib/b.dart');
|
||||
|
|
|
@ -338,6 +338,28 @@ main() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> 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<void> test_multiple() async {
|
||||
await resolveTestCode('''
|
||||
test({required int a, required int bcd}) {}
|
||||
|
|
|
@ -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<String>? get experiments => null;
|
||||
@override
|
||||
List<String> get experiments => const [];
|
||||
|
||||
/// Return the lint code being tested.
|
||||
String? get lintCode => null;
|
||||
|
|
|
@ -90,7 +90,7 @@ class RemoveArgumentTest extends FixProcessorLintTest {
|
|||
@override
|
||||
String get lintCode => LintNames.avoid_redundant_argument_values;
|
||||
|
||||
Future<void> test_named_param() async {
|
||||
Future<void> test_named() async {
|
||||
await resolveTestCode('''
|
||||
void f({bool valWithDefault = true, bool? val}) {}
|
||||
|
||||
|
@ -107,7 +107,27 @@ void main() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_named_param_2() async {
|
||||
@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}) {}
|
||||
|
||||
void f() {
|
||||
foo(0, c: true, 1);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void foo(int a, int b, {bool c = true}) {}
|
||||
|
||||
void f() {
|
||||
foo(0, 1);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_named_hasOtherNamed() async {
|
||||
await resolveTestCode('''
|
||||
void f({bool valWithDefault = true, bool? val}) {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue