@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
22 lines (16 loc) • 607 B
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
const testType =`
logic testType(lam : (Integer, Boolean) => Integer | Bool) {
let z : Integer | ( ) => Void | (Boolean) => Void;
}
`
describe('Test types', () => {
test('type', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(testType);
expect(parser.results.length).toBe(1);
expect(parser.results[0].cst[0].body.vars[0].ty['__type']).toBe('UnionType');
expect(parser.results[0].cst[0].body.vars[0].ty['tys'].length).toBe(2);
});
});