// The app's "With Quarto" page (#/quarto, src/ui/quarto.ts): its samples must show what a page gets from the // extension, and every program in it must run as its header says. import test from 'node:test'; import assert from 'node:assert/strict'; import { installDocument } from '../dist/quarto/dom.js'; import { langOfFile } from '../dist/quarto/program.js'; installDocument(); const { renderStatic } = await import('../dist/quarto/render.js'); const { parseRoute, routeFor } = await import('../dist/core/state.js'); test('the gallery\'s samples render as a page would get them, and every run in it prints what its file says', async () => { const { galleryFiles, SAMPLES } = await import('../dist/ui/quarto.js'); const { SHORTCODES, requestFor, liveStateFor, shortcodeText } = await import('../dist/quarto/shortcodes.js'); const files = galleryFiles(); const named = new Set(SAMPLES.map((s) => s.name)); // every shortcode has a card; the machine's one-view shortcodes share a card with a menu of them all for (const d of SHORTCODES) assert.ok(named.has(d.name) || (d.kind === 'machine' && d.hw && SAMPLES.some((x) => x.explore)), `the gallery shows ${d.name}`); for (const s of SAMPLES) { for (const [k, v] of Object.entries(s.attrs)) if (['lingo', 'matho', 'pseudo', 'speco', 'mojo', 'asm', 'setup'].includes(k)) assert.ok(files[v] !== undefined, `${s.name} names ${v}`); assert.match(shortcodeText(s.name, s.attrs), new RegExp(`^\\{\\{< ${s.name} .* >\\}\\}$`)); const def = SHORTCODES.find((d) => d.name === s.name); if (def.kind === 'live') { assert.ok(Object.keys(liveStateFor(s.attrs, files).sources).length, s.name); continue; } if (def.kind !== 'rendered' && def.kind !== 'machine') continue; const view = def.view ?? (s.attrs.view === 'dataflow' ? 'data' : s.attrs.view); const req = requestFor(view, s.attrs, files); if (def.hw) req.hw = [def.hw]; const r = renderStatic(req); assert.deepEqual(r.warnings, [], `${s.name} ${JSON.stringify(s.attrs)}`); if (r.expect) assert.ok(r.expect.ok, `${s.name}: ${JSON.stringify(r.expect)}`); } // the files' own headers hold: each run prints its EXPECT lines, each stop is the one it names for (const [name, text] of Object.entries(files)) { const lang = langOfFile(name); if (!lang || lang === 'speco' || lang === 'asm') continue; const r = renderStatic({ view: 'run', files: { [lang]: text } }); if (r.expect) assert.ok(r.expect.ok, `${name}: ${JSON.stringify(r.expect)}`); } }); test('#/quarto is the gallery, and its sections are links', () => { assert.deepEqual(parseRoute('#/quarto'), { kind: 'quarto' }); assert.deepEqual(parseRoute('#/quarto#pplus-steps'), { kind: 'quarto', anchor: 'pplus-steps' }); assert.equal(routeFor({ kind: 'quarto', anchor: 'setup' }), '#/quarto#setup'); assert.deepEqual(parseRoute('#/quarto/x'), { kind: 'home' }); });