-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathevaluation-utils.test.ts
More file actions
51 lines (46 loc) · 1.52 KB
/
evaluation-utils.test.ts
File metadata and controls
51 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { getFunctionBody, replaceMultipleStrings } from "./evaluation-utils";
describe("evaluation-utils", () => {
describe("getFunctionBody", () => {
it("returns inner statements without the wrapping function braces", () => {
const fn = function example() {
const n = 1;
return n + 1;
};
const body = getFunctionBody(fn);
expect(body).toContain("const n = 1");
expect(body).toContain("return n + 1");
expect(body.trim().startsWith("function")).toBe(false);
});
it("strips line comments from the serialized function", () => {
const fn = function withComment() {
// should disappear
return 42;
};
const body = getFunctionBody(fn);
expect(body).not.toMatch(/\/\/ should disappear/);
expect(body).toContain("return 42");
});
it("strips block comments from the serialized function", () => {
const fn = function withBlock() {
/* block */
return 7;
};
const body = getFunctionBody(fn);
expect(body).not.toMatch(/\/\* block \*\//);
expect(body).toContain("return 7");
});
});
describe("replaceMultipleStrings", () => {
it("applies each replacement in order", () => {
expect(
replaceMultipleStrings("alpha beta", {
alpha: "A",
beta: "B",
})
).toBe("A B");
});
it("only replaces the first occurrence per search string (non-global)", () => {
expect(replaceMultipleStrings("x x", { x: "y" })).toBe("y x");
});
});
});