Skip to content

Commit 07903b4

Browse files
committed
Add tests to alg visitor
1 parent df99d4c commit 07903b4

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

packages/septic/src/test/algParser.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AlgLiteral,
99
parseAlg,
1010
AlgUnary,
11+
AlgVisitor,
1112
} from "../alg";
1213

1314
describe("Test scanning of operators", () => {
@@ -462,3 +463,30 @@ describe("Test parsing of invalid algs", () => {
462463
expect(parse).to.not.throw();
463464
});
464465
});
466+
467+
describe("Test algVisitor", () => {
468+
it("Test extraction of variables in alg", () => {
469+
const input =
470+
"setmaxdn({{ Wellname }}ZpcNew, -abs({{ Wellname }}ZpcYWCD.Tests)/SPM)";
471+
const expr = parseAlg(input);
472+
const visitor = new AlgVisitor();
473+
visitor.visit(expr);
474+
expect(visitor.variables.length).to.equal(3);
475+
const variableNames = visitor.variables.map((v) => v.value);
476+
expect(variableNames).to.include("{{Wellname}}ZpcNew");
477+
expect(variableNames).to.include("{{Wellname}}ZpcYWCD.Tests");
478+
expect(variableNames).to.include("SPM");
479+
});
480+
it("Test extraction of variables in alg", () => {
481+
const input =
482+
"setmaxdn({{ Wellname }}ZpcNew, -abs({{ Wellname }}ZpcYWCD.Tests)/SPM) + min(10, -10)";
483+
const expr = parseAlg(input);
484+
const visitor = new AlgVisitor();
485+
visitor.visit(expr);
486+
expect(visitor.calcs.length).to.equal(3);
487+
const variableNames = visitor.calcs.map((v) => v.identifier);
488+
expect(variableNames).to.include("setmaxdn");
489+
expect(variableNames).to.include("abs");
490+
expect(variableNames).to.include("min");
491+
});
492+
});

0 commit comments

Comments
 (0)