Files
tailwind-ui-library/components/utils/normalize-text.test.ts
T
2026-10-01 08:02:47 +01:00

51 lines
1.6 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import twuiNormalizeText from "./normalize-text";
describe("twuiNormalizeText", () => {
test("collapses multiple spaces", () => {
expect(twuiNormalizeText("hello world")).toBe("hello world");
});
test("replaces newlines with spaces", () => {
expect(twuiNormalizeText("hello\nworld")).toBe("hello world");
});
test("replaces carriage returns with spaces", () => {
expect(twuiNormalizeText("hello\rworld")).toBe("hello world");
});
test("replaces CRLF with spaces", () => {
expect(twuiNormalizeText("hello\r\nworld")).toBe("hello world");
});
test("trims leading and trailing whitespace", () => {
expect(twuiNormalizeText(" hello world ")).toBe("hello world");
});
test("handles mixed whitespace", () => {
expect(twuiNormalizeText(" hello\n\n world \r\n ")).toBe("hello world");
});
test("handles empty string", () => {
expect(twuiNormalizeText("")).toBe("");
});
test("handles string with only whitespace", () => {
expect(twuiNormalizeText(" ")).toBe("");
});
test("preserves single spaces", () => {
expect(twuiNormalizeText("hello world")).toBe("hello world");
});
test("handles tabs as regular characters (not collapsed by default)", () => {
const result = twuiNormalizeText("hello\tworld");
expect(result).toContain("hello");
expect(result).toContain("world");
});
test("handles multiple consecutive newlines", () => {
expect(twuiNormalizeText("hello\n\n\nworld")).toBe("hello world");
});
});