mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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
This commit is contained in:
@@ -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.
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user