43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyPipeline,
|
|
textInventory,
|
|
type TransformStep,
|
|
} from "../../src/text/pipeline";
|
|
|
|
const step = (type: TransformStep["type"], option = ""): TransformStep => ({
|
|
id: type,
|
|
type,
|
|
option,
|
|
enabled: true,
|
|
});
|
|
describe("text pipelines", () => {
|
|
it("applies transformations in the declared order", () =>
|
|
expect(
|
|
applyPipeline(" b \nA\na", [
|
|
step("trim-lines"),
|
|
step("dedupe-lines"),
|
|
step("sort-lines", "en"),
|
|
]).output,
|
|
).toBe("a\nA\nb"));
|
|
it("keeps disabled steps out of the report", () =>
|
|
expect(
|
|
applyPipeline("A", [{ ...step("case", "lower"), enabled: false }]),
|
|
).toEqual({ output: "A", steps: [], warnings: [] }));
|
|
it("escapes HTML as data", () =>
|
|
expect(
|
|
applyPipeline("<img src=x onerror=1>", [step("escape", "html")]).output,
|
|
).toBe("<img src=x onerror=1>"));
|
|
it("reports lossy transliteration", () =>
|
|
expect(applyPipeline("Crème", [step("transliterate")]).warnings[0]).toMatch(
|
|
/lossy/u,
|
|
));
|
|
it("tracks exact line endings", () =>
|
|
expect(textInventory("a\r\nb\nc\r")).toMatchObject({
|
|
crlf: 1,
|
|
bareLf: 1,
|
|
bareCr: 1,
|
|
finalNewline: true,
|
|
}));
|
|
});
|