This commit is contained in:
TheGiddyLimit
2024-03-10 21:53:34 +00:00
parent b323d4123e
commit f00d1f3833
272 changed files with 24017 additions and 9350 deletions

View File

@@ -0,0 +1,67 @@
import "../../js/parser.js";
import "../../js/utils.js";
import "../../js/render.js";
describe("Splitting by tags", () => {
it("Should handle a single tag", () => {
expect(Renderer.splitByTags("aa {@b bb} cc"))
.toStrictEqual([
"aa ",
"{@b bb}",
" cc",
]);
expect(Renderer.splitByTags("aa{@b bb}"))
.toStrictEqual([
"aa",
"{@b bb}",
]);
expect(Renderer.splitByTags("{@b bb}"))
.toStrictEqual([
"{@b bb}",
]);
expect(Renderer.splitByTags("{@h}"))
.toStrictEqual([
"{@h}",
]);
});
it("Should handle multiple tags", () => {
expect(Renderer.splitByTags("{@b {@i aaa} bb} {@b cc}"))
.toStrictEqual([
"{@b {@i aaa} bb}",
" ",
"{@b cc}",
]);
});
it("Should handle property injectors", () => {
expect(Renderer.splitByTags("{=amount1/v} {=amount2}"))
.toStrictEqual([
"{=amount1/v}",
" ",
"{=amount2}",
]);
expect(Renderer.splitByTags("{=amount1/v} {@unit {=amount1}|egg|eggs}"))
.toStrictEqual([
"{=amount1/v}",
" ",
"{@unit {=amount1}|egg|eggs}",
]);
});
it("Should handle non-tags", () => {
expect(Renderer.splitByTags("{@@a {@@b"))
.toStrictEqual([
"{@@a {@@b",
]);
expect(Renderer.splitByTags("{@}"))
.toStrictEqual([
"{@}",
]);
});
});

View File

@@ -0,0 +1,31 @@
import "../../js/parser.js";
import "../../js/utils.js";
import "../../js/render.js";
describe("Stripping tags", () => {
it("Should handle a single tag", () => {
expect(Renderer.stripTags("aa {@b bb} cc")).toBe("aa bb cc");
expect(Renderer.stripTags("aa{@b bb}")).toBe("aabb");
expect(Renderer.stripTags("{@b bb}")).toBe("bb");
expect(Renderer.stripTags("{@h}")).toBe("Hit: ");
});
it("Should handle multiple tags", () => {
expect(Renderer.stripTags("{@b {@i aaa} bb} {@b cc}")).toBe("aaa bb cc");
});
it("Should ignore property injectors", () => {
expect(Renderer.stripTags("{=amount1/v} {=amount2}")).toBe("{=amount1/v} {=amount2}");
expect(Renderer.stripTags("{=amount1/v} {@unit {=amount1}|egg|eggs}")).toBe("{=amount1/v} egg");
});
it("Should ignore tags in allowlist", () => {
expect(Renderer.stripTags("{@b {@i aaa} bb} {@b cc}", {allowlistTags: new Set(["@i"])})).toBe("{@i aaa} bb cc");
expect(Renderer.stripTags("{@b {@i aaa} bb} {@b cc}", {allowlistTags: new Set([])})).toBe("aaa bb cc");
});
it("Should only remove tags in blocklist", () => {
expect(Renderer.stripTags("{@b {@i aaa} bb} {@b cc}", {blocklistTags: new Set(["@b"])})).toBe("{@i aaa} bb cc");
expect(Renderer.stripTags("{@b {@i aaa} bb} {@b cc}", {blocklistTags: new Set([])})).toBe("{@b {@i aaa} bb} {@b cc}");
});
});