|
| 1 | +/** |
| 2 | + * Bitloops Language CLI |
| 3 | + * Copyright (C) 2022 Bitloops S.A. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + * For further information you can contact legal(at)bitloops.com. |
| 19 | + */ |
| 20 | +import { IntermediateASTTree } from '../../../../src/ast/core/intermediate-ast/IntermediateASTTree.js'; |
| 21 | +import { IntermediateASTRootNode } from '../../../../src/ast/core/intermediate-ast/nodes/RootNode.js'; |
| 22 | +import { TargetGenerator } from '../../../../src/target/index.js'; |
| 23 | +import { SupportedLanguages } from '../../../../src/target/supportedLanguages.js'; |
| 24 | +import { TTargetCoreFinalContent } from '../../../../src/target/types.js'; |
| 25 | +import { formatString } from '../../../../src/target/typescript-nest/core/codeFormatting.js'; |
| 26 | +import { isTargetGeneratorError } from '../../../../src/target/typescript-nest/guards/index.js'; |
| 27 | +import { VALID_PACKAGE_EVALUATION_TEST_CASES } from './mocks/expression/evaluation.js'; |
| 28 | + |
| 29 | +describe('Valid package evaluation test cases', () => { |
| 30 | + const boundedContext = 'Hello world'; |
| 31 | + const module = 'demo'; |
| 32 | + const formatterConfig = null; |
| 33 | + const language = SupportedLanguages.TypeScriptNest; |
| 34 | + |
| 35 | + VALID_PACKAGE_EVALUATION_TEST_CASES.forEach((testCase) => { |
| 36 | + it(`${testCase.description}`, () => { |
| 37 | + let resultCore: TTargetCoreFinalContent[]; |
| 38 | + |
| 39 | + // given |
| 40 | + const tree = new IntermediateASTTree(new IntermediateASTRootNode()); |
| 41 | + const evaluation = testCase.evaluation; |
| 42 | + tree.insertChild(evaluation); |
| 43 | + |
| 44 | + const intermediateAST = { |
| 45 | + core: { [boundedContext]: { [module]: tree } }, |
| 46 | + }; |
| 47 | + |
| 48 | + // when |
| 49 | + const targetGenerator = new TargetGenerator(); |
| 50 | + const result = targetGenerator.generate(intermediateAST, { |
| 51 | + formatterConfig, |
| 52 | + targetLanguage: language, |
| 53 | + }); |
| 54 | + |
| 55 | + if (!isTargetGeneratorError(result)) { |
| 56 | + resultCore = result.core; |
| 57 | + } |
| 58 | + |
| 59 | + //then |
| 60 | + const formattedOutput = formatString(testCase.output as string, formatterConfig); |
| 61 | + if (result instanceof Error) { |
| 62 | + throw result; |
| 63 | + } |
| 64 | + expect(resultCore[0].fileContent).toEqual(formattedOutput); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments