import { test } from 'node:test'; import assert from 'node:assert/strict'; import { escapeHtml, escapeAttr } from './dom.ts'; test('escapeHtml escapes all five HTML-special characters', () => { assert.equal(escapeHtml(`&`), '<a href="x" title='y'>&'); }); test('escapeHtml is ampersand-first (no double-escaping of entities it emits)', () => { // & must be replaced before <,>," so "<" is not re-escaped into "&lt;". assert.equal(escapeHtml('<'), '<'); assert.equal(escapeHtml('<'), '&lt;'); }); test('escapeHtml coerces non-strings', () => { assert.equal(escapeHtml(42), '42'); assert.equal(escapeHtml(null), 'null'); }); test('escapeAttr is the same escaper', () => { assert.equal(escapeAttr, escapeHtml); });