import { test, expect } from "bun:test";
import { escapeHtml, cssEscape } from "./dom";

test("escapeHtml escapes the five HTML-significant characters", () => {
  expect(escapeHtml(`<a href="x" title='y'>& z</a>`)).toBe(
    "&lt;a href=&quot;x&quot; title=&#39;y&#39;&gt;&amp; z&lt;/a&gt;",
  );
});

test("escapeHtml is a no-op on plain text", () => {
  expect(escapeHtml("Aktenzeichen 4c O 12/23")).toBe("Aktenzeichen 4c O 12/23");
});

test("escapeHtml escapes & first to avoid double-encoding", () => {
  expect(escapeHtml("&lt;")).toBe("&amp;lt;");
});

test("cssEscape backslash-escapes the dots in a placeholder key", () => {
  // Both CSS.escape and the regex fallback escape '.' the same way, so the
  // result is stable across environments (bun has no CSS global → fallback).
  expect(cssEscape("project.case_number")).toBe("project\\.case_number");
});

test("cssEscape leaves identifier-safe characters untouched", () => {
  expect(cssEscape("today")).toBe("today");
});
