48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
|
|
const { EftlParser } = require('../out/parser');
|
|
const { EftlTokenizer } = require('../out/tokenizer');
|
|
|
|
function parse(source) {
|
|
const { tokens, errors: tokenizerErrors } = new EftlTokenizer(source).tokenize();
|
|
assert.deepEqual(tokenizerErrors, []);
|
|
return new EftlParser(tokens).parse().errors;
|
|
}
|
|
|
|
test('accepts a correctly closed VAR tag', () => {
|
|
assert.deepEqual(parse('[VAR][/VAR]'), []);
|
|
});
|
|
|
|
test('reports a VAR tag without its closing tag', () => {
|
|
assert.deepEqual(parse('[VAR]'), [{
|
|
message: 'Unclosed tag: [VAR] (expected [/VAR])',
|
|
line: 1,
|
|
column: 1,
|
|
length: 5
|
|
}]);
|
|
});
|
|
|
|
test('reports an unexpected closing tag', () => {
|
|
const errors = parse('[/VAR]');
|
|
|
|
assert.equal(errors.length, 1);
|
|
assert.match(errors[0].message, /Unexpected closing tag/);
|
|
});
|
|
|
|
test('reports every unclosed nested tag at its opening token', () => {
|
|
assert.deepEqual(parse('[EFTL]\n[VAR]'), [
|
|
{
|
|
message: 'Unclosed tag: [EFTL] (expected [/EFTL])',
|
|
line: 1,
|
|
column: 1,
|
|
length: 6
|
|
},
|
|
{
|
|
message: 'Unclosed tag: [VAR] (expected [/VAR])',
|
|
line: 2,
|
|
column: 1,
|
|
length: 5
|
|
}
|
|
]);
|
|
}); |