// font-families.test.mjs — the browser's family rule against the server's, // through the shared vectors (vectors/font-families.json, which // internal/slides/render/families_test.go reads too), and the section // reader the stage and the projector check a fetched slide with. import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { familiesOfView, familiesOfSection, familiesInStack, safeFontStack } from './font-families.mjs' const vectors = JSON.parse(readFileSync(new URL('./vectors/font-families.json', import.meta.url))) test('the shared vectors have cases to check', () => { assert.ok(vectors.cases.length >= 10) }) for (const c of vectors.cases) { test(`familiesOfView: ${c.name}`, () => { assert.deepEqual(familiesOfView(c.view, vectors.stacks), c.families) }) } test('a stack names a family wherever it appears, in any case, quoted or not', () => { assert.deepEqual(familiesInStack('Arial, "Liberation Serif", serif'), ['serif']) assert.deepEqual(familiesInStack("liberation mono, 'LIBERATION SANS'"), ['sans', 'mono']) assert.deepEqual(familiesInStack('Liberation Sans Narrow, sans-serif'), []) assert.deepEqual(familiesInStack(''), []) assert.deepEqual(familiesInStack(null), []) }) test('safeFontStack is render.go\'s allowlist', () => { assert.equal(safeFontStack(' Georgia, serif '), 'Georgia, serif') assert.equal(safeFontStack('url(x)'), '') assert.equal(safeFontStack('a; b'), '') assert.equal(safeFontStack('x'.repeat(201)), '') assert.equal(safeFontStack(7), '') }) // The reader with no DOM: the section's style attribute and whether it // holds code, the way sectionReader gets them from a