Skip to content

Commit 928b520

Browse files
test: annotation calls and named types referencing declarations in other files (#587)
Closes partially #540 ### Summary of Changes Add tests to ensure that annotation calls and named types can reference declarations in other files. No changes to the implementation of the scope provider were needed. --------- Co-authored-by: megalinter-bot <[email protected]>
1 parent 6b30de5 commit 928b520

File tree

51 files changed

+489
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+489
-20
lines changed

src/language/scoping/safe-ds-scope-provider.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,18 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
132132
}
133133

134134
private getScopeForMemberAccessMember(node: SdsMemberAccess): Scope {
135-
let currentScope = EMPTY_SCOPE;
136-
137135
// Static access
138136
const declaration = this.getUniqueReferencedDeclarationForExpression(node.receiver);
139137
if (isSdsClass(declaration)) {
140-
currentScope = this.createScopeForNodes(classMembersOrEmpty(declaration, isStatic));
138+
return this.createScopeForNodes(classMembersOrEmpty(declaration, isStatic));
141139

142140
// val superTypeMembers = receiverDeclaration.superClassMembers()
143141
// .filter { it.isStatic() }
144142
// .toList()
145143
//
146144
// return Scopes.scopeFor(members, Scopes.scopeFor(superTypeMembers))
147145
} else if (isSdsEnum(declaration)) {
148-
currentScope = this.createScopeForNodes(enumVariantsOrEmpty(declaration));
146+
return this.createScopeForNodes(enumVariantsOrEmpty(declaration));
149147
}
150148

151149
// // Call results
@@ -176,7 +174,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
176174
// else -> resultScope
177175
// }
178176

179-
return currentScope;
177+
return EMPTY_SCOPE;
180178
}
181179

182180
/**

tests/language/formatting/creator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Diagnostic } from 'vscode-languageserver-types';
55
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
66
import { EmptyFileSystem } from 'langium';
77
import { getSyntaxErrors } from '../../helpers/diagnostics.js';
8+
import { clearDocuments } from 'langium/test';
89

910
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
1011
const root = 'formatting';
@@ -29,12 +30,14 @@ const createFormattingTest = async (relativeResourcePath: string): Promise<Forma
2930
const expectedFormattedCode = normalizeLineBreaks(parts[1]).trim();
3031

3132
// Original code must not contain syntax errors
33+
await clearDocuments(services);
3234
const syntaxErrorsInOriginalCode = await getSyntaxErrors(services, originalCode);
3335
if (syntaxErrorsInOriginalCode.length > 0) {
3436
return invalidTest(relativeResourcePath, new SyntaxErrorsInOriginalCodeError(syntaxErrorsInOriginalCode));
3537
}
3638

3739
// Expected formatted code must not contain syntax errors
40+
await clearDocuments(services);
3841
const syntaxErrorsInExpectedFormattedCode = await getSyntaxErrors(services, expectedFormattedCode);
3942
if (syntaxErrorsInExpectedFormattedCode.length > 0) {
4043
return invalidTest(

tests/language/partialEvaluation/creator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { URI } from 'vscode-uri';
1010
import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../helpers/diagnostics.js';
1111
import { EmptyFileSystem } from 'langium';
1212
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
13+
import { clearDocuments } from 'langium/test';
1314

1415
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
1516
const root = 'partial evaluation';
@@ -40,6 +41,7 @@ const createPartialEvaluationTest = async (
4041
const code = fs.readFileSync(absolutePath).toString();
4142

4243
// File must not contain any syntax errors
44+
await clearDocuments(services);
4345
const syntaxErrors = await getSyntaxErrors(services, code);
4446
if (syntaxErrors.length > 0) {
4547
return invalidTest(

tests/language/scoping/creator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const createScopingTest = async (
4040
const code = fs.readFileSync(absolutePath).toString();
4141

4242
// File must not contain any syntax errors
43+
await clearDocuments(services);
4344
const syntaxErrors = await getSyntaxErrors(services, code);
4445
if (syntaxErrors.length > 0) {
4546
return invalidTest(
4647
`INVALID TEST FILE [${relativeResourcePath}]`,
4748
new SyntaxErrorsInCodeError(syntaxErrors),
4849
);
4950
}
50-
await clearDocuments(services);
5151

5252
const checksResult = findTestChecks(code, uri, { failIfFewerRangesThanComments: true });
5353

tests/language/typing/creator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { URI } from 'vscode-uri';
1010
import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../helpers/diagnostics.js';
1111
import { EmptyFileSystem } from 'langium';
1212
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
13+
import { clearDocuments } from 'langium/test';
1314

1415
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
1516
const root = 'typing';
@@ -39,6 +40,7 @@ const createTypingTest = async (
3940
const code = fs.readFileSync(absolutePath).toString();
4041

4142
// File must not contain any syntax errors
43+
await clearDocuments(services);
4244
const syntaxErrors = await getSyntaxErrors(services, code);
4345
if (syntaxErrors.length > 0) {
4446
return invalidTest(

tests/language/validation/creator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../helpers/diagnost
1010
import { EmptyFileSystem } from 'langium';
1111
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
1212
import { DocumentUri, Range } from 'vscode-languageserver-types';
13+
import { clearDocuments } from 'langium/test';
1314

1415
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
1516
const root = 'validation';
@@ -38,6 +39,7 @@ const createValidationTest = async (
3839
const code = fs.readFileSync(absolutePath).toString();
3940

4041
// File must not contain any syntax errors
42+
await clearDocuments(services);
4143
const syntaxErrors = await getSyntaxErrors(services, code);
4244
if (syntaxErrors.length > 0) {
4345
return invalidTest(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package tests.scoping.annotationCalls.acrossFiles
2+
3+
// $TEST$ references same_MyAnnotation
4+
@»MyAnnotation«
5+
6+
// $TEST$ references same_AnnotationInSamePackage
7+
@»AnnotationInSamePackage«
8+
9+
// $TEST$ references safeds_AnnotationInSafeDsPackage
10+
@»AnnotationInSafeDsPackage«
11+
12+
// $TEST$ unresolved
13+
@»AnnotationInAnotherPackage«
14+
15+
// $TEST$ unresolved
16+
@»AnnotationWithoutPackage«
17+
pipeline myPipeline {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tests.scoping.annotationCalls.acrossFiles
2+
3+
import safeds.scoping.annotationCalls.acrossFiles.MyAnnotation as MyOwnAnnotation
4+
import tests.scoping.annotationCalls.acrossFiles.other.AnnotationInAnotherPackage
5+
6+
// $TEST$ target own_MyOwnAnnotation
7+
annotation »MyOwnAnnotation«
8+
9+
// $TEST$ references own_MyOwnAnnotation
10+
@»MyOwnAnnotation«
11+
12+
// $TEST$ references same_AnnotationInSamePackage
13+
@»AnnotationInSamePackage«
14+
15+
// $TEST$ references safeds_AnnotationInSafeDsPackage
16+
@»AnnotationInSafeDsPackage«
17+
18+
// $TEST$ references other_AnnotationInAnotherPackage
19+
@»AnnotationInAnotherPackage«
20+
21+
// $TEST$ unresolved
22+
@»AnnotationWithoutPackage«
23+
pipeline myPipeline {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package tests.scoping.annotationCalls.acrossFiles
2+
3+
import safeds.scoping.annotationCalls.acrossFiles.MyAnnotation
4+
import tests.scoping.annotationCalls.acrossFiles.other.MyAnnotation
5+
import tests.scoping.annotationCalls.acrossFiles.MyAnnotation
6+
7+
pipeline myPipeline {
8+
// $TEST$ references safeds_MyAnnotation
9+
»MyAnnotation«;
10+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tests.scoping.annotationCalls.acrossFiles
2+
3+
import tests.scoping.annotationCalls.acrossFiles.MyAnnotation as MyAnnotationInSamePackage
4+
import safeds.scoping.annotationCalls.acrossFiles.MyAnnotation as MyAnnotationInSafeDsPackage
5+
import tests.scoping.annotationCalls.acrossFiles.other.MyAnnotation as MyAnnotationInAnotherPackage
6+
7+
// $TEST$ references same_MyAnnotation
8+
@»MyAnnotation«
9+
10+
11+
// $TEST$ references same_AnnotationInSamePackage
12+
@»AnnotationInSamePackage«
13+
14+
// $TEST$ references safeds_AnnotationInSafeDsPackage
15+
@»AnnotationInSafeDsPackage«
16+
17+
// $TEST$ unresolved
18+
@»AnnotationInAnotherPackage«
19+
20+
// $TEST$ unresolved
21+
@»AnnotationWithoutPackage«
22+
23+
// $TEST$ references same_MyAnnotation
24+
@»MyAnnotationInSamePackage«
25+
26+
// $TEST$ references safeds_MyAnnotation
27+
@»MyAnnotationInSafeDsPackage«
28+
29+
// $TEST$ references other_MyAnnotation
30+
@»MyAnnotationInAnotherPackage«
31+
pipeline myPipeline {}

0 commit comments

Comments
 (0)