diff --git a/src/cli/generator.ts b/src/cli/generator.ts index c1de486d2..b6a5849f4 100644 --- a/src/cli/generator.ts +++ b/src/cli/generator.ts @@ -1,41 +1,604 @@ import fs from 'fs'; -import { CompositeGeneratorNode, toString } from 'langium'; +import { + expandToString, + expandToStringWithNL, + findRootNode, + getContainerOfType, + getDocument, + streamAllContents, +} from 'langium'; import path from 'path'; -import { SdsModule } from '../language/generated/ast.js'; +import { + isSdsAbstractResult, + isSdsAssignment, + isSdsBlockLambda, + isSdsBlockLambdaResult, + isSdsCall, + isSdsCallable, + isSdsEnumVariant, + isSdsExpressionLambda, + isSdsExpressionStatement, + isSdsIndexedAccess, + isSdsInfixOperation, + isSdsList, + isSdsMap, + isSdsMemberAccess, + isSdsParenthesizedExpression, + isSdsPipeline, + isSdsPlaceholder, + isSdsPrefixOperation, + isSdsQualifiedImport, + isSdsReference, + isSdsSegment, + isSdsTemplateString, + isSdsTemplateStringEnd, + isSdsTemplateStringInner, + isSdsTemplateStringPart, + isSdsTemplateStringStart, + isSdsWildcard, + isSdsWildcardImport, + isSdsYield, + SdsArgument, + SdsAssignee, + SdsAssignment, + SdsBlock, + SdsBlockLambda, + SdsDeclaration, + SdsExpression, + SdsModule, + SdsParameter, + SdsParameterList, + SdsPipeline, + SdsSegment, + SdsStatement, +} from '../language/generated/ast.js'; import { extractAstNode, extractDestinationAndName } from './cli-util.js'; import chalk from 'chalk'; -import { createSafeDsServices } from '../language/safe-ds-module.js'; +import { createSafeDsServices, SafeDsServices } from '../language/safe-ds-module.js'; import { NodeFileSystem } from 'langium/node'; +import { + abstractResultsOrEmpty, + assigneesOrEmpty, + blockLambdaResultsOrEmpty, + importedDeclarationsOrEmpty, + importsOrEmpty, + isRequiredParameter, + moduleMembersOrEmpty, + statementsOrEmpty, +} from '../language/helpers/nodeProperties.js'; +import { group } from 'radash'; +import { IdManager } from '../language/helpers/idManager.js'; +import { isInStubFile } from '../language/helpers/fileExtensions.js'; +import { + BooleanConstant, + FloatConstant, + IntConstant, + NullConstant, + StringConstant, +} from '../language/partialEvaluation/model.js'; + +export const CODEGEN_PREFIX = '__gen_'; +const BLOCK_LAMBDA_PREFIX = `${CODEGEN_PREFIX}block_lambda_`; +const BLOCK_LAMBDA_RESULT_PREFIX = `${CODEGEN_PREFIX}block_lambda_result_`; +const YIELD_PREFIX = `${CODEGEN_PREFIX}yield_`; + +const RUNNER_CODEGEN_PACKAGE = 'safeds_runner.codegen'; +const PYTHON_INDENT = ' '; /* c8 ignore start */ export const generateAction = async (fileName: string, opts: GenerateOptions): Promise => { const services = createSafeDsServices(NodeFileSystem).SafeDs; const module = await extractAstNode(fileName, services); - const generatedFilePath = generatePython(module, fileName, opts.destination); + const generatedFilePath = generatePython(services, module, fileName, opts.destination); // eslint-disable-next-line no-console console.log(chalk.green(`Python code generated successfully: ${generatedFilePath}`)); }; /* c8 ignore stop */ -export type GenerateOptions = { - destination?: string; -}; - export const generatePython = function ( + services: SafeDsServices, module: SdsModule, filePath: string, destination: string | undefined, ): string[] { + // Do not generate stub files + if (isInStubFile(module)) { + return []; + } const data = extractDestinationAndName(filePath, destination); - const generatedFilePath = `${path.join(data.destination, data.name)}.py`; + const pythonModuleName = services.builtins.Annotations.getPythonModule(module); + const packagePath = pythonModuleName === undefined ? module.name.split('.') : [pythonModuleName]; + const parentDirectoryPath = path.join(data.destination, ...packagePath); + + const generatedFiles = new Map(); + generatedFiles.set( + `${path.join(parentDirectoryPath, formatGeneratedFileName(data.name))}.py`, + generateModule(services, module), + ); + for (const pipeline of streamAllContents(module).filter(isSdsPipeline)) { + const entryPointFilename = `${path.join( + parentDirectoryPath, + `${formatGeneratedFileName(data.name)}_${getPythonNameOrDefault(services, pipeline)}`, + )}.py`; + const entryPointContent = expandToStringWithNL`from ${formatGeneratedFileName( + data.name, + )} import ${getPythonNameOrDefault( + services, + pipeline, + )}\n\nif __name__ == '__main__':\n${PYTHON_INDENT}${getPythonNameOrDefault(services, pipeline)}()`; + generatedFiles.set(entryPointFilename, entryPointContent); + } + if (!fs.existsSync(parentDirectoryPath)) { + fs.mkdirSync(parentDirectoryPath, { recursive: true }); + } + for (const [generatedFilePath, generatedFileContent] of generatedFiles.entries()) { + fs.writeFileSync(generatedFilePath, generatedFileContent); + } + return [...generatedFiles.keys()]; +}; + +const getPythonNameOrDefault = function ( + services: SafeDsServices, + object: SdsPipeline | SdsSegment | SdsParameter | SdsDeclaration, +) { + return services.builtins.Annotations.getPythonName(object) || object.name; +}; + +const formatGeneratedFileName = function (baseName: string): string { + return `gen_${baseName.replaceAll('%2520', '_').replaceAll(/[ .-]/gu, '_').replaceAll(/\\W/gu, '')}`; +}; + +const generateModule = function (services: SafeDsServices, module: SdsModule): string { + const importSet = new Map(); + const segments = moduleMembersOrEmpty(module) + .filter(isSdsSegment) + .map((segment) => generateSegment(services, segment, importSet)); + const pipelines = moduleMembersOrEmpty(module) + .filter(isSdsPipeline) + .map((pipeline) => generatePipeline(services, pipeline, importSet)); + const imports = generateImports(Array.from(importSet.values())); + const output: string[] = []; + if (imports.length > 0) { + output.push( + expandToStringWithNL`# Imports ----------------------------------------------------------------------\n\n${imports.join( + '\n', + )}`, + ); + } + if (segments.length > 0) { + output.push( + expandToStringWithNL`# Steps ------------------------------------------------------------------------\n\n${segments.join( + '\n\n', + )}`, + ); + } + if (pipelines.length > 0) { + output.push( + expandToStringWithNL`# Pipelines --------------------------------------------------------------------\n\n${pipelines.join( + '\n\n', + )}`, + ); + } + return expandToStringWithNL`${output.join('\n')}`; +}; + +const generateSegment = function ( + services: SafeDsServices, + segment: SdsSegment, + importSet: Map, +): string { + const infoFrame = new GenerationInfoFrame(services, importSet); + const segmentResult = segment.resultList?.results || []; + let segmentBlock = generateBlock(segment.body, infoFrame); + if (segmentResult.length !== 0) { + segmentBlock += `\nreturn ${segmentResult.map((result) => `${YIELD_PREFIX}${result.name}`).join(', ')}`; + } + return expandToString`def ${getPythonNameOrDefault(services, segment)}(${generateParameters( + segment.parameterList, + infoFrame, + )}):\n${PYTHON_INDENT}${segmentBlock}`; +}; + +const generateParameters = function (parameters: SdsParameterList | undefined, frame: GenerationInfoFrame): string { + const result = (parameters?.parameters || []).map((param) => generateParameter(param, frame)); + return result.join(', '); +}; + +const generateParameter = function ( + parameter: SdsParameter, + frame: GenerationInfoFrame, + defaultValue: boolean = true, +): string { + return expandToString`${getPythonNameOrDefault(frame.getServices(), parameter)}${ + defaultValue && parameter.defaultValue !== undefined + ? '=' + generateExpression(parameter.defaultValue, frame) + : '' + }`; +}; + +const generatePipeline = function ( + services: SafeDsServices, + pipeline: SdsPipeline, + importSet: Map, +): string { + const infoFrame = new GenerationInfoFrame(services, importSet); + return expandToString`def ${getPythonNameOrDefault(services, pipeline)}():\n${PYTHON_INDENT}${generateBlock( + pipeline.body, + infoFrame, + )}`; +}; + +const generateImports = function (importSet: ImportData[]): string[] { + const qualifiedImports = Array.from(importSet) + .filter((importStmt) => importStmt.declarationName === undefined) + .sort((a, b) => a.importPath.localeCompare(b.importPath)) + .map(generateQualifiedImport); + const groupedImports = Object.entries( + group( + Array.from(importSet).filter((importStmt) => importStmt.declarationName !== undefined), + (importStmt) => importStmt.importPath, + ), + ).sort(([key1, _value1], [key2, _value2]) => key1.localeCompare(key2)); + const declaredImports: string[] = []; + for (const [key, value] of groupedImports) { + const importedDecls = + value + ?.filter((importData) => importData !== undefined) + .sort((a, b) => a.declarationName!.localeCompare(b.declarationName!)) + .map((localValue) => + localValue.alias !== undefined + ? `${localValue.declarationName} as ${localValue.alias}` + : localValue.declarationName!, + ) || []; + declaredImports.push(`from ${key} import ${[...new Set(importedDecls)].join(', ')}`); + } + return [...new Set(qualifiedImports), ...new Set(declaredImports)]; +}; + +const generateQualifiedImport = function (importStmt: ImportData): string { + if (importStmt.alias === undefined) { + return `import ${importStmt.importPath}`; + } else { + /* c8 ignore next 2 */ + return `import ${importStmt.importPath} as ${importStmt.alias}`; + } +}; + +const generateBlock = function (block: SdsBlock, frame: GenerationInfoFrame): string { + // TODO filter withEffect + let statements = statementsOrEmpty(block); + if (statements.length === 0) { + return 'pass'; + } + return expandToString`${statements.map((stmt) => generateStatement(stmt, frame)).join('\n')}`; +}; + +const generateStatement = function (statement: SdsStatement, frame: GenerationInfoFrame): string { + if (isSdsAssignment(statement)) { + return generateAssignment(statement, frame); + } else if (isSdsExpressionStatement(statement)) { + const expressionStatement = statement; + const blockLambdaCode: string[] = []; + for (const lambda of streamAllContents(expressionStatement.expression).filter(isSdsBlockLambda)) { + blockLambdaCode.push(generateBlockLambda(lambda, frame)); + } + blockLambdaCode.push(generateExpression(expressionStatement.expression, frame)); + return expandToString`${blockLambdaCode.join('\n')}`; + } + /* c8 ignore next 2 */ + throw new Error(`Unknown SdsStatement: ${statement}`); +}; + +const generateAssignment = function (assignment: SdsAssignment, frame: GenerationInfoFrame): string { + const requiredAssignees = isSdsCall(assignment.expression) + ? abstractResultsOrEmpty( + frame.getServices().helpers.NodeMapper.callToCallableOrUndefined(assignment.expression), + ).length + : /* c8 ignore next */ + 1; + const assignees = assigneesOrEmpty(assignment); + if (assignees.some((value) => !isSdsWildcard(value))) { + const actualAssignees = assignees.map(generateAssignee); + if (requiredAssignees === actualAssignees.length) { + return `${actualAssignees.join(', ')} = ${generateExpression(assignment.expression!, frame)}`; + } else { + // Add wildcards to match given results + return `${actualAssignees + .concat(Array(requiredAssignees - actualAssignees.length).fill('_')) + .join(', ')} = ${generateExpression(assignment.expression!, frame)}`; + } + } else { + return generateExpression(assignment.expression!, frame); + } +}; + +const generateAssignee = function (assignee: SdsAssignee): string { + if (isSdsBlockLambdaResult(assignee)) { + return `${BLOCK_LAMBDA_RESULT_PREFIX}${assignee.name}`; + } else if (isSdsPlaceholder(assignee)) { + return assignee.name; + } else if (isSdsWildcard(assignee)) { + return '_'; + } else if (isSdsYield(assignee)) { + return `${YIELD_PREFIX}${assignee.result?.ref?.name!}`; + } + /* c8 ignore next 2 */ + throw new Error(`Unknown SdsAssignment: ${assignee.$type}`); +}; + +const generateBlockLambda = function (blockLambda: SdsBlockLambda, frame: GenerationInfoFrame): string { + const lambdaResult = blockLambdaResultsOrEmpty(blockLambda); + let lambdaBlock = generateBlock(blockLambda.body, frame); + if (lambdaResult.length !== 0 && lambdaBlock !== 'pass') { + lambdaBlock += `\nreturn ${lambdaResult + .map((result) => `${BLOCK_LAMBDA_RESULT_PREFIX}${result.name}`) + .join(', ')}`; + } + return expandToString`def ${frame.getUniqueLambdaBlockName(blockLambda)}(${generateParameters( + blockLambda.parameterList, + frame, + )}):\n${PYTHON_INDENT}${lambdaBlock}`; +}; + +const generateExpression = function (expression: SdsExpression, frame: GenerationInfoFrame): string { + if (isSdsTemplateStringPart(expression)) { + if (isSdsTemplateStringStart(expression)) { + return `${formatStringSingleLine(expression.value)}{ `; + } else if (isSdsTemplateStringInner(expression)) { + return ` }${formatStringSingleLine(expression.value)}{ `; + } else if (isSdsTemplateStringEnd(expression)) { + return ` }${formatStringSingleLine(expression.value)}`; + } + } + + const partiallyEvaluatedNode = frame.getServices().evaluation.PartialEvaluator.evaluate(expression); + if (partiallyEvaluatedNode instanceof BooleanConstant) { + return partiallyEvaluatedNode.value ? 'True' : 'False'; + } else if (partiallyEvaluatedNode instanceof IntConstant) { + return String(partiallyEvaluatedNode.value); + } else if (partiallyEvaluatedNode instanceof FloatConstant) { + const floatValue = partiallyEvaluatedNode.value; + return Number.isInteger(floatValue) ? `${floatValue}.0` : String(floatValue); + } else if (partiallyEvaluatedNode === NullConstant) { + return 'None'; + } else if (partiallyEvaluatedNode instanceof StringConstant) { + return `'${formatStringSingleLine(partiallyEvaluatedNode.value)}'`; + } + // Handled after constant expressions: EnumVariant, List, Map + + if (isSdsTemplateString(expression)) { + return `f'${expression.expressions.map((expr) => generateExpression(expr, frame)).join('')}'`; + } + + if (isSdsMap(expression)) { + const mapContent = expression.entries.map( + (entry) => `${generateExpression(entry.key, frame)}: ${generateExpression(entry.value, frame)}`, + ); + return `{${mapContent.join(', ')}}`; + } + if (isSdsList(expression)) { + const listContent = expression.elements.map((value) => generateExpression(value, frame)); + return `[${listContent.join(', ')}]`; + } + + if (isSdsBlockLambda(expression)) { + return frame.getUniqueLambdaBlockName(expression); + } + if (isSdsCall(expression)) { + const sortedArgs = sortArguments(frame.getServices(), expression.argumentList.arguments); + return expandToString`${generateExpression(expression.receiver, frame)}(${sortedArgs + .map((arg) => generateArgument(arg, frame)) + .join(', ')})`; + } + if (isSdsExpressionLambda(expression)) { + return `lambda ${generateParameters(expression.parameterList, frame)}: ${generateExpression( + expression.result, + frame, + )}`; + } + if (isSdsInfixOperation(expression)) { + const leftOperand = generateExpression(expression.leftOperand, frame); + const rightOperand = generateExpression(expression.rightOperand, frame); + switch (expression.operator) { + case 'or': + frame.addImport({ importPath: RUNNER_CODEGEN_PACKAGE }); + return `${RUNNER_CODEGEN_PACKAGE}.eager_or(${leftOperand}, ${rightOperand})`; + case 'and': + frame.addImport({ importPath: RUNNER_CODEGEN_PACKAGE }); + return `${RUNNER_CODEGEN_PACKAGE}.eager_and(${leftOperand}, ${rightOperand})`; + case '?:': + frame.addImport({ importPath: RUNNER_CODEGEN_PACKAGE }); + return `${RUNNER_CODEGEN_PACKAGE}.eager_elvis(${leftOperand}, ${rightOperand})`; + case '===': + return `(${leftOperand}) is (${rightOperand})`; + case '!==': + return `(${leftOperand}) is not (${rightOperand})`; + default: + return `(${leftOperand}) ${expression.operator} (${rightOperand})`; + } + } + if (isSdsIndexedAccess(expression)) { + return expandToString`${generateExpression(expression.receiver, frame)}[${generateExpression( + expression.index, + frame, + )}]`; + } + if (isSdsMemberAccess(expression)) { + const member = expression.member?.target.ref!; + const receiver = generateExpression(expression.receiver, frame); + if (isSdsEnumVariant(member)) { + const enumMember = generateExpression(expression.member!, frame); + const suffix = isSdsCall(expression.$container) ? '' : '()'; + return `${receiver}.${enumMember}${suffix}`; + } else if (isSdsAbstractResult(member)) { + const resultList = abstractResultsOrEmpty(getContainerOfType(member, isSdsCallable)); + if (resultList.length === 1) { + return receiver; + } + const currentIndex = resultList.indexOf(member); + return `${receiver}[${currentIndex}]`; + } else { + const memberExpression = generateExpression(expression.member!, frame); + if (expression.isNullSafe) { + frame.addImport({ importPath: RUNNER_CODEGEN_PACKAGE }); + return `${RUNNER_CODEGEN_PACKAGE}.safe_access(${receiver}, '${memberExpression}')`; + } else { + return `${receiver}.${memberExpression}`; + } + } + } + if (isSdsParenthesizedExpression(expression)) { + return expandToString`${generateExpression(expression.expression, frame)}`; + } + if (isSdsPrefixOperation(expression)) { + const operand = generateExpression(expression.operand, frame); + switch (expression.operator) { + case 'not': + return expandToString`not (${operand})`; + case '-': + return expandToString`-(${operand})`; + } + } + if (isSdsReference(expression)) { + const declaration = expression.target.ref!; + const referenceImport = + getExternalReferenceNeededImport(frame.getServices(), expression, declaration) || + getInternalReferenceNeededImport(frame.getServices(), expression, declaration); + frame.addImport(referenceImport); + return referenceImport?.alias || getPythonNameOrDefault(frame.getServices(), declaration); + } + /* c8 ignore next 2 */ + throw new Error(`Unknown expression type: ${expression.$type}`); +}; + +const sortArguments = function (services: SafeDsServices, argumentList: SdsArgument[]): SdsArgument[] { + // $containerIndex contains the index of the parameter in the receivers parameter list + const parameters = argumentList.map((argument) => { + return { par: services.helpers.NodeMapper.argumentToParameterOrUndefined(argument), arg: argument }; + }); + return parameters + .slice() + .filter((value) => value.par !== undefined) + .sort((a, b) => + a.par !== undefined && b.par !== undefined ? a.par.$containerIndex! - b.par.$containerIndex! : 0, + ) + .map((value) => value.arg); +}; - const fileNode = new CompositeGeneratorNode(); - // fileNode.append('"use strict";', NL, NL); - // model.greetings.forEach(greeting => fileNode.append(`console.log('Hello, ${greeting.person.ref?.name}!');`, NL)); +const generateArgument = function (argument: SdsArgument, frame: GenerationInfoFrame) { + const parameter = frame.getServices().helpers.NodeMapper.argumentToParameterOrUndefined(argument); + return expandToString`${ + parameter !== undefined && !isRequiredParameter(parameter) + ? generateParameter(parameter, frame, false) + '=' + : '' + }${generateExpression(argument.value, frame)}`; +}; + +const getExternalReferenceNeededImport = function ( + services: SafeDsServices, + expression: SdsExpression, + declaration: SdsDeclaration, +): ImportData | undefined { + // Root Node is always a module. + const currentModule = findRootNode(expression); + const targetModule = findRootNode(declaration); + for (const value of importsOrEmpty(currentModule)) { + // Verify same package + if (value.package !== targetModule.name) { + continue; + } + if (isSdsQualifiedImport(value)) { + const importedDeclarations = importedDeclarationsOrEmpty(value); + for (const importedDeclaration of importedDeclarations) { + if (declaration === importedDeclaration.declaration.ref) { + if (importedDeclaration.alias !== undefined) { + return { + importPath: services.builtins.Annotations.getPythonModule(targetModule) || value.package, + declarationName: importedDeclaration.declaration?.ref?.name, + alias: importedDeclaration.alias.alias, + }; + } else { + return { + importPath: services.builtins.Annotations.getPythonModule(targetModule) || value.package, + declarationName: importedDeclaration.declaration?.ref?.name, + }; + } + } + } + } + if (isSdsWildcardImport(value)) { + return { + importPath: services.builtins.Annotations.getPythonModule(targetModule) || value.package, + declarationName: declaration.name, + }; + } + } + return undefined; +}; - if (!fs.existsSync(data.destination)) { - fs.mkdirSync(data.destination, { recursive: true }); +const getInternalReferenceNeededImport = function ( + services: SafeDsServices, + expression: SdsExpression, + declaration: SdsDeclaration, +): ImportData | undefined { + // Root Node is always a module. + const currentModule = findRootNode(expression); + const targetModule = findRootNode(declaration); + if (currentModule !== targetModule && !isInStubFile(targetModule)) { + return { + importPath: `${ + services.builtins.Annotations.getPythonModule(targetModule) || targetModule.name + }.${formatGeneratedFileName(getModuleFileBaseName(targetModule))}`, + declarationName: getPythonNameOrDefault(services, declaration), + }; } - fs.writeFileSync(generatedFilePath, toString(fileNode)); - return [generatedFilePath]; + return undefined; +}; + +const getModuleFileBaseName = function (module: SdsModule): string { + const filePath = getDocument(module).uri.fsPath; + return path.basename(filePath, path.extname(filePath)); }; + +const formatStringSingleLine = function (value: string): string { + return value.replaceAll('\r\n', '\\n').replaceAll('\n', '\\n'); +}; + +interface ImportData { + readonly importPath: string; + readonly declarationName?: string; + readonly alias?: string; +} + +class GenerationInfoFrame { + services: SafeDsServices; + blockLambdaManager: IdManager; + importSet: Map; + + constructor(services: SafeDsServices, importSet: Map = new Map()) { + this.services = services; + this.blockLambdaManager = new IdManager(); + this.importSet = importSet; + } + + addImport(importData: ImportData | undefined) { + if (importData) { + const hashKey = JSON.stringify(importData); + if (!this.importSet.has(hashKey)) { + this.importSet.set(hashKey, importData); + } + } + } + + getUniqueLambdaBlockName(lambda: SdsBlockLambda): string { + return `${BLOCK_LAMBDA_PREFIX}${this.blockLambdaManager.assignId(lambda)}`; + } + + getServices(): SafeDsServices { + return this.services; + } +} + +export interface GenerateOptions { + destination?: string; +} diff --git a/src/language/validation/names.ts b/src/language/validation/names.ts index dc2bb7349..6a0e83938 100644 --- a/src/language/validation/names.ts +++ b/src/language/validation/names.ts @@ -36,26 +36,26 @@ import { isInPipelineFile, isInStubFile, isInTestFile } from '../helpers/fileExt import { declarationIsAllowedInPipelineFile, declarationIsAllowedInStubFile } from './other/modules.js'; import { SafeDsServices } from '../safe-ds-module.js'; import { listBuiltinFiles } from '../builtins/fileFinder.js'; +import { CODEGEN_PREFIX } from '../../cli/generator.js'; -export const CODE_NAME_BLOCK_LAMBDA_PREFIX = 'name/block-lambda-prefix'; +export const CODE_NAME_CODEGEN_PREFIX = 'name/codegen-prefix'; export const CODE_NAME_CASING = 'name/casing'; export const CODE_NAME_DUPLICATE = 'name/duplicate'; // ----------------------------------------------------------------------------- -// Block lambda prefix +// Codegen prefix // ----------------------------------------------------------------------------- -export const nameMustNotStartWithBlockLambdaPrefix = (node: SdsDeclaration, accept: ValidationAcceptor) => { +export const nameMustNotStartWithCodegenPrefix = (node: SdsDeclaration, accept: ValidationAcceptor) => { const name = node.name ?? ''; - const blockLambdaPrefix = '__block_lambda_'; - if (name.startsWith(blockLambdaPrefix)) { + if (name.startsWith(CODEGEN_PREFIX)) { accept( 'error', - "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas.", + `Names of declarations must not start with '${CODEGEN_PREFIX}'. This is reserved for code generation.`, { node, property: 'name', - code: CODE_NAME_BLOCK_LAMBDA_PREFIX, + code: CODE_NAME_CODEGEN_PREFIX, }, ); } diff --git a/src/language/validation/safe-ds-validator.ts b/src/language/validation/safe-ds-validator.ts index 15fd46a26..618b96196 100644 --- a/src/language/validation/safe-ds-validator.ts +++ b/src/language/validation/safe-ds-validator.ts @@ -12,7 +12,7 @@ import { functionMustContainUniqueNames, moduleMemberMustHaveNameThatIsUniqueInPackage, moduleMustContainUniqueNames, - nameMustNotStartWithBlockLambdaPrefix, + nameMustNotStartWithCodegenPrefix, nameShouldHaveCorrectCasing, pipelineMustContainUniqueNames, schemaMustContainUniqueNames, @@ -188,7 +188,7 @@ export const registerValidationChecks = function (services: SafeDsServices) { SdsClassBody: [classBodyShouldNotBeEmpty], SdsConstraintList: [constraintListShouldNotBeEmpty], SdsDeclaration: [ - nameMustNotStartWithBlockLambdaPrefix, + nameMustNotStartWithCodegenPrefix, nameShouldHaveCorrectCasing, pythonNameShouldDifferFromSafeDsName(services), singleUseAnnotationsMustNotBeRepeated(services), diff --git a/tests/helpers/diagnostics.ts b/tests/helpers/diagnostics.ts index 36e7d2fce..78b54f709 100644 --- a/tests/helpers/diagnostics.ts +++ b/tests/helpers/diagnostics.ts @@ -41,6 +41,18 @@ export const getErrors = async (services: LangiumServices, code: string): Promis return diagnostics.filter((d) => d.severity === DiagnosticSeverity.Error); }; +/** + * Get all errors from a loaded document. + * + * @param services The language services. + * @param uri The URI of the document to check. + * @returns The errors. + */ +export const getErrorsAtURI = (services: LangiumServices, uri: URI): Diagnostic[] => { + const diagnostics = getDiagnosticsAtURI(services, uri); + return diagnostics.filter((d) => d.severity === DiagnosticSeverity.Error); +}; + /** * Get all diagnostics from a code snippet. * @@ -57,6 +69,18 @@ const getDiagnostics = async (services: LangiumServices, code: string): Promise< return document.diagnostics ?? []; }; +/** + * Get all diagnostics from a loaded document. + * + * @param services The language services. + * @param uri The URI of the document to check. + * @returns The diagnostics. + */ +const getDiagnosticsAtURI = (services: LangiumServices, uri: URI): Diagnostic[] => { + const document = services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri); + return document.diagnostics ?? []; +}; + /** * The code contains syntax errors. */ diff --git a/tests/helpers/testResources.ts b/tests/helpers/testResources.ts index 67dfcd847..63a0daee4 100644 --- a/tests/helpers/testResources.ts +++ b/tests/helpers/testResources.ts @@ -2,7 +2,8 @@ import path from 'path'; import { globSync } from 'glob'; import { SAFE_DS_FILE_EXTENSIONS } from '../../src/language/helpers/fileExtensions.js'; import { group } from 'radash'; -import { URI } from 'langium'; +import { BuildOptions, LangiumDocument, URI } from 'langium'; +import { SafeDsServices } from '../../src/language/safe-ds-module.js'; const TEST_RESOURCES_PATH = path.join(__dirname, '..', 'resources'); @@ -92,3 +93,21 @@ const isNotSkipped = (pathRelativeToResources: string) => { const segments = pathRelativeToResources.split(path.sep); return !segments.some((segment) => segment.startsWith('skip')); }; + +/** + * Load the documents at the specified URIs into the workspace managed by the given services. + * + * @param services The language services. + * @param uris The URIs of the documents to load. + * @param options The build options. + * @returns The loaded documents. + */ +export const loadDocuments = async ( + services: SafeDsServices, + uris: URI[], + options: BuildOptions = {}, +): Promise => { + const documents = uris.map((uri) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri)); + await services.shared.workspace.DocumentBuilder.build(documents, options); + return documents; +}; diff --git a/tests/language/generation/creator.ts b/tests/language/generation/creator.ts index 88a40584a..87364e6b5 100644 --- a/tests/language/generation/creator.ts +++ b/tests/language/generation/creator.ts @@ -1,12 +1,13 @@ import { listTestPythonFiles, listTestSafeDsFilesGroupedByParentDirectory, + loadDocuments, uriToShortenedTestResourceName, } from '../../helpers/testResources.js'; import path from 'path'; import fs from 'fs'; import { createSafeDsServices } from '../../../src/language/safe-ds-module.js'; -import { ErrorsInCodeError, getErrors } from '../../helpers/diagnostics.js'; +import { ErrorsInCodeError, getErrorsAtURI } from '../../helpers/diagnostics.js'; import { findTestChecks } from '../../helpers/testChecks.js'; import { Location } from 'vscode-languageserver'; import { NodeFileSystem } from 'langium/node'; @@ -31,11 +32,14 @@ const createGenerationTest = async (parentDirectory: URI, inputUris: URI[]): Pro const expectedOutputFiles = readExpectedOutputFiles(expectedOutputRoot, actualOutputRoot); let runUntil: Location | undefined; + // Load all files, so they get linked + await loadDocuments(services, inputUris, { validation: true }); + for (const uri of inputUris) { - const code = fs.readFileSync(uri.fsPath).toString(); + const code = services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri).textDocument.getText(); // File must not contain any errors - const errors = await getErrors(services, code); + const errors = getErrorsAtURI(services, uri); if (errors.length > 0) { return invalidTest('FILE', new ErrorsInCodeError(errors, uri)); } diff --git a/tests/language/generation/testGeneration.test.ts b/tests/language/generation/testGeneration.test.ts index 2587d37db..79ba59b58 100644 --- a/tests/language/generation/testGeneration.test.ts +++ b/tests/language/generation/testGeneration.test.ts @@ -6,6 +6,7 @@ import { createGenerationTests } from './creator.js'; import { SdsModule } from '../../../src/language/generated/ast.js'; import { generatePython } from '../../../src/cli/generator.js'; import fs from 'fs'; +import { loadDocuments } from '../../helpers/testResources.js'; const services = createSafeDsServices(NodeFileSystem).SafeDs; const generationTests = createGenerationTests(); @@ -27,10 +28,7 @@ describe('generation', async () => { } // Load all documents - const documents = test.inputUris.map((uri) => - services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri), - ); - await services.shared.workspace.DocumentBuilder.build(documents); + const documents = await loadDocuments(services, test.inputUris); // Generate code for all documents const actualOutputPaths: string[] = []; @@ -38,7 +36,7 @@ describe('generation', async () => { for (const document of documents) { const module = document.parseResult.value as SdsModule; const fileName = document.uri.fsPath; - const generatedFilePaths = generatePython(module, fileName, test.actualOutputRoot.fsPath); + const generatedFilePaths = generatePython(services, module, fileName, test.actualOutputRoot.fsPath); actualOutputPaths.push(...generatedFilePaths); } diff --git a/tests/language/partialEvaluation/testPartialEvaluation.test.ts b/tests/language/partialEvaluation/testPartialEvaluation.test.ts index 533772466..2b5b8f64f 100644 --- a/tests/language/partialEvaluation/testPartialEvaluation.test.ts +++ b/tests/language/partialEvaluation/testPartialEvaluation.test.ts @@ -6,6 +6,7 @@ import { AssertionError } from 'assert'; import { locationToString } from '../../helpers/location.js'; import { createPartialEvaluationTests } from './creator.js'; import { getNodeByLocation } from '../../helpers/nodeFinder.js'; +import { loadDocuments } from '../../helpers/testResources.js'; const services = createSafeDsServices(NodeFileSystem).SafeDs; const partialEvaluator = services.evaluation.PartialEvaluator; @@ -22,8 +23,7 @@ describe('partial evaluation', async () => { } // Load all documents - const documents = test.uris.map((uri) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri)); - await services.shared.workspace.DocumentBuilder.build(documents); + await loadDocuments(services, test.uris); // Ensure that partially evaluating nodes in the same equivalence class yields the same result for (const equivalenceClassAssertion of test.equivalenceClassAssertions) { diff --git a/tests/language/scoping/testScoping.test.ts b/tests/language/scoping/testScoping.test.ts index 86a29987d..485ed0caf 100644 --- a/tests/language/scoping/testScoping.test.ts +++ b/tests/language/scoping/testScoping.test.ts @@ -7,6 +7,7 @@ import { AssertionError } from 'assert'; import { isLocationEqual, locationToString } from '../../helpers/location.js'; import { createScopingTests, ExpectedReference } from './creator.js'; import { Location } from 'vscode-languageserver'; +import { loadDocuments } from '../../helpers/testResources.js'; const services = createSafeDsServices(NodeFileSystem).SafeDs; @@ -27,8 +28,7 @@ describe('scoping', async () => { } // Load all documents - const documents = test.uris.map((uri) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri)); - await services.shared.workspace.DocumentBuilder.build(documents); + await loadDocuments(services, test.uris); // Ensure all expected references match for (const expectedReference of test.expectedReferences) { diff --git a/tests/language/typing/creator.ts b/tests/language/typing/type computer/creator.ts similarity index 94% rename from tests/language/typing/creator.ts rename to tests/language/typing/type computer/creator.ts index 1bc690c74..d1908613b 100644 --- a/tests/language/typing/creator.ts +++ b/tests/language/typing/type computer/creator.ts @@ -1,14 +1,14 @@ import { listTestSafeDsFilesGroupedByParentDirectory, uriToShortenedTestResourceName, -} from '../../helpers/testResources.js'; +} from '../../../helpers/testResources.js'; import fs from 'fs'; -import { findTestChecks } from '../../helpers/testChecks.js'; +import { findTestChecks } from '../../../helpers/testChecks.js'; import { Location } from 'vscode-languageserver'; -import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../helpers/diagnostics.js'; +import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../../helpers/diagnostics.js'; import { EmptyFileSystem, URI } from 'langium'; -import { createSafeDsServices } from '../../../src/language/safe-ds-module.js'; -import { TestDescription, TestDescriptionError } from '../../helpers/testDescription.js'; +import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js'; +import { TestDescription, TestDescriptionError } from '../../../helpers/testDescription.js'; const services = createSafeDsServices(EmptyFileSystem).SafeDs; const rootResourceName = 'typing'; diff --git a/tests/language/typing/testTyping.test.ts b/tests/language/typing/type computer/testTyping.test.ts similarity index 87% rename from tests/language/typing/testTyping.test.ts rename to tests/language/typing/type computer/testTyping.test.ts index b2975c05e..6f388838a 100644 --- a/tests/language/typing/testTyping.test.ts +++ b/tests/language/typing/type computer/testTyping.test.ts @@ -1,11 +1,12 @@ import { afterEach, beforeEach, describe, it } from 'vitest'; -import { createSafeDsServices } from '../../../src/language/safe-ds-module.js'; +import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js'; import { NodeFileSystem } from 'langium/node'; import { clearDocuments } from 'langium/test'; import { AssertionError } from 'assert'; -import { locationToString } from '../../helpers/location.js'; +import { locationToString } from '../../../helpers/location.js'; import { createTypingTests } from './creator.js'; -import { getNodeByLocation } from '../../helpers/nodeFinder.js'; +import { getNodeByLocation } from '../../../helpers/nodeFinder.js'; +import { loadDocuments } from '../../../helpers/testResources.js'; const services = createSafeDsServices(NodeFileSystem).SafeDs; const typeComputer = services.types.TypeComputer; @@ -27,8 +28,7 @@ describe('typing', async () => { } // Load all documents - const documents = test.uris.map((uri) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri)); - await services.shared.workspace.DocumentBuilder.build(documents); + await loadDocuments(services, test.uris); // Ensure all nodes in the equivalence class have the same type for (const equivalenceClassAssertion of test.equivalenceClassAssertions) { diff --git a/tests/language/validation/testValidation.test.ts b/tests/language/validation/testValidation.test.ts index 6d342dc07..81d6a7f4a 100644 --- a/tests/language/validation/testValidation.test.ts +++ b/tests/language/validation/testValidation.test.ts @@ -6,6 +6,7 @@ import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver'; import { AssertionError } from 'assert'; import { clearDocuments, isRangeEqual } from 'langium/test'; import { locationToString } from '../../helpers/location.js'; +import { loadDocuments } from '../../helpers/testResources.js'; const services = createSafeDsServices(NodeFileSystem).SafeDs; @@ -26,8 +27,7 @@ describe('validation', async () => { } // Load all documents - const documents = test.uris.map((uri) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri)); - await services.shared.workspace.DocumentBuilder.build(documents, { validation: true }); + await loadDocuments(services, test.uris, { validation: true }); // Ensure all expected issues match for (const expectedIssue of test.expectedIssues) { diff --git a/tests/resources/generation/skip-declarations/empty pipeline/input.sdstest b/tests/resources/generation/declarations/empty pipeline/input.sdstest similarity index 100% rename from tests/resources/generation/skip-declarations/empty pipeline/input.sdstest rename to tests/resources/generation/declarations/empty pipeline/input.sdstest diff --git a/tests/resources/generation/skip-declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input.py b/tests/resources/generation/declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input.py similarity index 100% rename from tests/resources/generation/skip-declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input.py rename to tests/resources/generation/declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input.py diff --git a/tests/resources/generation/skip-declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input_test.py b/tests/resources/generation/declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input_test.py rename to tests/resources/generation/declarations/empty pipeline/output/tests/generator/emptyPipeline/gen_input_test.py diff --git a/tests/resources/generation/skip-declarations/empty step/input.sdstest b/tests/resources/generation/declarations/empty step/input.sdstest similarity index 100% rename from tests/resources/generation/skip-declarations/empty step/input.sdstest rename to tests/resources/generation/declarations/empty step/input.sdstest diff --git a/tests/resources/generation/skip-declarations/empty step/output/tests/generator/emptyStep/gen_input.py b/tests/resources/generation/declarations/empty step/output/tests/generator/emptyStep/gen_input.py similarity index 100% rename from tests/resources/generation/skip-declarations/empty step/output/tests/generator/emptyStep/gen_input.py rename to tests/resources/generation/declarations/empty step/output/tests/generator/emptyStep/gen_input.py diff --git a/tests/resources/generation/declarations/parameter with python name/input.sdstest b/tests/resources/generation/declarations/parameter with python name/input.sdstest new file mode 100644 index 000000000..c6b48eed9 --- /dev/null +++ b/tests/resources/generation/declarations/parameter with python name/input.sdstest @@ -0,0 +1,9 @@ +package tests.generator.parameterWithPythonName + +fun f1(param: (a: Int, b: Int, c: Int) -> r: Int) +fun f2(param: (a: Int, b: Int, c: Int) -> ()) + +segment test(param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_3") param3: Int = 0) { + f1((param1: Int, param2: Int, param3: Int = 0) -> 1); + f2((param1: Int, param2: Int, param3: Int = 0) {}); +} diff --git a/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py b/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py new file mode 100644 index 000000000..4d9c8f8d5 --- /dev/null +++ b/tests/resources/generation/declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py @@ -0,0 +1,7 @@ +# Steps ------------------------------------------------------------------------ + +def test(param1, param_2, param_3=0): + f1(lambda param1, param2, param3=0: 1) + def __gen_block_lambda_0(param1, param2, param3=0): + pass + f2(__gen_block_lambda_0) diff --git a/tests/resources/generation/skip-declarations/pipeline with python name/input.sdstest b/tests/resources/generation/declarations/pipeline with python name/input.sdstest similarity index 100% rename from tests/resources/generation/skip-declarations/pipeline with python name/input.sdstest rename to tests/resources/generation/declarations/pipeline with python name/input.sdstest diff --git a/tests/resources/generation/skip-declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input.py b/tests/resources/generation/declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input.py similarity index 100% rename from tests/resources/generation/skip-declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input.py rename to tests/resources/generation/declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input.py diff --git a/tests/resources/generation/skip-declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input_test_pipeline.py b/tests/resources/generation/declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input_test_pipeline.py similarity index 100% rename from tests/resources/generation/skip-declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input_test_pipeline.py rename to tests/resources/generation/declarations/pipeline with python name/output/tests/generator/pipelineWithPythonName/gen_input_test_pipeline.py diff --git a/tests/resources/generation/skip-declarations/step with python name/input.sdstest b/tests/resources/generation/declarations/step with python name/input.sdstest similarity index 100% rename from tests/resources/generation/skip-declarations/step with python name/input.sdstest rename to tests/resources/generation/declarations/step with python name/input.sdstest diff --git a/tests/resources/generation/skip-declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py b/tests/resources/generation/declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py similarity index 100% rename from tests/resources/generation/skip-declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py rename to tests/resources/generation/declarations/step with python name/output/tests/generator/stepWithPythonName/gen_input.py diff --git a/tests/resources/generation/skip-declarations/two pipelines/input.sdstest b/tests/resources/generation/declarations/two pipelines/input.sdstest similarity index 100% rename from tests/resources/generation/skip-declarations/two pipelines/input.sdstest rename to tests/resources/generation/declarations/two pipelines/input.sdstest diff --git a/tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input.py b/tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input.py similarity index 100% rename from tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input.py rename to tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input.py diff --git a/tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test1.py b/tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test1.py similarity index 100% rename from tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test1.py rename to tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test1.py diff --git a/tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test2.py b/tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test2.py similarity index 100% rename from tests/resources/generation/skip-declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test2.py rename to tests/resources/generation/declarations/two pipelines/output/tests/generator/twoPipelines/gen_input_test2.py diff --git a/tests/resources/generation/skip-declarations/two steps/input.sdstest b/tests/resources/generation/declarations/two steps/input.sdstest similarity index 72% rename from tests/resources/generation/skip-declarations/two steps/input.sdstest rename to tests/resources/generation/declarations/two steps/input.sdstest index 8c21e4602..d265f8262 100644 --- a/tests/resources/generation/skip-declarations/two steps/input.sdstest +++ b/tests/resources/generation/declarations/two steps/input.sdstest @@ -6,6 +6,6 @@ segment test1(a: Int, b: Int = 0) { f(); } -segment test2(a: Int, vararg c: Int) { +segment test2(a: Int, c: Int) { f(); } diff --git a/tests/resources/generation/skip-declarations/two steps/output/tests/generator/twoSteps/gen_input.py b/tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py similarity index 86% rename from tests/resources/generation/skip-declarations/two steps/output/tests/generator/twoSteps/gen_input.py rename to tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py index bb0c1f51b..15d4deb31 100644 --- a/tests/resources/generation/skip-declarations/two steps/output/tests/generator/twoSteps/gen_input.py +++ b/tests/resources/generation/declarations/two steps/output/tests/generator/twoSteps/gen_input.py @@ -3,5 +3,5 @@ def test1(a, b=0): f() -def test2(a, *c): +def test2(a, c): f() diff --git a/tests/resources/generation/dummy/output/test.py b/tests/resources/generation/dummy/output/test.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/generation/dummy/test.sdstest b/tests/resources/generation/dummy/test.sdstest deleted file mode 100644 index 8e2774107..000000000 --- a/tests/resources/generation/dummy/test.sdstest +++ /dev/null @@ -1,6 +0,0 @@ -package tests.generation.dummy - -pipeline myPipeline { - // $TEST$ run_until - val »a« = 1; -} diff --git a/tests/resources/generation/expressions/block lambda result/input.sdstest b/tests/resources/generation/expressions/block lambda result/input.sdstest new file mode 100644 index 000000000..28fc9b248 --- /dev/null +++ b/tests/resources/generation/expressions/block lambda result/input.sdstest @@ -0,0 +1,26 @@ +package tests.generator.blockLambdaResult + +fun g() -> a: Int + +fun h(a: Int) + +segment f1(l: (a: Int, b: Int) -> d: Int) { + h(l(1, 2).d); +} + +segment f2(l: (a: Int, b: Int) -> (d1: Int, e1: Int)) { + h(l(1, 2).e1); + h(l(1, 2).d1); +} + +pipeline test { + + f1((a: Int, b: Int) { + yield d = g(); + }); + f2((a: Int, b: Int) { + yield d = g(); + yield e = g(); + }); + +} diff --git a/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py b/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py new file mode 100644 index 000000000..3dfd67ece --- /dev/null +++ b/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input.py @@ -0,0 +1,21 @@ +# Steps ------------------------------------------------------------------------ + +def f1(l): + h(l(1, 2)) + +def f2(l): + h(l(1, 2)[1]) + h(l(1, 2)[0]) + +# Pipelines -------------------------------------------------------------------- + +def test(): + def __gen_block_lambda_0(a, b): + __gen_block_lambda_result_d = g() + return __gen_block_lambda_result_d + f1(__gen_block_lambda_0) + def __gen_block_lambda_1(a, b): + __gen_block_lambda_result_d = g() + __gen_block_lambda_result_e = g() + return __gen_block_lambda_result_d, __gen_block_lambda_result_e + f2(__gen_block_lambda_1) diff --git a/tests/resources/generation/skip-expressions/block lambda/output/tests/generator/blockLambda/gen_input_test.py b/tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/block lambda/output/tests/generator/blockLambda/gen_input_test.py rename to tests/resources/generation/expressions/block lambda result/output/tests/generator/blockLambdaResult/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/block lambda/input.sdstest b/tests/resources/generation/expressions/block lambda/input.sdstest similarity index 63% rename from tests/resources/generation/skip-expressions/block lambda/input.sdstest rename to tests/resources/generation/expressions/block lambda/input.sdstest index 6105b6ad0..bdfcd497c 100644 --- a/tests/resources/generation/skip-expressions/block lambda/input.sdstest +++ b/tests/resources/generation/expressions/block lambda/input.sdstest @@ -1,8 +1,7 @@ package tests.generator.blockLambda fun f1(param: (a: Int, b: Int) -> r: Int) -fun f2(param: (a: Int, vararg b: Int) -> r: Int) -fun f3(param: () -> ()) +fun f2(param: () -> ()) fun g() -> a: Int @@ -10,8 +9,8 @@ pipeline test { f1((a: Int, b: Int = 2) { yield d = g(); }); - f2((a: Int, vararg c: Int) { + f1((a: Int, c: Int) { yield d = g(); }); - f3(() {}); + f2(() {}); } diff --git a/tests/resources/generation/expressions/block lambda/output/tests/generator/blockLambda/gen_input.py b/tests/resources/generation/expressions/block lambda/output/tests/generator/blockLambda/gen_input.py new file mode 100644 index 000000000..1f02920f7 --- /dev/null +++ b/tests/resources/generation/expressions/block lambda/output/tests/generator/blockLambda/gen_input.py @@ -0,0 +1,14 @@ +# Pipelines -------------------------------------------------------------------- + +def test(): + def __gen_block_lambda_0(a, b=2): + __gen_block_lambda_result_d = g() + return __gen_block_lambda_result_d + f1(__gen_block_lambda_0) + def __gen_block_lambda_1(a, c): + __gen_block_lambda_result_d = g() + return __gen_block_lambda_result_d + f1(__gen_block_lambda_1) + def __gen_block_lambda_2(): + pass + f2(__gen_block_lambda_2) diff --git a/tests/resources/generation/skip-expressions/call/output/tests/generator/call/gen_input_test.py b/tests/resources/generation/expressions/block lambda/output/tests/generator/blockLambda/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/call/output/tests/generator/call/gen_input_test.py rename to tests/resources/generation/expressions/block lambda/output/tests/generator/blockLambda/gen_input_test.py diff --git a/tests/resources/generation/expressions/call/input.sdstest b/tests/resources/generation/expressions/call/input.sdstest new file mode 100644 index 000000000..656a10dbe --- /dev/null +++ b/tests/resources/generation/expressions/call/input.sdstest @@ -0,0 +1,20 @@ +package tests.generator.call + +fun f(param: Any?) + +fun g( + param1: Int, + param2: Int = 0 +) -> result: Boolean + +fun h( + @PythonName("param_1") param1: Int, + @PythonName("param_2") param2: Int = 0 +) -> result: Boolean + +pipeline test { + f((g(1, 2))); + f((g(param2 = 1, param1 = 2))); + f((h(1, 2))); + f((h(param2 = 1, param1 = 2))); +} diff --git a/tests/resources/generation/expressions/call/output/tests/generator/call/gen_input.py b/tests/resources/generation/expressions/call/output/tests/generator/call/gen_input.py new file mode 100644 index 000000000..e2968155b --- /dev/null +++ b/tests/resources/generation/expressions/call/output/tests/generator/call/gen_input.py @@ -0,0 +1,7 @@ +# Pipelines -------------------------------------------------------------------- + +def test(): + f(g(1, param2=2)) + f(g(2, param2=1)) + f(h(1, param_2=2)) + f(h(2, param_2=1)) diff --git a/tests/resources/generation/skip-expressions/constant/output/tests/generator/constant/gen_input_test.py b/tests/resources/generation/expressions/call/output/tests/generator/call/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/constant/output/tests/generator/constant/gen_input_test.py rename to tests/resources/generation/expressions/call/output/tests/generator/call/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/constant/input.sdstest b/tests/resources/generation/expressions/constant/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/constant/input.sdstest rename to tests/resources/generation/expressions/constant/input.sdstest diff --git a/tests/resources/generation/skip-expressions/constant/output/tests/generator/constant/gen_input.py b/tests/resources/generation/expressions/constant/output/tests/generator/constant/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/constant/output/tests/generator/constant/gen_input.py rename to tests/resources/generation/expressions/constant/output/tests/generator/constant/gen_input.py diff --git a/tests/resources/generation/skip-expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input_test.py b/tests/resources/generation/expressions/constant/output/tests/generator/constant/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input_test.py rename to tests/resources/generation/expressions/constant/output/tests/generator/constant/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/enum variant call/input.sdstest b/tests/resources/generation/expressions/enum variant call/input.sdstest similarity index 72% rename from tests/resources/generation/skip-expressions/enum variant call/input.sdstest rename to tests/resources/generation/expressions/enum variant call/input.sdstest index d113a4972..62431f4b4 100644 --- a/tests/resources/generation/skip-expressions/enum variant call/input.sdstest +++ b/tests/resources/generation/expressions/enum variant call/input.sdstest @@ -1,5 +1,3 @@ -// Related to https://github.com/lars-reimann/Safe-DS/issues/118 - package tests.generator.enumVariantCall fun f(p: Any) @@ -11,6 +9,9 @@ enum MyEnum { pipeline test { f(MyEnum.Variant1); + f(MyEnum?.Variant1); f(MyEnum.Variant1()); + f(MyEnum?.Variant1()); f(MyEnum.Variant2(1)); + f(MyEnum?.Variant2(1)); } diff --git a/tests/resources/generation/skip-expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py b/tests/resources/generation/expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py similarity index 69% rename from tests/resources/generation/skip-expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py rename to tests/resources/generation/expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py index 1a9a4f9d8..60d9dfc46 100644 --- a/tests/resources/generation/skip-expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py +++ b/tests/resources/generation/expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input.py @@ -3,4 +3,7 @@ def test(): f(MyEnum.Variant1()) f(MyEnum.Variant1()) + f(MyEnum.Variant1()) + f(MyEnum.Variant1()) + f(MyEnum.Variant2(1)) f(MyEnum.Variant2(1)) diff --git a/tests/resources/generation/skip-expressions/expression lambda/output/tests/generator/expressionLambda/gen_input_test.py b/tests/resources/generation/expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/expression lambda/output/tests/generator/expressionLambda/gen_input_test.py rename to tests/resources/generation/expressions/enum variant call/output/tests/generator/enumVariantCall/gen_input_test.py diff --git a/tests/resources/generation/expressions/expression lambda/input.sdstest b/tests/resources/generation/expressions/expression lambda/input.sdstest new file mode 100644 index 000000000..6f39b97ec --- /dev/null +++ b/tests/resources/generation/expressions/expression lambda/input.sdstest @@ -0,0 +1,8 @@ +package tests.generator.expressionLambda + +fun f(param: (a: Int, b: Int) -> r: Int) + +pipeline test { + f((a, b = 2) -> 1); + f((a, c) -> 1); +} diff --git a/tests/resources/generation/skip-expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py b/tests/resources/generation/expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py similarity index 65% rename from tests/resources/generation/skip-expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py rename to tests/resources/generation/expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py index 9399f7d79..7f130276a 100644 --- a/tests/resources/generation/skip-expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py +++ b/tests/resources/generation/expressions/expression lambda/output/tests/generator/expressionLambda/gen_input.py @@ -1,5 +1,5 @@ # Pipelines -------------------------------------------------------------------- def test(): - f1(lambda a, b=2: 1) - f2(lambda a, *c: 1) + f(lambda a, b=2: 1) + f(lambda a, c: 1) diff --git a/tests/resources/generation/skip-expressions/infix operation/output/tests/generator/infixOperation/gen_input_test.py b/tests/resources/generation/expressions/expression lambda/output/tests/generator/expressionLambda/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/infix operation/output/tests/generator/infixOperation/gen_input_test.py rename to tests/resources/generation/expressions/expression lambda/output/tests/generator/expressionLambda/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/indexed access/input.sdstest b/tests/resources/generation/expressions/indexed access/input.sdstest similarity index 69% rename from tests/resources/generation/skip-expressions/indexed access/input.sdstest rename to tests/resources/generation/expressions/indexed access/input.sdstest index 4532ca536..4b9c2a608 100644 --- a/tests/resources/generation/skip-expressions/indexed access/input.sdstest +++ b/tests/resources/generation/expressions/indexed access/input.sdstest @@ -2,6 +2,6 @@ package tests.generator.indexedAccess fun f(param: Any?) -segment test(vararg params: Int) { +segment test(params: List) { f(params[0]); } diff --git a/tests/resources/generation/skip-expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py b/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py similarity index 83% rename from tests/resources/generation/skip-expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py rename to tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py index 2673de5a6..56096ed17 100644 --- a/tests/resources/generation/skip-expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py +++ b/tests/resources/generation/expressions/indexed access/output/tests/generator/indexedAccess/gen_input.py @@ -1,4 +1,4 @@ # Steps ------------------------------------------------------------------------ -def test(*params): +def test(params): f(params[0]) diff --git a/tests/resources/generation/skip-expressions/infix operation/input.sdstest b/tests/resources/generation/expressions/infix operation/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/infix operation/input.sdstest rename to tests/resources/generation/expressions/infix operation/input.sdstest diff --git a/tests/resources/generation/skip-expressions/infix operation/output/tests/generator/infixOperation/gen_input.py b/tests/resources/generation/expressions/infix operation/output/tests/generator/infixOperation/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/infix operation/output/tests/generator/infixOperation/gen_input.py rename to tests/resources/generation/expressions/infix operation/output/tests/generator/infixOperation/gen_input.py diff --git a/tests/resources/generation/skip-expressions/literals/output/tests/generator/literals/gen_input_test.py b/tests/resources/generation/expressions/infix operation/output/tests/generator/infixOperation/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/literals/output/tests/generator/literals/gen_input_test.py rename to tests/resources/generation/expressions/infix operation/output/tests/generator/infixOperation/gen_input_test.py diff --git a/tests/resources/generation/expressions/lists/input.sdstest b/tests/resources/generation/expressions/lists/input.sdstest new file mode 100644 index 000000000..efb5ca1f8 --- /dev/null +++ b/tests/resources/generation/expressions/lists/input.sdstest @@ -0,0 +1,11 @@ +package tests.generator.lists + +fun f(param: List) + +fun h() -> result: Int + +pipeline test { + f([]); + f([1, 2, 3]); + f([1, h(), h() + 5]); +} diff --git a/tests/resources/generation/expressions/lists/output/tests/generator/lists/gen_input.py b/tests/resources/generation/expressions/lists/output/tests/generator/lists/gen_input.py new file mode 100644 index 000000000..d5faf3b21 --- /dev/null +++ b/tests/resources/generation/expressions/lists/output/tests/generator/lists/gen_input.py @@ -0,0 +1,6 @@ +# Pipelines -------------------------------------------------------------------- + +def test(): + f([]) + f([1, 2, 3]) + f([1, h(), (h()) + (5)]) diff --git a/tests/resources/generation/skip-expressions/member access/output/tests/generator/memberAccess/gen_input_test.py b/tests/resources/generation/expressions/lists/output/tests/generator/lists/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/member access/output/tests/generator/memberAccess/gen_input_test.py rename to tests/resources/generation/expressions/lists/output/tests/generator/lists/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/literals/input.sdstest b/tests/resources/generation/expressions/literals/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/literals/input.sdstest rename to tests/resources/generation/expressions/literals/input.sdstest diff --git a/tests/resources/generation/skip-expressions/literals/output/tests/generator/literals/gen_input.py b/tests/resources/generation/expressions/literals/output/tests/generator/literals/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/literals/output/tests/generator/literals/gen_input.py rename to tests/resources/generation/expressions/literals/output/tests/generator/literals/gen_input.py diff --git a/tests/resources/generation/skip-expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input_test.py b/tests/resources/generation/expressions/literals/output/tests/generator/literals/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input_test.py rename to tests/resources/generation/expressions/literals/output/tests/generator/literals/gen_input_test.py diff --git a/tests/resources/generation/expressions/maps/input.sdstest b/tests/resources/generation/expressions/maps/input.sdstest new file mode 100644 index 000000000..981e6a274 --- /dev/null +++ b/tests/resources/generation/expressions/maps/input.sdstest @@ -0,0 +1,17 @@ +package tests.generator.maps + +fun g1(param: Map) + +fun g2(param: Map) + +fun h1() -> result: Float + +fun h2() -> result: String + +pipeline test { + g1({}); + g1({"a": 1.2, "b": 1.0}); + g1({h2(): -0.5, "b": h1()}); + g2({1.2: "a", 1.0: "b"}); + g2({5.6: "c", h1(): h2()}); +} diff --git a/tests/resources/generation/expressions/maps/output/tests/generator/maps/gen_input.py b/tests/resources/generation/expressions/maps/output/tests/generator/maps/gen_input.py new file mode 100644 index 000000000..9db46e6bf --- /dev/null +++ b/tests/resources/generation/expressions/maps/output/tests/generator/maps/gen_input.py @@ -0,0 +1,8 @@ +# Pipelines -------------------------------------------------------------------- + +def test(): + g1({}) + g1({'a': 1.2, 'b': 1.0}) + g1({h2(): -0.5, 'b': h1()}) + g2({1.2: 'a', 1.0: 'b'}) + g2({5.6: 'c', h1(): h2()}) diff --git a/tests/resources/generation/skip-expressions/prefix operation/output/tests/generator/prefixOperation/gen_input_test.py b/tests/resources/generation/expressions/maps/output/tests/generator/maps/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/prefix operation/output/tests/generator/prefixOperation/gen_input_test.py rename to tests/resources/generation/expressions/maps/output/tests/generator/maps/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/member access/input.sdstest b/tests/resources/generation/expressions/member access/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/member access/input.sdstest rename to tests/resources/generation/expressions/member access/input.sdstest diff --git a/tests/resources/generation/skip-expressions/member access/output/tests/generator/memberAccess/gen_input.py b/tests/resources/generation/expressions/member access/output/tests/generator/memberAccess/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/member access/output/tests/generator/memberAccess/gen_input.py rename to tests/resources/generation/expressions/member access/output/tests/generator/memberAccess/gen_input.py diff --git a/tests/resources/generation/skip-expressions/reference/output/tests/generator/reference/gen_input_test.py b/tests/resources/generation/expressions/member access/output/tests/generator/memberAccess/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/reference/output/tests/generator/reference/gen_input_test.py rename to tests/resources/generation/expressions/member access/output/tests/generator/memberAccess/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/parenthesized expression/input.sdstest b/tests/resources/generation/expressions/parenthesized expression/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/parenthesized expression/input.sdstest rename to tests/resources/generation/expressions/parenthesized expression/input.sdstest diff --git a/tests/resources/generation/skip-expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input.py b/tests/resources/generation/expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input.py rename to tests/resources/generation/expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input.py diff --git a/tests/resources/generation/skip-expressions/template string/output/tests/generator/templateString/gen_input_test.py b/tests/resources/generation/expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-expressions/template string/output/tests/generator/templateString/gen_input_test.py rename to tests/resources/generation/expressions/parenthesized expression/output/tests/generator/parenthesizedExpression/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/prefix operation/input.sdstest b/tests/resources/generation/expressions/prefix operation/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/prefix operation/input.sdstest rename to tests/resources/generation/expressions/prefix operation/input.sdstest diff --git a/tests/resources/generation/skip-expressions/prefix operation/output/tests/generator/prefixOperation/gen_input.py b/tests/resources/generation/expressions/prefix operation/output/tests/generator/prefixOperation/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/prefix operation/output/tests/generator/prefixOperation/gen_input.py rename to tests/resources/generation/expressions/prefix operation/output/tests/generator/prefixOperation/gen_input.py diff --git a/tests/resources/generation/skip-imports/output/tests/generator/imports/gen_input_test.py b/tests/resources/generation/expressions/prefix operation/output/tests/generator/prefixOperation/gen_input_test.py similarity index 100% rename from tests/resources/generation/skip-imports/output/tests/generator/imports/gen_input_test.py rename to tests/resources/generation/expressions/prefix operation/output/tests/generator/prefixOperation/gen_input_test.py diff --git a/tests/resources/generation/skip-expressions/reference/input.sdstest b/tests/resources/generation/expressions/reference/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/reference/input.sdstest rename to tests/resources/generation/expressions/reference/input.sdstest diff --git a/tests/resources/generation/skip-expressions/reference/output/tests/generator/reference/gen_input.py b/tests/resources/generation/expressions/reference/output/tests/generator/reference/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/reference/output/tests/generator/reference/gen_input.py rename to tests/resources/generation/expressions/reference/output/tests/generator/reference/gen_input.py diff --git a/tests/resources/generation/expressions/reference/output/tests/generator/reference/gen_input_test.py b/tests/resources/generation/expressions/reference/output/tests/generator/reference/gen_input_test.py new file mode 100644 index 000000000..30abe031d --- /dev/null +++ b/tests/resources/generation/expressions/reference/output/tests/generator/reference/gen_input_test.py @@ -0,0 +1,4 @@ +from gen_input import test + +if __name__ == '__main__': + test() diff --git a/tests/resources/generation/skip-expressions/template string/input.sdstest b/tests/resources/generation/expressions/template string/input.sdstest similarity index 100% rename from tests/resources/generation/skip-expressions/template string/input.sdstest rename to tests/resources/generation/expressions/template string/input.sdstest diff --git a/tests/resources/generation/skip-expressions/template string/output/tests/generator/templateString/gen_input.py b/tests/resources/generation/expressions/template string/output/tests/generator/templateString/gen_input.py similarity index 100% rename from tests/resources/generation/skip-expressions/template string/output/tests/generator/templateString/gen_input.py rename to tests/resources/generation/expressions/template string/output/tests/generator/templateString/gen_input.py diff --git a/tests/resources/generation/expressions/template string/output/tests/generator/templateString/gen_input_test.py b/tests/resources/generation/expressions/template string/output/tests/generator/templateString/gen_input_test.py new file mode 100644 index 000000000..30abe031d --- /dev/null +++ b/tests/resources/generation/expressions/template string/output/tests/generator/templateString/gen_input_test.py @@ -0,0 +1,4 @@ +from gen_input import test + +if __name__ == '__main__': + test() diff --git a/tests/resources/generation/skip-imports/context different package.sdsstub b/tests/resources/generation/imports/general/context different package.sdsstub similarity index 100% rename from tests/resources/generation/skip-imports/context different package.sdsstub rename to tests/resources/generation/imports/general/context different package.sdsstub diff --git a/tests/resources/generation/skip-imports/context package with python module.sdsstub b/tests/resources/generation/imports/general/context package with python module.sdsstub similarity index 100% rename from tests/resources/generation/skip-imports/context package with python module.sdsstub rename to tests/resources/generation/imports/general/context package with python module.sdsstub diff --git a/tests/resources/generation/skip-imports/context same package.sdstest b/tests/resources/generation/imports/general/context same package.sdstest similarity index 100% rename from tests/resources/generation/skip-imports/context same package.sdstest rename to tests/resources/generation/imports/general/context same package.sdstest diff --git a/tests/resources/generation/skip-imports/input.sdstest b/tests/resources/generation/imports/general/input.sdstest similarity index 100% rename from tests/resources/generation/skip-imports/input.sdstest rename to tests/resources/generation/imports/general/input.sdstest diff --git a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py new file mode 100644 index 000000000..2575a1ac1 --- /dev/null +++ b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_context_same_package.py @@ -0,0 +1,9 @@ +# Steps ------------------------------------------------------------------------ + +def step1InSamePackage(): + __gen_yield_result = impureFunction() + return __gen_yield_result + +def step2InSamePackage(): + __gen_yield_result = impureFunction() + return __gen_yield_result diff --git a/tests/resources/generation/skip-imports/output/tests/generator/imports/gen_input.py b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py similarity index 87% rename from tests/resources/generation/skip-imports/output/tests/generator/imports/gen_input.py rename to tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py index 1010e1898..895f4da5d 100644 --- a/tests/resources/generation/skip-imports/output/tests/generator/imports/gen_input.py +++ b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input.py @@ -2,7 +2,7 @@ from special_location import function1InCompilationUnitWithPythonModule, function2InCompilationUnitWithPythonModule as h from tests.generator.differentPackage import function1InDifferentPackage, function2InDifferentPackage as g -from tests.generator.imports.gen__skip__context_same_package import step1InSamePackage, step2InSamePackage +from tests.generator.imports.gen_context_same_package import step1InSamePackage, step2InSamePackage # Pipelines -------------------------------------------------------------------- diff --git a/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input_test.py b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input_test.py new file mode 100644 index 000000000..30abe031d --- /dev/null +++ b/tests/resources/generation/imports/general/output/tests/generator/imports/gen_input_test.py @@ -0,0 +1,4 @@ +from gen_input import test + +if __name__ == '__main__': + test() diff --git a/tests/resources/generation/imports/wildcard/context different package.sdsstub b/tests/resources/generation/imports/wildcard/context different package.sdsstub new file mode 100644 index 000000000..1bd918cce --- /dev/null +++ b/tests/resources/generation/imports/wildcard/context different package.sdsstub @@ -0,0 +1,4 @@ +package tests.generator.differentPackageWildcard + +fun function1InDifferentPackage() -> result: Int +fun function2InDifferentPackage() -> result: Int diff --git a/tests/resources/generation/imports/wildcard/context package with python module.sdsstub b/tests/resources/generation/imports/wildcard/context package with python module.sdsstub new file mode 100644 index 000000000..d274d7c98 --- /dev/null +++ b/tests/resources/generation/imports/wildcard/context package with python module.sdsstub @@ -0,0 +1,6 @@ +@PythonModule("special_location") + +package tests.generator.withPythonModuleWildcard + +fun function1InCompilationUnitWithPythonModule() -> result: Int +fun function2InCompilationUnitWithPythonModule() -> result: Int diff --git a/tests/resources/generation/imports/wildcard/input.sdstest b/tests/resources/generation/imports/wildcard/input.sdstest new file mode 100644 index 000000000..a0bfad653 --- /dev/null +++ b/tests/resources/generation/imports/wildcard/input.sdstest @@ -0,0 +1,18 @@ +package tests.generator.wildcard + +from tests.generator.differentPackageWildcard import * +from tests.generator.withPythonModuleWildcard import * + +fun f(param: Any?) + +pipeline test { + f(function1InDifferentPackage()); + f(function1InDifferentPackage()); + f(function2InDifferentPackage()); + f(function2InDifferentPackage()); + + f(function1InCompilationUnitWithPythonModule()); + f(function1InCompilationUnitWithPythonModule()); + f(function2InCompilationUnitWithPythonModule()); + f(function2InCompilationUnitWithPythonModule()); +} diff --git a/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input.py b/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input.py new file mode 100644 index 000000000..4283f3f54 --- /dev/null +++ b/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input.py @@ -0,0 +1,16 @@ +# Imports ---------------------------------------------------------------------- + +from special_location import function1InCompilationUnitWithPythonModule, function2InCompilationUnitWithPythonModule +from tests.generator.differentPackageWildcard import function1InDifferentPackage, function2InDifferentPackage + +# Pipelines -------------------------------------------------------------------- + +def test(): + f(function1InDifferentPackage()) + f(function1InDifferentPackage()) + f(function2InDifferentPackage()) + f(function2InDifferentPackage()) + f(function1InCompilationUnitWithPythonModule()) + f(function1InCompilationUnitWithPythonModule()) + f(function2InCompilationUnitWithPythonModule()) + f(function2InCompilationUnitWithPythonModule()) diff --git a/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input_test.py b/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input_test.py new file mode 100644 index 000000000..30abe031d --- /dev/null +++ b/tests/resources/generation/imports/wildcard/output/tests/generator/wildcard/gen_input_test.py @@ -0,0 +1,4 @@ +from gen_input import test + +if __name__ == '__main__': + test() diff --git a/tests/resources/generation/skip-python module/input.sdstest b/tests/resources/generation/python module/input.sdstest similarity index 100% rename from tests/resources/generation/skip-python module/input.sdstest rename to tests/resources/generation/python module/input.sdstest diff --git a/tests/resources/generation/skip-python module/output/special_module/gen_input.py b/tests/resources/generation/python module/output/special_module/gen_input.py similarity index 100% rename from tests/resources/generation/skip-python module/output/special_module/gen_input.py rename to tests/resources/generation/python module/output/special_module/gen_input.py diff --git a/tests/resources/generation/skip-declarations/parameter with python name/input.sdstest b/tests/resources/generation/skip-declarations/parameter with python name/input.sdstest deleted file mode 100644 index 860e98ece..000000000 --- a/tests/resources/generation/skip-declarations/parameter with python name/input.sdstest +++ /dev/null @@ -1,14 +0,0 @@ -package tests.generator.parameterWithPythonName - -fun f1(param: (a: Int, b: Int, c: Int) -> r: Int) -fun f2(param: (a: Int, b: Int, c: Int) -> ()) - -segment test1(param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_3") param3: Int = 0) { - f1((param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_3") param3: Int = 0) -> 1); - f2((param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_3") param3: Int = 0) {}); -} - -segment test2(param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_4") vararg param4: Int) { - f1((param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_4") vararg param4: Int) -> 1); - f2((param1: Int, @PythonName("param_2") param2: Int, @PythonName("param_4") vararg param4: Int) {}); -} diff --git a/tests/resources/generation/skip-declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py b/tests/resources/generation/skip-declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py deleted file mode 100644 index 5a04fef8f..000000000 --- a/tests/resources/generation/skip-declarations/parameter with python name/output/tests/generator/parameterWithPythonName/gen_input.py +++ /dev/null @@ -1,13 +0,0 @@ -# Steps ------------------------------------------------------------------------ - -def test1(param1, param_2, param_3=0): - f1(lambda param1, param_2, param_3=0: 1) - def __block_lambda_0(param1, param_2, param_3=0): - pass - f2(__block_lambda_0) - -def test2(param1, param_2, *param_4): - f1(lambda param1, param_2, *param_4: 1) - def __block_lambda_0(param1, param_2, *param_4): - pass - f2(__block_lambda_0) diff --git a/tests/resources/generation/skip-expressions/block lambda/output/tests/generator/blockLambda/gen_input.py b/tests/resources/generation/skip-expressions/block lambda/output/tests/generator/blockLambda/gen_input.py deleted file mode 100644 index 57e2b1fcf..000000000 --- a/tests/resources/generation/skip-expressions/block lambda/output/tests/generator/blockLambda/gen_input.py +++ /dev/null @@ -1,14 +0,0 @@ -# Pipelines -------------------------------------------------------------------- - -def test(): - def __block_lambda_0(a, b=2): - d = g() - return d - f1(__block_lambda_0) - def __block_lambda_1(a, *c): - d = g() - return d - f2(__block_lambda_1) - def __block_lambda_2(): - pass - f3(__block_lambda_2) diff --git a/tests/resources/generation/skip-expressions/call/input.sdstest b/tests/resources/generation/skip-expressions/call/input.sdstest deleted file mode 100644 index 655b2e2a7..000000000 --- a/tests/resources/generation/skip-expressions/call/input.sdstest +++ /dev/null @@ -1,32 +0,0 @@ -package tests.generator.call - -fun f(param: Any?) - -fun g1( - param1: Int, - param2: Int = 0 -) -> result: Boolean - -fun g2( - param1: Int, - vararg param3: Int -) -> result: Boolean - -fun h1( - @PythonName("param_1") param1: Int, - @PythonName("param_2") param2: Int = 0 -) -> result: Boolean - -fun h2( - @PythonName("param_1") param1: Int, - @PythonName("param_3") vararg param3: Int -) -> result: Boolean - -pipeline test { - f((g1(1, 2))); - f((g1(param2 = 1, param1 = 2))); - f((g2(2, 3, 4))); - f((h1(1, 2))); - f((h1(param2 = 1, param1 = 2))); - f((h2(2, 3, 4))); -} diff --git a/tests/resources/generation/skip-expressions/call/output/tests/generator/call/gen_input.py b/tests/resources/generation/skip-expressions/call/output/tests/generator/call/gen_input.py deleted file mode 100644 index 37634f44a..000000000 --- a/tests/resources/generation/skip-expressions/call/output/tests/generator/call/gen_input.py +++ /dev/null @@ -1,9 +0,0 @@ -# Pipelines -------------------------------------------------------------------- - -def test(): - f(g1(1, param2=2)) - f(g1(2, param2=1)) - f(g2(2, 3, 4)) - f(h1(1, param_2=2)) - f(h1(2, param_2=1)) - f(h2(2, 3, 4)) diff --git a/tests/resources/generation/skip-expressions/expression lambda/input.sdstest b/tests/resources/generation/skip-expressions/expression lambda/input.sdstest deleted file mode 100644 index 6d49a6ce7..000000000 --- a/tests/resources/generation/skip-expressions/expression lambda/input.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.generator.expressionLambda - -fun f1(param: (a: Int, b: Int) -> r: Int) -fun f2(param: (a: Int, vararg c: Int) -> r: Int) - -pipeline test { - f1((a, b = 2) -> 1); - f2((a, vararg c) -> 1); -} diff --git a/tests/resources/generation/skip-imports/output/tests/generator/imports/gen__skip__context_same_package.py b/tests/resources/generation/skip-imports/output/tests/generator/imports/gen__skip__context_same_package.py deleted file mode 100644 index 4f69c70b4..000000000 --- a/tests/resources/generation/skip-imports/output/tests/generator/imports/gen__skip__context_same_package.py +++ /dev/null @@ -1,9 +0,0 @@ -# Steps ------------------------------------------------------------------------ - -def step1InSamePackage(): - result = impureFunction() - return result - -def step2InSamePackage(): - result = impureFunction() - return result diff --git a/tests/resources/generation/skip-statements/assignment/input.sdstest b/tests/resources/generation/statements/assignment/input.sdstest similarity index 100% rename from tests/resources/generation/skip-statements/assignment/input.sdstest rename to tests/resources/generation/statements/assignment/input.sdstest diff --git a/tests/resources/generation/skip-statements/assignment/output/tests/generator/assignment/gen_input.py b/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py similarity index 54% rename from tests/resources/generation/skip-statements/assignment/output/tests/generator/assignment/gen_input.py rename to tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py index 8c24c2309..d98f68403 100644 --- a/tests/resources/generation/skip-statements/assignment/output/tests/generator/assignment/gen_input.py +++ b/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input.py @@ -1,32 +1,26 @@ -# Imports ---------------------------------------------------------------------- - -import runtimeBridge - # Steps ------------------------------------------------------------------------ def testStep(): g() - a, _, c = g() + a, _, __gen_yield_c = g() x, _, _ = g() f1(a) f1(x) - return c + return __gen_yield_c # Pipelines -------------------------------------------------------------------- def testPipeline(): g() a, _, _ = g() - runtimeBridge.save_placeholder('a', a) x, _, _ = g() - runtimeBridge.save_placeholder('x', x) f1(a) f1(x) - def __block_lambda_0(): + def __gen_block_lambda_0(): g() - a, _, c = g() + a, _, __gen_block_lambda_result_c = g() x, _, _ = g() f1(a) f1(x) - return c - f2(__block_lambda_0) + return __gen_block_lambda_result_c + f2(__gen_block_lambda_0) diff --git a/tests/resources/generation/skip-statements/assignment/output/tests/generator/assignment/gen_input_testPipeline.py b/tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input_testPipeline.py similarity index 100% rename from tests/resources/generation/skip-statements/assignment/output/tests/generator/assignment/gen_input_testPipeline.py rename to tests/resources/generation/statements/assignment/output/tests/generator/assignment/gen_input_testPipeline.py diff --git a/tests/resources/generation/skip-statements/expression statement/input.sdstest b/tests/resources/generation/statements/expression statement/input.sdstest similarity index 100% rename from tests/resources/generation/skip-statements/expression statement/input.sdstest rename to tests/resources/generation/statements/expression statement/input.sdstest diff --git a/tests/resources/generation/skip-statements/expression statement/output/tests/generator/expressionStatement/gen_input.py b/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py similarity index 79% rename from tests/resources/generation/skip-statements/expression statement/output/tests/generator/expressionStatement/gen_input.py rename to tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py index f77b73f00..117709000 100644 --- a/tests/resources/generation/skip-statements/expression statement/output/tests/generator/expressionStatement/gen_input.py +++ b/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input.py @@ -7,6 +7,6 @@ def testStep(): def testPipeline(): g() - def __block_lambda_0(): + def __gen_block_lambda_0(): g() - f(__block_lambda_0) + f(__gen_block_lambda_0) diff --git a/tests/resources/generation/skip-statements/expression statement/output/tests/generator/expressionStatement/gen_input_testPipeline.py b/tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input_testPipeline.py similarity index 100% rename from tests/resources/generation/skip-statements/expression statement/output/tests/generator/expressionStatement/gen_input_testPipeline.py rename to tests/resources/generation/statements/expression statement/output/tests/generator/expressionStatement/gen_input_testPipeline.py diff --git a/tests/resources/generation/skip-statements/statement without effect/input.sdstest b/tests/resources/generation/statements/skip-statement without effect/input.sdstest similarity index 100% rename from tests/resources/generation/skip-statements/statement without effect/input.sdstest rename to tests/resources/generation/statements/skip-statement without effect/input.sdstest diff --git a/tests/resources/generation/skip-statements/statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py b/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py similarity index 78% rename from tests/resources/generation/skip-statements/statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py rename to tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py index 85e9e98ee..2cde3391a 100644 --- a/tests/resources/generation/skip-statements/statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py +++ b/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input.py @@ -6,6 +6,6 @@ def testStep(): # Pipelines -------------------------------------------------------------------- def testPipeline(): - def __block_lambda_0(): + def __gen_block_lambda_0(): pass - f(__block_lambda_0) + f(__gen_block_lambda_0) diff --git a/tests/resources/generation/skip-statements/statement without effect/output/tests/generator/statementWithoutEffect/gen_input_testPipeline.py b/tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input_testPipeline.py similarity index 100% rename from tests/resources/generation/skip-statements/statement without effect/output/tests/generator/statementWithoutEffect/gen_input_testPipeline.py rename to tests/resources/generation/statements/skip-statement without effect/output/tests/generator/statementWithoutEffect/gen_input_testPipeline.py diff --git a/tests/resources/validation/names/__block_lambda_ prefix/annotations.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/annotations.sdstest deleted file mode 100644 index d6e72e88b..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/annotations.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -annotation »__block_lambda_0« - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -annotation »_block_lambda_1« diff --git a/tests/resources/validation/names/__block_lambda_ prefix/attributes.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/attributes.sdstest deleted file mode 100644 index c00524d6f..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/attributes.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -class MyClass { - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - attr »__block_lambda_0«: Int - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - attr »_block_lambda_1«: Int -} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/block lambda results.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/block lambda results.sdstest deleted file mode 100644 index 35cc49624..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/block lambda results.sdstest +++ /dev/null @@ -1,11 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -pipeline myPipeline2 { - () { - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - yield »__block_lambda_0« = 1; - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - yield »_block_lambda_1« = 1; - }; -} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/classes.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/classes.sdstest deleted file mode 100644 index b1a513e91..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/classes.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -class »__block_lambda_0« - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -class »_block_lambda_1« diff --git a/tests/resources/validation/names/__block_lambda_ prefix/enum variants.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/enum variants.sdstest deleted file mode 100644 index 096504548..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/enum variants.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -enum MyEnum { - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »__block_lambda_0« - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »_block_lambda_1« -} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/enums.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/enums.sdstest deleted file mode 100644 index fe820ae01..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/enums.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -enum »__block_lambda_0« - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -enum »_block_lambda_1« diff --git a/tests/resources/validation/names/__block_lambda_ prefix/functions.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/functions.sdstest deleted file mode 100644 index 9c99c5a4b..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/functions.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -fun »__block_lambda_0«() - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -fun »_block_lambda_1«() diff --git a/tests/resources/validation/names/__block_lambda_ prefix/no package name.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/no package name.sdstest deleted file mode 100644 index ef31d98d5..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/no package name.sdstest +++ /dev/null @@ -1 +0,0 @@ -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." diff --git a/tests/resources/validation/names/__block_lambda_ prefix/package name with block lambda prefix.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/package name with block lambda prefix.sdstest deleted file mode 100644 index 4c00c1f81..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/package name with block lambda prefix.sdstest +++ /dev/null @@ -1,2 +0,0 @@ -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -package »__block_lambda_0« diff --git a/tests/resources/validation/names/__block_lambda_ prefix/package name without block lambda prefix.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/package name without block lambda prefix.sdstest deleted file mode 100644 index d09e0f930..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/package name without block lambda prefix.sdstest +++ /dev/null @@ -1,2 +0,0 @@ -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -package »_block_lambda_1« diff --git a/tests/resources/validation/names/__block_lambda_ prefix/parameters.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/parameters.sdstest deleted file mode 100644 index 9fbf21acd..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/parameters.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -fun myFunction1( - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »__block_lambda_0«: Int, - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »_block_lambda_1«: Int, -) diff --git a/tests/resources/validation/names/__block_lambda_ prefix/pipelines.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/pipelines.sdstest deleted file mode 100644 index fc10c0a35..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/pipelines.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -pipeline »__block_lambda_0« {} - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -pipeline »_block_lambda_1« {} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/placeholders.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/placeholders.sdstest deleted file mode 100644 index 92fd70ff9..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/placeholders.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -pipeline myPipeline1 { - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - val »__block_lambda_0« = 1; - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - val »_block_lambda_1« = 1; -} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/results.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/results.sdstest deleted file mode 100644 index 82d3f06c3..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/results.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -fun myFunction2() -> ( - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »__block_lambda_0«: Int, - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »_block_lambda_1«: Int, -) diff --git a/tests/resources/validation/names/__block_lambda_ prefix/schemas.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/schemas.sdstest deleted file mode 100644 index b39f5072d..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/schemas.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -schema »__block_lambda_0« {} - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -schema »_block_lambda_1« {} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/segments.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/segments.sdstest deleted file mode 100644 index 51e23ce62..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/segments.sdstest +++ /dev/null @@ -1,7 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -// $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -segment »__block_lambda_0«() {} - -// $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." -segment »_block_lambda_1«() {} diff --git a/tests/resources/validation/names/__block_lambda_ prefix/type parameters.sdstest b/tests/resources/validation/names/__block_lambda_ prefix/type parameters.sdstest deleted file mode 100644 index 5503e2cf3..000000000 --- a/tests/resources/validation/names/__block_lambda_ prefix/type parameters.sdstest +++ /dev/null @@ -1,9 +0,0 @@ -package tests.validation.names.blockLambdaPrefix - -fun myFunction3< - // $TEST$ error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »__block_lambda_0«, - - // $TEST$ no error "Names of declarations must not start with '__block_lambda_'. This is reserved for code generation of block lambdas." - »_block_lambda_1«, ->() diff --git a/tests/resources/validation/names/codegen prefix/annotations.sdstest b/tests/resources/validation/names/codegen prefix/annotations.sdstest new file mode 100644 index 000000000..2f1ed5138 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/annotations.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +annotation »__gen_0« + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +annotation »_gen_1« diff --git a/tests/resources/validation/names/codegen prefix/attributes.sdstest b/tests/resources/validation/names/codegen prefix/attributes.sdstest new file mode 100644 index 000000000..410cd1004 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/attributes.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +class MyClass { + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + attr »__gen_0«: Int + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + attr »_gen_1«: Int +} diff --git a/tests/resources/validation/names/codegen prefix/block lambda results.sdstest b/tests/resources/validation/names/codegen prefix/block lambda results.sdstest new file mode 100644 index 000000000..dcb4646b5 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/block lambda results.sdstest @@ -0,0 +1,11 @@ +package tests.validation.names.blockLambdaPrefix + +pipeline myPipeline2 { + () { + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + yield »__gen_0« = 1; + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + yield »_gen_1« = 1; + }; +} diff --git a/tests/resources/validation/names/codegen prefix/classes.sdstest b/tests/resources/validation/names/codegen prefix/classes.sdstest new file mode 100644 index 000000000..d7e77027e --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/classes.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +class »__gen_0« + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +class »_gen_1« diff --git a/tests/resources/validation/names/codegen prefix/enum variants.sdstest b/tests/resources/validation/names/codegen prefix/enum variants.sdstest new file mode 100644 index 000000000..d69569bd0 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/enum variants.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +enum MyEnum { + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »__gen_0« + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »_gen_1« +} diff --git a/tests/resources/validation/names/codegen prefix/enums.sdstest b/tests/resources/validation/names/codegen prefix/enums.sdstest new file mode 100644 index 000000000..c549ec75f --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/enums.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +enum »__gen_0« + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +enum »_gen_1« diff --git a/tests/resources/validation/names/codegen prefix/functions.sdstest b/tests/resources/validation/names/codegen prefix/functions.sdstest new file mode 100644 index 000000000..bdd235e7e --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/functions.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +fun »__gen_0«() + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +fun »_gen_1«() diff --git a/tests/resources/validation/names/codegen prefix/no package name.sdstest b/tests/resources/validation/names/codegen prefix/no package name.sdstest new file mode 100644 index 000000000..961d17e5d --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/no package name.sdstest @@ -0,0 +1 @@ +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." diff --git a/tests/resources/validation/names/codegen prefix/package name with block lambda prefix.sdstest b/tests/resources/validation/names/codegen prefix/package name with block lambda prefix.sdstest new file mode 100644 index 000000000..72430e42b --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/package name with block lambda prefix.sdstest @@ -0,0 +1,2 @@ +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +package »__gen_0« diff --git a/tests/resources/validation/names/codegen prefix/package name without block lambda prefix.sdstest b/tests/resources/validation/names/codegen prefix/package name without block lambda prefix.sdstest new file mode 100644 index 000000000..56bc1da44 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/package name without block lambda prefix.sdstest @@ -0,0 +1,2 @@ +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +package »_gen_1« diff --git a/tests/resources/validation/names/codegen prefix/parameters.sdstest b/tests/resources/validation/names/codegen prefix/parameters.sdstest new file mode 100644 index 000000000..6fc81e57d --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/parameters.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +fun myFunction1( + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »__gen_0«: Int, + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »_gen_1«: Int, +) diff --git a/tests/resources/validation/names/codegen prefix/pipelines.sdstest b/tests/resources/validation/names/codegen prefix/pipelines.sdstest new file mode 100644 index 000000000..e5da70f5b --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/pipelines.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +pipeline »__gen_0« {} + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +pipeline »_gen_1« {} diff --git a/tests/resources/validation/names/codegen prefix/placeholders.sdstest b/tests/resources/validation/names/codegen prefix/placeholders.sdstest new file mode 100644 index 000000000..7bb4abb1d --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/placeholders.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +pipeline myPipeline1 { + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + val »__gen_0« = 1; + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + val »_gen_1« = 1; +} diff --git a/tests/resources/validation/names/codegen prefix/results.sdstest b/tests/resources/validation/names/codegen prefix/results.sdstest new file mode 100644 index 000000000..654e3798d --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/results.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +fun myFunction2() -> ( + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »__gen_0«: Int, + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »_gen_1«: Int, +) diff --git a/tests/resources/validation/names/codegen prefix/schemas.sdstest b/tests/resources/validation/names/codegen prefix/schemas.sdstest new file mode 100644 index 000000000..7ec0a8ad0 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/schemas.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +schema »__gen_0« {} + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +schema »_gen_1« {} diff --git a/tests/resources/validation/names/codegen prefix/segments.sdstest b/tests/resources/validation/names/codegen prefix/segments.sdstest new file mode 100644 index 000000000..fe7c64e41 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/segments.sdstest @@ -0,0 +1,7 @@ +package tests.validation.names.blockLambdaPrefix + +// $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +segment »__gen_0«() {} + +// $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." +segment »_gen_1«() {} diff --git a/tests/resources/validation/names/codegen prefix/type parameters.sdstest b/tests/resources/validation/names/codegen prefix/type parameters.sdstest new file mode 100644 index 000000000..71f700288 --- /dev/null +++ b/tests/resources/validation/names/codegen prefix/type parameters.sdstest @@ -0,0 +1,9 @@ +package tests.validation.names.blockLambdaPrefix + +fun myFunction3< + // $TEST$ error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »__gen_0«, + + // $TEST$ no error "Names of declarations must not start with '__gen_'. This is reserved for code generation." + »_gen_1«, +>()