From 3c5277ded28d3e83593efb1e7dd1472f0a8b12bc Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Thu, 20 Mar 2025 02:49:17 +0100 Subject: [PATCH] More nested macro tests Add error case tests to enforce macro start position requirements Include nested macro parsing scenarios and invalid syntax checks Ensures parser correctly handles edge cases with embedded macros --- tests/frontend/MacroParser.test.js | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/frontend/MacroParser.test.js b/tests/frontend/MacroParser.test.js index 62a3ee3ba..ac92f0101 100644 --- a/tests/frontend/MacroParser.test.js +++ b/tests/frontend/MacroParser.test.js @@ -78,6 +78,20 @@ describe('MacroParser', () => { expect(macroCst).toBeUndefined(); expect(errors).toEqual(expectedErrors); }); + + // something{{user}} + // something{{user}} + it('[Error] for testing purposes, macros need to start at the beginning of the string', async () => { + const input = 'something{{user}}'; + const { macroCst, errors } = await runParserAndGetErrors(input); + + const expectedErrors = [ + { name: 'MismatchedTokenException', message: 'Expecting token of type --> Macro.Start <-- but found --> \'something\' <--' }, + ]; + + expect(macroCst).toBeUndefined(); + expect(errors).toEqual(expectedErrors); + }); }); }); @@ -222,6 +236,54 @@ describe('MacroParser', () => { 'Macro.End': '}}', }); }); + + it('should parse two nested macros next to each other inside an argument', async () => { + const input = '{{outer::word {{inner1}}{{inner2}}}}'; + const macroCst = await runParser(input, {}); + expect(macroCst).toEqual({ + 'Macro.Start': '{{', + 'Macro.Identifier': 'outer', + 'arguments': { + 'argument': { + 'Identifier': 'word', + 'macro': [ + { + 'Macro.Start': '{{', + 'Macro.Identifier': 'inner1', + 'Macro.End': '}}', + }, + { + 'Macro.Start': '{{', + 'Macro.Identifier': 'inner2', + 'Macro.End': '}}', + }, + ], + }, + 'separator': '::', + }, + 'Macro.End': '}}', + }); + }); + + describe('Error Cases (Nested Macros)', () => { + + it('[Error] should throw when there is a nested macro instead of an identifier', async () => { + const input = '{{{{macroindentifier}}::value}}'; + const { macroCst, errors } = await runParserAndGetErrors(input); + + expect(macroCst).toBeUndefined(); + expect(errors).toHaveLength(1); // error doesn't really matter. Just don't parse it pls. + }); + + it('[Error] should throw when there is a macro inside an identifier', async () => { + const input = '{{inside{{macro}}me}}'; + const { macroCst, errors } = await runParserAndGetErrors(input); + + expect(macroCst).toBeUndefined(); + expect(errors).toHaveLength(1); // error doesn't really matter. Just don't parse it pls. + }); + + }); }); });