import { expect, test } from "bun:test"; import { decodeEntities, findTags, metaContent, parseAttributes, textOf } from "../src/core/html"; test("decodes named and numeric entities", () => { expect(decodeEntities("a & b <c> "d" 'e' 'f' &bogus;")).toBe(`a & b "d" 'e' 'f' &bogus;`); }); test("parses attributes in any order and quoting style", () => { expect(parseAttributes(``)) .toEqual({ content: "x&y", property: "og:image", "data-a": "1", hidden: "" }); expect(parseAttributes(`
`).style) .toBe("background:url('https://a/b.jpg') repeat-x"); }); test("finds tags and meta content by property or name", () => { const html = ``; expect(findTags(html, "meta")).toHaveLength(2); expect(metaContent(html, "og:image")).toBe("o.jpg"); expect(metaContent(html, "twitter:image")).toBe("t.jpg"); expect(metaContent(html, "og:title")).toBeUndefined(); }); test("textOf strips tags and collapses whitespace", () => { expect(textOf("Tower\n of & God ")).toBe("Tower of & God"); });