Skip to content

Commit ed7375d

Browse files
committed
test: cover missing cases
1 parent 23e5c24 commit ed7375d

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

packages/safe-ds-lang/src/language/codeActions/quickfixes/arguments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const makeArgumentsAssignedToOptionalParametersNamed = (services: SafeDsS
1414
return (diagnostic: Diagnostic, document: LangiumDocument, acceptor: CodeActionAcceptor) => {
1515
const node = locator.getAstNode(document.parseResult.value, diagnostic.data.path);
1616
if (!isSdsArgumentList(node)) {
17+
/* c8 ignore next 2 */
1718
return;
1819
}
1920

@@ -31,7 +32,6 @@ export const makeArgumentsAssignedToOptionalParametersNamed = (services: SafeDsS
3132

3233
const ensureArgumentIsNamed = (nodeMapper: SafeDsNodeMapper, argument: SdsArgument): TextEdit[] | TextEdit => {
3334
const cstNode = argument.$cstNode;
34-
3535
if (!cstNode || Argument.isNamed(argument)) {
3636
return [];
3737
}

packages/safe-ds-lang/src/language/codeActions/quickfixes/safe-ds-quickfix-provider.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@ export class SafeDsQuickfixProvider {
1616

1717
createQuickfixes(diagnostic: Diagnostic, document: LangiumDocument, acceptor: CodeActionAcceptor) {
1818
if (!diagnostic.code) {
19+
/* c8 ignore next 2 */
1920
return;
2021
}
2122

22-
const quickfixes = this.registry[diagnostic.code];
23-
24-
if (Array.isArray(quickfixes)) {
25-
for (const quickfix of quickfixes) {
26-
quickfix(diagnostic, document, acceptor);
27-
}
28-
} else if (quickfixes) {
29-
quickfixes(diagnostic, document, acceptor);
23+
const quickfixes = this.registry[diagnostic.code] ?? [];
24+
for (const quickfix of quickfixes) {
25+
quickfix(diagnostic, document, acceptor);
3026
}
3127
}
3228
}
3329

3430
type QuickfixRegistry = {
35-
[code: string | number]: QuickfixCreator | QuickfixCreator[];
31+
[code: string | number]: QuickfixCreator[];
3632
};
3733

3834
type QuickfixCreator = (diagnostic: Diagnostic, document: LangiumDocument, acceptor: CodeActionAcceptor) => void;

packages/safe-ds-lang/tests/resources/code actions/quickfixes/make arguments assigned to optional parameters named/skip-output/input.sdsdev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fun myFunction(required: Int, optional1: Int = 0, optional2: Int = 0)
1010

1111
@MyAnnotation(1, optional1 = 2, optional2 = 3, 4)
1212

13-
@MyAnnotation(1, 2, optional2 = 3)
13+
@MyAnnotation(1, optional1 = 2, optional2 = 3)
1414
pipeline testPipeline {
1515
myFunction(1, optional1 = 2, optional2 = 3, 4);
1616

17-
myFunction(1, 2, optional2 = 3);
17+
myFunction(1, optional1 = 2, optional2 = 3);
1818
}

packages/safe-ds-lang/tests/resources/validation/other/expressions/arguments/must be named if parameter is optional/annotation calls.sdsdev

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ annotation MyAnnotation(required: Int, optional1: Int = 0, optional2: Int = 0)
1212
// $TEST$ no error "Argument must be named if the parameter is optional."
1313
@MyAnnotation(»1«, »2«, »3«, »4«)
1414
// $TEST$ no error "Argument must be named if the parameter is optional."
15+
// $TEST$ error "Argument must be named if the parameter is optional."
16+
// $TEST$ no error "Argument must be named if the parameter is optional."
17+
@MyAnnotation(»1«, »2«, »optional2 = 3«)
18+
// $TEST$ no error "Argument must be named if the parameter is optional."
1519
// $TEST$ no error "Argument must be named if the parameter is optional."
1620
@MyAnnotation(»required = 1«, »optional1 = 2«)
1721

packages/safe-ds-lang/tests/resources/validation/other/expressions/arguments/must be named if parameter is optional/calls.sdsdev

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pipeline testPipeline {
1212
// $TEST$ no error "Argument must be named if the parameter is optional."
1313
myFunction(»1«, »2«, »3«, »4«);
1414
// $TEST$ no error "Argument must be named if the parameter is optional."
15+
// $TEST$ error "Argument must be named if the parameter is optional."
16+
// $TEST$ no error "Argument must be named if the parameter is optional."
17+
myFunction(»1«, »2«, »optional2 = 3«);
18+
// $TEST$ no error "Argument must be named if the parameter is optional."
1519
// $TEST$ no error "Argument must be named if the parameter is optional."
1620
myFunction(»required = 1«, »optional1 = 2«);
1721

0 commit comments

Comments
 (0)