oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1// fixtures/fonts.test.mjs — the font vocabulary, as the editor sees it.
2// internal/fonts' own tests hold the same manifest from the Go side.
3import { test } from 'node:test'
4import assert from 'node:assert/strict'
5import { FONTS, FONT_MARKS, DEFAULT_FONT, CODE_FONT, FAMILIES, fontMark, fontForMarks, fontKeysIn } from './fonts.mjs'
6
7test('the picker offers the sixteen families, Carlito and Caladea first', () => {
8 assert.deepEqual(FONTS, [
9 'carlito', 'caladea', 'inter', 'sourcesans', 'plexsans', 'sourceserif', 'literata', 'garamond',
10 'sans', 'serif', 'mono', 'notosans', 'zilla', 'jetbrains', 'playfair', 'caveat',
11 ])
12 assert.equal(FONT_MARKS.length, 16)
13})
14
15test('an unmarked run is Carlito', () => {
16 assert.equal(DEFAULT_FONT, 'carlito')
17 assert.equal(fontForMarks([]), 'carlito')
18 assert.equal(fontForMarks(['strong', 'size_14']), 'carlito')
19})
20
21test('code is Liberation Mono', () => {
22 assert.equal(CODE_FONT, 'mono')
23})
24
25test('choosing the default clears the mark rather than setting one', () => {
26 assert.equal(fontMark('carlito'), null)
27})
28
29test('choosing another family sets its mark, Liberation keeping its old keys', () => {
30 assert.equal(fontMark('caladea'), 'font_caladea')
31 assert.equal(fontMark('sans'), 'font_sans')
32 assert.equal(fontMark('serif'), 'font_serif')
33 assert.equal(fontMark('mono'), 'font_mono')
34})
35
36test('a face this build does not know is not an instruction to clear', () => {
37 assert.equal(fontMark('comic'), undefined)
38 assert.equal(fontMark(''), undefined)
39 assert.equal(fontMark('constructor'), undefined)
40})
41
42test('every font mark reads back as its own family', () => {
43 for (const key of FONTS) assert.equal(fontForMarks(['font_' + key]), key)
44})
45
46test('a run carrying two font marks reads as the innermost, the later in the manifest', () => {
47 const both = ['font_sans', 'font_caladea']
48 assert.equal(fontForMarks(both), fontForMarks([...both].reverse()))
49 assert.equal(fontForMarks(both), 'sans')
50})
51
52test('every family has a regular, and Caveat no italic', () => {
53 for (const f of FAMILIES) assert.ok(f.faces.some((s) => s.weight === 400 && s.style === 'normal'), f.key)
54 const caveat = FAMILIES.find((f) => f.key === 'caveat')
55 assert.equal(caveat.faces.length, 2)
56 assert.equal(caveat.cssName, 'Docs Caveat')
57})
58
59test('fontKeysIn picks out the families a set of marks asks for', () => {
60 assert.deepEqual(fontKeysIn(['strong', 'font_inter', 'font_nope', 'font_caveat']), ['inter', 'caveat'])
61})
62
63// A pasted font-family stack maps the way the native app maps it, from
64// the same manifest, and the same cases (fixtures/vectors/font-stacks.json).
65test('a pasted font stack is read in order, the first family that maps winning', async () => {
66 const { readFileSync } = await import('node:fs')
67 const { familyForStack } = await import('./fonts.mjs')
68 const { cases } = JSON.parse(readFileSync(new URL('./vectors/font-stacks.json', import.meta.url)))
69 for (const [stack, want] of cases) assert.equal(familyForStack(stack), want, stack)
70})
71