UNPKG

@bitloops/bl-transpiler

Version:
93 lines 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mappings_js_1 = require("../../../src/helpers/mappings.js"); const index_js_1 = require("../../../src/parser/index.js"); const index_js_2 = require("../../../src/ast/core/index.js"); const index_js_3 = require("../../../src/parser/core/guards/index.js"); const index_js_4 = require("../../../src/ast/core/guards/index.js"); const struct_js_1 = require("./mocks/struct.js"); const types_js_1 = require("../../../src/parser/core/types.js"); const BOUNDED_CONTEXT = 'Hello World'; const MODULE = 'core'; describe('Struct declaration is valid', () => { let resultTree; const parser = new index_js_1.BitloopsParser(); const intermediateParser = new index_js_2.IntermediateASTParser(); struct_js_1.validStructDeclarationCases.forEach((testStructDeclaration) => { test(`${testStructDeclaration.description}`, () => { const initialModelOutput = parser.parse({ core: [ { boundedContext: BOUNDED_CONTEXT, module: MODULE, fileId: testStructDeclaration.fileId, fileContents: testStructDeclaration.inputBLString, }, ], }); if (!(0, index_js_3.isParserErrors)(initialModelOutput)) { const result = intermediateParser.parse(initialModelOutput); if (!(0, index_js_4.isIntermediateASTValidationErrors)(result)) { resultTree = result.core[BOUNDED_CONTEXT][MODULE]; } } const structDeclarationNodes = resultTree.getRootChildrenNodesByType(mappings_js_1.BitloopsTypesMapping.TStruct); const value = structDeclarationNodes[0].getValue(); expect(value).toMatchObject(testStructDeclaration.expected); expect(structDeclarationNodes.length).toBe(1); }); }); }); describe('Struct declaration is invalid', () => { const parser = new index_js_1.BitloopsParser(); struct_js_1.invalidStructDeclarationCases.forEach((testStruct) => { test(`${testStruct.description}`, () => { const initialModelOutput = parser.parse({ core: [ { boundedContext: BOUNDED_CONTEXT, module: MODULE, fileId: testStruct.fileId, fileContents: testStruct.inputBLString, }, ], }); expect(Array.isArray(initialModelOutput)).toBeTruthy(); if (!(0, index_js_3.isParserErrors)(initialModelOutput)) { throw new Error('Parser should return errors'); } initialModelOutput.forEach((error) => { expect(error).toBeInstanceOf(types_js_1.ParserSyntacticError); }); }); }); }); describe('Struct declaration with multiple structs is valid', () => { let resultTree; const parser = new index_js_1.BitloopsParser(); const intermediateParser = new index_js_2.IntermediateASTParser(); struct_js_1.validMultipleStructsTestCases.forEach((testDTO) => { test(`${testDTO.description}`, () => { const initialModelOutput = parser.parse({ core: [ { boundedContext: BOUNDED_CONTEXT, module: MODULE, fileId: testDTO.fileId, fileContents: testDTO.inputBLString, }, ], }); if (!(0, index_js_3.isParserErrors)(initialModelOutput)) { const result = intermediateParser.parse(initialModelOutput); if (!(0, index_js_4.isIntermediateASTValidationErrors)(result)) { resultTree = result.core[BOUNDED_CONTEXT][MODULE]; } } const structNodes = resultTree.getRootChildrenNodesByType(mappings_js_1.BitloopsTypesMapping.TStruct); const values = structNodes.map((node) => node.getValue()); expect(values).toMatchObject(testDTO.expected); }); }); }); //# sourceMappingURL=structDeclaration.steps.js.map