@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
27 lines (22 loc) • 979 B
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
import { toNaslAST } from "../../ts/toAST/to-nasl-ast";
const testStrIntp =`
logic testStrIntp ( ) {
let zmc = s" 123 \${xy - 1} abc ";
}`
describe('String interpolation AST', () => {
test('String interpolation AST', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(testStrIntp);
expect(parser.results.length).toBe(1);
const nasl = toNaslAST(parser.results[0].nasl);
expect(nasl.logics[0].variables[0].name).toBe('zmc');
// @ts-ignore
expect(nasl.logics[0].variables[0].defaultValue.expression.expressions.length).toBe(3);
// @ts-ignore
expect(nasl.logics[0].variables[0].defaultValue.expression.expressions[0].value).toBe(' 123 ');
// @ts-ignore
expect(nasl.logics[0].variables[0].defaultValue.expression.expressions[2].value).toBe(' abc ');
});
});