// The rendered views of the Quarto extension (src/quarto/): a program from the files beside a page, run by the app's // engines and drawn by its views as HTML, under the small document of src/quarto/dom.ts; the CLI pplus.lua calls // (quarto/_extensions/pplus/render.mjs). The gallery that shows them in the app is tests/quarto-gallery.test.mjs. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; import zlib from 'node:zlib'; import { installDocument, SDocument } from '../dist/quarto/dom.js'; import { programHeader, listingText, langOfFile } from '../dist/quarto/program.js'; installDocument(); const { renderStatic, STATIC_VIEWS, stepsPanel } = await import('../dist/quarto/render.js'); const { problemById } = await import('../dist/core/catalog.js'); const ROOT = new URL('..', import.meta.url).pathname; const CB = problemById('count-base'); const head = (call, expect) => `// CALL: ${call}\n${expect ? `// EXPECT: ${expect}\n` : ''}`; const PSEUDO = head(CB.call, 'COUNT_BASE returned 3') + CB.sources.pseudo; test('a program file: its pane, its header lines, and the text a page shows', () => { assert.equal(langOfFile('x/count.pseudo'), 'pseudo'); assert.equal(langOfFile('mean.tex'), 'matho'); assert.equal(langOfFile('demo.mojo'), 'mojo'); assert.equal(langOfFile('notes.txt'), null); const h = programHeader('// CALL: F(1)\n// INPUT: 4\n// INPUT: 5\n// EXPECT: F returned 2\n// STOPS: index\nFUNCTION F...'); assert.deepEqual(h, { call: 'F(1)', input: ['4', '5'], expect: ['F returned 2'], stops: 'index', questions: [] }); assert.deepEqual(programHeader('% CALL: X(1)\n% EXPECT: X returned 1\n').expect, ['X returned 1']); assert.deepEqual(programHeader('# expect-stdout: 3\n# expect-stdout: 4\ndef main():\n pass\n').expect, ['3', '4'], 'a Mojo file\'s corpus header counts as EXPECT'); assert.equal(listingText('// CALL: F(1)\n\nFUNCTION F()\n', 'pseudo'), 'FUNCTION F()'); assert.equal(listingText('# origin: x\n# expect-stdout: 1\n\ndef main():\n # note: mine\n print(1)\n', 'mojo'), 'def main():\n # note: mine\n print(1)'); }); test('the small document builds, finds and writes what the views make', () => { const doc = new SDocument(); const div = doc.createElement('div'); div.className = 'a b'; div.classList.add('c'); div.classList.toggle('a'); div.style.left = '10%'; div.style.setProperty('--x', '1'); div.dataset.stepNo = '4'; const svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('viewBox', '0 0 1 1'); svg.appendChild(doc.createElementNS('http://www.w3.org/2000/svg', 'path')); const p = doc.createElement('p'); p.textContent = 'x < y & "z"'; const sel = doc.createElement('select'); for (const v of ['one', 'two']) { const o = doc.createElement('option'); o.value = v; o.textContent = v; sel.appendChild(o); } sel.value = 'two'; const details = doc.createElement('details'); details.open = true; div.append(svg, p, sel, details); assert.equal(div.outerHTML, '
x < y & "z"