@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
39 lines (32 loc) • 778 B
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
const testIf= `
logic testIf ( ) {
if (false && true) {
x = 1;
}
if (11 + 22) {
} else {
x = 2;
}
// 这是一个 if
if (3 + 2) {
b = 6
}
if (3 + 2) {
b = 6
abort
} else {
c = 124
}
}
`
describe('Test Logical Operations', () => {
test('Logic Operation and booleans', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(testIf);
expect(parser.results.length).toBe(1);
expect(parser.results[0].cst[0].body.stmts[0]['__type']).toBe("If");
expect(parser.results[0].cst[0].body.stmts[1]['finalElse'].length).toBe(1);
});
});