UNPKG

@lcap/nasl-parser

Version:

Take Nasl text to Nasl AST with the help of generalized parsing.

27 lines (22 loc) 827 B
import { Parser, Grammar } from "nearley"; import grammar from "../../ts/nasl"; const testSwitch = ` logic testSwitch() { switch { 1 == 1 => { end; } true => { end; } _ => { end; } }; } ` describe('Test Assignment', () => { test('Single and batch assignment', async () => { const parser = new Parser(Grammar.fromCompiled(grammar)); parser.feed(testSwitch); expect(parser.results.length).toBe(1); expect(parser.results[0].cst[0].body.stmts[0]['__type']).toBe("Switch"); expect(parser.results[0].cst[0].body.stmts[0]['cases'].length).toBe(3); expect(parser.results[0].cst[0].body.stmts[0]['cases'][1]['__type']).toBe('SwitchCase'); expect(parser.results[0].cst[0].body.stmts[0]['cases'][2]['__type']).toBe('SwitchCase'); }); });