mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:29:47 +00:00
[CMSR] Tests for TrailingComma, support for required positional formal parameters.
Change-Id: I1e477782895a053ff2060dada8fe834bd2c2c8db Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310977 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
b892ccdb19
commit
ecc18c9600
|
@ -182,8 +182,6 @@ class MethodSignatureUpdate {
|
|||
final Set<String> removedNamedFormalParameters;
|
||||
|
||||
/// Specifies whether to add the trailing comma after formal parameters.
|
||||
///
|
||||
/// TODO(scheglov) Test for empty formal parameter lists.
|
||||
final TrailingComma formalParametersTrailingComma;
|
||||
|
||||
/// Specifies whether to add the trailing comma after arguments.
|
||||
|
@ -898,6 +896,16 @@ class _SignatureUpdater {
|
|||
hasParameterWritten = true;
|
||||
}
|
||||
|
||||
// Maybe write the trailing comma.
|
||||
if (requiredPositionalWrites.isNotEmpty &&
|
||||
optionalPositionalWrites.isEmpty &&
|
||||
namedWrites.isEmpty) {
|
||||
writeFormalParametersTrailingComma(
|
||||
formalParameterList: formalParameterList,
|
||||
builder: builder,
|
||||
);
|
||||
}
|
||||
|
||||
// Write optional positional parameters.
|
||||
writeOptionalParameters(
|
||||
parameters: optionalPositionalWrites,
|
||||
|
|
|
@ -1599,6 +1599,186 @@ ChangeStatusFailure
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredNamed_always_add() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({required int a, required int b}) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.always,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test({
|
||||
required int b,
|
||||
required int a,
|
||||
}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredNamed_ifPresent_false() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({required int a, required int b}) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.ifPresent,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test({required int b, required int a}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredNamed_ifPresent_true() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({
|
||||
required int a,
|
||||
required int b,
|
||||
}) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.ifPresent,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test({
|
||||
required int b,
|
||||
required int a,
|
||||
}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredNamed_never_remove() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({
|
||||
required int b,
|
||||
required int a,
|
||||
}) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredNamed,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.never,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test({required int a, required int b}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredPositional_always_add() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test(int a, int b) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredPositional,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredPositional,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.always,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test(
|
||||
int b,
|
||||
int a,
|
||||
) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void>
|
||||
test_formalParametersTrailingComma_requiredPositional_never_remove() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test(
|
||||
int a,
|
||||
int b,
|
||||
) {}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [
|
||||
FormalParameterUpdate(
|
||||
id: 1,
|
||||
kind: FormalParameterKind.requiredPositional,
|
||||
),
|
||||
FormalParameterUpdate(
|
||||
id: 0,
|
||||
kind: FormalParameterKind.requiredPositional,
|
||||
),
|
||||
],
|
||||
formalParametersTrailingComma: TrailingComma.never,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test(int b, int a) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topFunction_fail_noSuchId_greater() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test(int a) {}
|
||||
|
@ -2326,6 +2506,34 @@ ChangeStatusFailure
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topFunction_requiredNamed_remove_all() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({
|
||||
required int a,
|
||||
}) {}
|
||||
|
||||
void f() {
|
||||
test(a: 0);
|
||||
}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [],
|
||||
removedNamedFormalParameters: {'a'},
|
||||
formalParametersTrailingComma: TrailingComma.always,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.always,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test() {}
|
||||
|
||||
void f() {
|
||||
test();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topFunction_requiredNamed_remove_first() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test({
|
||||
|
@ -2646,6 +2854,31 @@ void f() {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topFunction_requiredPositional_remove_all() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test(int a) {}
|
||||
|
||||
void f() {
|
||||
test(0);
|
||||
}
|
||||
''');
|
||||
|
||||
final signatureUpdate = MethodSignatureUpdate(
|
||||
formalParameters: [],
|
||||
formalParametersTrailingComma: TrailingComma.always,
|
||||
argumentsTrailingComma: ArgumentsTrailingComma.always,
|
||||
);
|
||||
|
||||
await _assertUpdate(signatureUpdate, r'''
|
||||
>>>>>>> /home/test/lib/test.dart
|
||||
void test() {}
|
||||
|
||||
void f() {
|
||||
test();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topFunction_requiredPositional_remove_first() async {
|
||||
await _analyzeValidSelection(r'''
|
||||
void ^test(int a, int b, int c) {}
|
||||
|
|
Loading…
Reference in a new issue