|
8 | 8 | AlgLiteral, |
9 | 9 | parseAlg, |
10 | 10 | AlgUnary, |
| 11 | + AlgVisitor, |
11 | 12 | } from "../alg"; |
12 | 13 |
|
13 | 14 | describe("Test scanning of operators", () => { |
@@ -462,3 +463,30 @@ describe("Test parsing of invalid algs", () => { |
462 | 463 | expect(parse).to.not.throw(); |
463 | 464 | }); |
464 | 465 | }); |
| 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