Skip to content

Commit adb58ad

Browse files
committed
Add additional tests for functions
1 parent 9b378f0 commit adb58ad

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

server/src/septic/septicFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function createFunctionFromNode(name: string, node: SepticFunctionNode, maxDepth
101101
if (visited.has(n)) return;
102102

103103
visited.add(n);
104-
if (maxDepth && depth == maxDepth) {
104+
if (maxDepth !== undefined && depth == maxDepth) {
105105
n.children.forEach((child) => {
106106
inputs.add(child.name);
107107
});

server/src/test/functions.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,52 @@ describe("SepticFunction", () => {
7272
expect(functions.length).to.equal(2);
7373

7474
});
75+
it("Expect only a single function with one line and two inputs when depth is set to 0", async () => {
76+
const text = `
77+
CalcModl: Test
78+
79+
CalcPvr: A
80+
Alg= "1+2"
81+
82+
CalcPvr: B
83+
Alg= "A + 1"
84+
85+
CalcPvr: C
86+
Text2= "#test(0)"
87+
Alg= "A * B"
88+
89+
`;
90+
const doc = new MockDocument(text);
91+
const cnfg = parseSepticSync(doc.getText());
92+
const functions = cnfg.getFunctions();
93+
expect(functions.length).to.equal(1);
94+
expect(functions[0].lines.length).to.equal(1);
95+
expect(functions[0].inputs.length).to.equal(2);
96+
});
97+
it("Expect only a single function with one line and two inputs when depth is set to 0", async () => {
98+
const text = `
99+
CalcModl: Test
100+
101+
CalcPvr: A
102+
Alg= "1+2"
103+
104+
CalcPvr: B
105+
Alg= "A + 1"
106+
107+
CalcPvr: C
108+
Alg= "A * B"
109+
110+
CalcPvr: D
111+
Text2= "#test(1)"
112+
Alg= "C + 1"
113+
114+
`;
115+
const doc = new MockDocument(text);
116+
const cnfg = parseSepticSync(doc.getText());
117+
const functions = cnfg.getFunctions();
118+
expect(functions.length).to.equal(1);
119+
expect(functions[0].lines.length).to.equal(2);
120+
expect(functions[0].inputs.length).to.equal(2);
121+
});
75122

76123
});

0 commit comments

Comments
 (0)