UNPKG

@bitloops/bl-transpiler

Version:
38 lines 1.94 kB
import { BitloopsTypesMapping } from '../../../src/helpers/mappings.js'; import { BitloopsParser } from '../../../src/parser/index.js'; import { IntermediateASTParser } from '../../../src/ast/core/index.js'; import { isParserErrors } from '../../../src/parser/core/guards/index.js'; import { isIntermediateASTValidationErrors } from '../../../src/ast/core/guards/index.js'; import { validVariableDeclarationCases } from './mocks/statements/variableDeclaration.js'; const BOUNDED_CONTEXT = 'Hello World'; const MODULE = 'core'; describe('Variable declaration is valid', () => { let resultTree; const parser = new BitloopsParser(); const intermediateParser = new IntermediateASTParser(); validVariableDeclarationCases.forEach((testVariableDeclaration) => { test(`${testVariableDeclaration.description}`, () => { const initialModelOutput = parser.parse({ core: [ { boundedContext: BOUNDED_CONTEXT, module: MODULE, fileId: testVariableDeclaration.fileId, fileContents: testVariableDeclaration.inputBLString, }, ], }); if (!isParserErrors(initialModelOutput)) { const result = intermediateParser.parse(initialModelOutput); if (!isIntermediateASTValidationErrors(result)) { resultTree = result.core[BOUNDED_CONTEXT][MODULE]; } } const variableDeclarationNodes = resultTree.getRootChildrenNodesByType(BitloopsTypesMapping.TVariableDeclaration); const value = variableDeclarationNodes[0].getValue(); expect(value).toMatchObject(testVariableDeclaration.expected); expect(variableDeclarationNodes.length).toBe(1); }); }); }); //# sourceMappingURL=variableDeclaration.steps.js.map