From 38e7bcfaca48b7acfbe48eae6899e96886a22b5c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 08:28:13 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20assert=20th?= =?UTF-8?q?e=20reduced=20task=20list=20whole=20and=20list=20the=20README?= =?UTF-8?q?=20codes=20by=20one=20match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portable/adf-to-portable-markdown.test.ts | 35 ++++++++----------- src/result.test.ts | 11 ++---- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/markdown/portable/adf-to-portable-markdown.test.ts b/src/markdown/portable/adf-to-portable-markdown.test.ts index 0ed37c9..0c2add9 100644 --- a/src/markdown/portable/adf-to-portable-markdown.test.ts +++ b/src/markdown/portable/adf-to-portable-markdown.test.ts @@ -158,28 +158,23 @@ test('spells a task list as a bullet list whose items lead with their state', () assert.equal(portable(node('taskList', {}, task('DONE', 'a'), node('taskList', {}, task('TODO', '')))), '- [x] a\n - [ ]\n') }) -test('leaves a block task item only when it opens with a paragraph', () => { - const task = (state: string, value: string): AdfNode => node('taskItem', { state }, text(value)) +test('leaves a block task item only when it opens with two or more paragraphs', () => { + const task = (value: string): AdfNode => node('taskItem', { state: 'TODO' }, text(value)) const blockTask = (...content: AdfNode[]): AdfNode => node('blockTaskItem', { state: 'TODO' }, ...content) const codeBlock: AdfNode = { content: [text('x')], type: 'codeBlock' } - const nested = node('taskList', {}, task('TODO', 'n')) - const lists = [ - node('taskList', {}, blockTask(said('a'), said('b')), blockTask(codeBlock, said('c')), blockTask(bulletList(item(said('d'))), said('e'))), - node('taskList', {}, blockTask(nested, said('f')), blockTask(said('g'), codeBlock, said('h')), blockTask(), blockTask(said('i'))), - node('taskList', {}, blockTask(said('j'), nested, said('k'), nested), blockTask(said('l'), said('m'), nested)), - ] - const reduced = reduceToPortable(document(...lists)) - assert.ok(reduced.ok) - const pending = [...(reduced.value.content ?? [])] - let blockTasks = 0 - for (let at = pending.pop(); at !== undefined; at = pending.pop()) { - for (const child of at.content ?? []) pending.push(child) - if (at.type !== 'blockTaskItem') continue - blockTasks += 1 - assert.equal(at.content?.[0]?.type, 'paragraph') - assert.ok((at.content ?? []).filter((child) => child.type === 'paragraph').length >= 2) - } - assert.equal(blockTasks, 2) + const taskList = (...content: AdfNode[]): AdfNode => ({ content, type: 'taskList' }) + const nested = taskList(task('n')) + const reduced = reduceToPortable( + document(node('taskList', {}, blockTask(said('a'), said('b')), blockTask(codeBlock, said('c')), blockTask(said('d'), codeBlock), blockTask(said('e'), said('f'), node('taskList', {}, task('n'))))), + ) + assert.deepEqual(reduced.ok && reduced.value.content, [ + taskList(blockTask(said('a'), said('b')), { attrs: { state: 'TODO' }, type: 'taskItem' }), + codeBlock, + said('c'), + taskList(task('d')), + codeBlock, + taskList(blockTask(said('e'), said('f')), nested), + ]) }) test('spells a decision list as a plain bullet list', () => { diff --git a/src/result.test.ts b/src/result.test.ts index afa4e4d..b7b6e48 100644 --- a/src/result.test.ts +++ b/src/result.test.ts @@ -48,14 +48,9 @@ for (const [code, cause] of Object.entries(causes)) { }) } -// A code added or removed must reach the README's tables, which are the contract a consumer switches on. test('the README error tables list exactly the codes ConvertErrorCode holds', () => { const readme = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'README.md'), 'utf8') - const section = readme.slice(readme.indexOf('\n## The errors\n')) - const listed = new Set() - for (const line of section.slice(1, section.indexOf('\n## ', 1)).split('\n')) { - const code = /^\| `([a-z-]+)` \|/.exec(line)?.[1] - if (code !== undefined) listed.add(code) - } - assert.deepEqual([...listed].sort(), Object.keys(causes).sort()) + const section = readme.slice(readme.indexOf('\n## The errors\n') + 1, readme.indexOf('\n## ', readme.indexOf('\n## The errors\n') + 1)) + const listed = [...section.matchAll(/^\| `([a-z-]+)` \|/gm)].map((match) => match[1]) + assert.deepEqual(listed.sort(), Object.keys(causes).sort()) })