# test.web/core/normalizers/text.normalizer.test.ts

> 47 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-web-core-normalizers-text-normalizer-test-ts
Source text: https://banes-lab.com/source/testing/test.web/core/normalizers/text.normalizer.test.ts.txt

Listed in [test.web/core/normalizers](https://banes-lab.com/api/source/testing/test.web/core/normalizers.md), after [test.web/core/normalizers/markdown.normalizer.test.ts](https://banes-lab.com/source/testing/test.web/core/normalizers/markdown.normalizer.test.ts.md) and before [test.web/core/normalizers/word.normalizer.test.ts](https://banes-lab.com/source/testing/test.web/core/normalizers/word.normalizer.test.ts.md).

## Contained in

- [test.web/core/normalizers](https://banes-lab.com/anatomy/testing/folder-testing-test-web-core-normalizers.md)

## Source

````typescript
import { collapseBreaks, collapseSpaces, joinParts } from "@banes-lab/web/core/normalizers/text.normalizer.ts";
import { describe, expect, it } from "vitest";

describe("joinParts", () => {
    it("spaces two words that would otherwise touch, and two adjacent elements, and nothing else", () => {
        expect(
            joinParts([
                { element: false, text: "one" },
                { element: false, text: "two" },
            ]),
        ).toBe("one two");
        expect(
            joinParts([
                { element: false, text: "one" },
                { element: false, text: "." },
            ]),
        ).toBe("one.");
        expect(
            joinParts([
                { element: true, text: "(a)" },
                { element: true, text: "(b)" },
            ]),
        ).toBe("(a) (b)");
        expect(
            joinParts([
                { element: false, text: "one " },
                { element: false, text: "" },
                { element: false, text: "two" },
            ]),
        ).toBe("one two");
    });
});

describe("collapseSpaces", () => {
    it("folds every run of whitespace into one space and keeps a trailing one", () => {
        expect(collapseSpaces("a \n\t b ")).toBe("a b ");
        expect(collapseSpaces("plain")).toBe("plain");
    });
});

describe("collapseBreaks", () => {
    it("keeps at most one blank line, drops a space before a break and after one, and trims", () => {
        expect(collapseBreaks("\n a \n\n\n\n b \n")).toBe("a\n\nb");
        expect(collapseBreaks("x \ny")).toBe("x\ny");
    });

    it("keeps every line inside a code fence as it is, indentation and blank lines included", () => {
        const fence = "```yaml\nroot:\n    child: 1\n\n\n    other: 2\n```";
        expect(collapseBreaks(` text \n\n\n${fence}\n\n\n after`)).toBe(`text\n\n${fence}\n\nafter`);
    });
});
````
