Skip to content

Commit c2ffa07

Browse files
scheglovCommit Queue
authored andcommitted
[CMSR] Tests for removing first / last named / positional formal parameter.
Change-Id: I4028f17b9244835beb60d955f12763ff9184afc4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310967 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent cc5b77a commit c2ffa07

File tree

1 file changed

+154
-2
lines changed

1 file changed

+154
-2
lines changed

pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart

Lines changed: 154 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,91 @@ ChangeStatusFailure
23252325
''');
23262326
}
23272327

2328-
Future<void> test_topFunction_requiredNamed_remove() async {
2328+
Future<void> test_topFunction_requiredNamed_remove_first() async {
2329+
await _analyzeValidSelection(r'''
2330+
void ^test({
2331+
required int a,
2332+
required int b,
2333+
required int c,
2334+
}) {}
2335+
2336+
void f() {
2337+
test(a: 0, b: 1, c: 2);
2338+
}
2339+
''');
2340+
2341+
final signatureUpdate = MethodSignatureUpdate(
2342+
formalParameters: [
2343+
FormalParameterUpdate(
2344+
id: 1,
2345+
kind: FormalParameterKind.requiredNamed,
2346+
),
2347+
FormalParameterUpdate(
2348+
id: 2,
2349+
kind: FormalParameterKind.requiredNamed,
2350+
),
2351+
],
2352+
removedNamedFormalParameters: {'a'},
2353+
formalParametersTrailingComma: TrailingComma.ifPresent,
2354+
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
2355+
);
2356+
2357+
await _assertUpdate(signatureUpdate, r'''
2358+
>>>>>>> /home/test/lib/test.dart
2359+
void test({
2360+
required int b,
2361+
required int c,
2362+
}) {}
2363+
2364+
void f() {
2365+
test(b: 1, c: 2);
2366+
}
2367+
''');
2368+
}
2369+
2370+
Future<void> test_topFunction_requiredNamed_remove_last() async {
2371+
await _analyzeValidSelection(r'''
2372+
void ^test({
2373+
required int a,
2374+
required int b,
2375+
required int c,
2376+
}) {}
2377+
2378+
void f() {
2379+
test(a: 0, b: 1, c: 2);
2380+
}
2381+
''');
2382+
2383+
final signatureUpdate = MethodSignatureUpdate(
2384+
formalParameters: [
2385+
FormalParameterUpdate(
2386+
id: 0,
2387+
kind: FormalParameterKind.requiredNamed,
2388+
),
2389+
FormalParameterUpdate(
2390+
id: 1,
2391+
kind: FormalParameterKind.requiredNamed,
2392+
),
2393+
],
2394+
removedNamedFormalParameters: {'c'},
2395+
formalParametersTrailingComma: TrailingComma.ifPresent,
2396+
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
2397+
);
2398+
2399+
await _assertUpdate(signatureUpdate, r'''
2400+
>>>>>>> /home/test/lib/test.dart
2401+
void test({
2402+
required int a,
2403+
required int b,
2404+
}) {}
2405+
2406+
void f() {
2407+
test(a: 0, b: 1);
2408+
}
2409+
''');
2410+
}
2411+
2412+
Future<void> test_topFunction_requiredNamed_remove_middle() async {
23292413
await _analyzeValidSelection(r'''
23302414
void ^test({
23312415
required int a,
@@ -2561,7 +2645,75 @@ void f() {
25612645
''');
25622646
}
25632647

2564-
Future<void> test_topFunction_requiredPositional_remove() async {
2648+
Future<void> test_topFunction_requiredPositional_remove_first() async {
2649+
await _analyzeValidSelection(r'''
2650+
void ^test(int a, int b, int c) {}
2651+
2652+
void f() {
2653+
test(0, 1, 2);
2654+
}
2655+
''');
2656+
2657+
final signatureUpdate = MethodSignatureUpdate(
2658+
formalParameters: [
2659+
FormalParameterUpdate(
2660+
id: 1,
2661+
kind: FormalParameterKind.requiredPositional,
2662+
),
2663+
FormalParameterUpdate(
2664+
id: 2,
2665+
kind: FormalParameterKind.requiredPositional,
2666+
),
2667+
],
2668+
formalParametersTrailingComma: TrailingComma.ifPresent,
2669+
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
2670+
);
2671+
2672+
await _assertUpdate(signatureUpdate, r'''
2673+
>>>>>>> /home/test/lib/test.dart
2674+
void test(int b, int c) {}
2675+
2676+
void f() {
2677+
test(1, 2);
2678+
}
2679+
''');
2680+
}
2681+
2682+
Future<void> test_topFunction_requiredPositional_remove_last() async {
2683+
await _analyzeValidSelection(r'''
2684+
void ^test(int a, int b, int c) {}
2685+
2686+
void f() {
2687+
test(0, 1, 2);
2688+
}
2689+
''');
2690+
2691+
final signatureUpdate = MethodSignatureUpdate(
2692+
formalParameters: [
2693+
FormalParameterUpdate(
2694+
id: 0,
2695+
kind: FormalParameterKind.requiredPositional,
2696+
),
2697+
FormalParameterUpdate(
2698+
id: 1,
2699+
kind: FormalParameterKind.requiredPositional,
2700+
),
2701+
],
2702+
formalParametersTrailingComma: TrailingComma.ifPresent,
2703+
argumentsTrailingComma: ArgumentsTrailingComma.ifPresent,
2704+
);
2705+
2706+
await _assertUpdate(signatureUpdate, r'''
2707+
>>>>>>> /home/test/lib/test.dart
2708+
void test(int a, int b) {}
2709+
2710+
void f() {
2711+
test(0, 1);
2712+
}
2713+
''');
2714+
}
2715+
2716+
Future<void> test_topFunction_requiredPositional_remove_middle() async {
25652717
await _analyzeValidSelection(r'''
25662718
void ^test(int a, int b, int c) {}
25672719

0 commit comments

Comments
 (0)