From 5facc0fc5dd7419ebfd524792ddc944c2990f16f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 02:10:06 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=202=20?= =?UTF-8?q?=F0=9F=94=B4,=207=20=F0=9F=9F=A1=20(0=20misread);=20look=20mark?= =?UTF-8?q?s=20up=20in=20a=20Map,=20judge=20delimiters=20by=20whole=20code?= =?UTF-8?q?=20points,=20report=20a=20container's=20first=20refusal=20and?= =?UTF-8?q?=20test=20the=20mutants=20left?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wiki/emit/adf-to-jira-wiki.test.ts | 31 +++++++++++++++++++++++--- src/wiki/emit/adf-to-jira-wiki.ts | 4 ++-- src/wiki/emit/inline-line.ts | 18 +++++++++++---- src/wiki/emit/spelled-blocks.ts | 3 ++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/wiki/emit/adf-to-jira-wiki.test.ts b/src/wiki/emit/adf-to-jira-wiki.test.ts index 4cf25b8..167b0de 100644 --- a/src/wiki/emit/adf-to-jira-wiki.test.ts +++ b/src/wiki/emit/adf-to-jira-wiki.test.ts @@ -344,6 +344,7 @@ for (const [panelType, colour] of [['error', '#ffebe6'], ['info', '#deebff'], [' const external = { type: 'external', url: 'https://example.com/a.png' } const riddenBlocks: [string, AdfNode][] = [ + ['an image whose mediaSingle holds no content', { attrs: { layout: 'center' }, type: 'mediaSingle' }], ['an image whose mediaSingle holds no media', { attrs: { layout: 'center' }, content: [paragraph(text('a'))], type: 'mediaSingle' }], ['an image whose mediaSingle holds its caption first', { attrs: { layout: 'center' }, content: [{ content: [text('c')], type: 'caption' }, { attrs: external, type: 'media' }], type: 'mediaSingle' }], ['an image whose mediaSingle holds two media', { attrs: { layout: 'center' }, content: [{ attrs: external, type: 'media' }, { attrs: external, type: 'media' }], type: 'mediaSingle' }], @@ -361,9 +362,10 @@ const riddenBlocks: [string, AdfNode][] = [ ['a blockquote holding no content', { type: 'blockquote' }], ['a list holding a paragraph', { content: [paragraph(text('a'))], type: 'bulletList' }], ['a list holding a list item and a paragraph', { content: [item(paragraph(text('a'))), paragraph(text('b'))], type: 'bulletList' }], - ['a blockquote holding a list that holds a quote', { content: [list('bulletList', item(paragraph(text('a')), { content: [paragraph(text('b')), paragraph(text('c'))], type: 'blockquote' }))], type: 'blockquote' }], + ['a blockquote holding a panel that holds a quote', quote(panel('info', quote(paragraph(text('a')), paragraph(text('b')))))], ['a list item holding a localId', list('bulletList', { attrs: { localId: 'i1' }, content: [paragraph(text('a'))], type: 'listItem' })], ['a list item opening with a list', list('bulletList', item(list('bulletList', item(paragraph(text('a'))))))], + ['a panel whose panelType is an array', { attrs: { panelType: ['info'] }, content: [paragraph(text('a'))], type: 'panel' }], ['a panel holding another attribute', { attrs: { panelIcon: ':x:', panelType: 'info' }, content: [paragraph(text('a'))], type: 'panel' }], ['a table holding a paragraph', { attrs: plainTable, content: [paragraph(text('a'))], type: 'table' }], ['a table holding a row and a paragraph', { attrs: plainTable, content: [{ content: [cell('tableCell', text('a'))], type: 'tableRow' }, paragraph(text('b'))], type: 'table' }], @@ -456,7 +458,10 @@ test('writes a link whose href starts with ~ with its text, since [~x] names a u const riddenMarks: [string, AdfMark][] = [ ['a colour followed by more', { attrs: { color: '#ff0000x' }, type: 'textColor' }], ['a colour led by more', { attrs: { color: 'x#ff0000' }, type: 'textColor' }], + ['a colour held in an array', { attrs: { color: ['#ff0000'] }, type: 'textColor' }], ['a colour holding another attribute', { attrs: { color: '#ff0000', x: 1 }, type: 'textColor' }], + ['a mark of type __proto__', { type: '__proto__' }], + ['a mark of type toString', { type: 'toString' }], ['a subsup holding another attribute', { attrs: { type: 'sub', x: 1 }, type: 'subsup' }], ['a mark of another type holding an href', { attrs: { href: 'https://example.com' }, type: 'fancyLink' }], ['a link whose href is no string', { attrs: { href: 5 }, type: 'link' }], @@ -481,9 +486,29 @@ for (const [name, node] of riddenInlines) { }) } -test('refuses a carry past 500 levels by its path in a list', () => { +test('refuses a carry past 500 levels in a list by the path of the first', () => { let value: AdfAttributes[string] = 1 for (let level = 0; level < largestNesting - 1; level += 1) value = [value] const deep: AdfNode = { attrs: { a: value }, type: 'unknownInline' } - assert.equal(refusal(adfToLosslessJiraWiki(document(list('bulletList', item(paragraph(deep)))))), 'unsupported-nesting-depth at /content/0/content/0/content/0/content/0') + assert.equal(refusal(adfToLosslessJiraWiki(document(list('bulletList', item(paragraph(deep)), item(paragraph(deep)))))), 'unsupported-nesting-depth at /content/0/content/0/content/0/content/0') +}) + +test('carries a text holding no text', () => { + assert.equal(wiki(paragraph(text('a'), { type: 'text' })), `a${inline('{"type":"text"}')}`) +}) + +test('carries two inline nodes that each ride as two carries', () => { + const first: AdfNode = { attrs: { a: 1 }, type: 'unknownInline' } + const second: AdfNode = { attrs: { a: 2 }, type: 'unknownInline' } + assert.equal(wiki(paragraph(first, second)), `${inline(JSON.stringify(first))}${inline(JSON.stringify(second))}`) +}) + +test('reads a letter outside the Basic Multilingual Plane beside a delimiter as a letter', () => { + const strong = text('x', { type: 'strong' }) + assert.equal(wiki(paragraph(text('\u{20000}'), strong)), `\u{20000}${inline(JSON.stringify(strong))}`) + assert.equal(wiki(paragraph(strong, text('\u{20000}'))), `${inline(JSON.stringify(strong))}\u{20000}`) +}) + +test('writes a delimiter followed by whitespace at a line start as itself', () => { + assert.equal(line('+ a'), '+ a') }) diff --git a/src/wiki/emit/adf-to-jira-wiki.ts b/src/wiki/emit/adf-to-jira-wiki.ts index 680f853..7b1f8d5 100644 --- a/src/wiki/emit/adf-to-jira-wiki.ts +++ b/src/wiki/emit/adf-to-jira-wiki.ts @@ -9,7 +9,7 @@ import { spelledBlocks, type Spelling } from './spelled-blocks.ts' // `prefix`: the markers of the lists holding the block, one character per level. type Pending = string | { node: AdfNode; prefix: string } -const listMarkers: Readonly> = { bulletList: '*', orderedList: '#' } +const listMarkers: ReadonlyMap = new Map([['bulletList', '*'], ['orderedList', '#']]) export function adfToLosslessJiraWiki(document: AdfDocument): Result { return withinEngineLimits(() => { @@ -51,7 +51,7 @@ function blockPieces(node: AdfNode, prefix: string, spelled: ReadonlyMap> = { em: '_', strike: '-', strong: '*', underline: '+' } +const characterDelimiters: ReadonlyMap = new Map([['em', '_'], ['strike', '-'], ['strong', '*'], ['underline', '+']]) const spellableUrl = /^[^\s[\]{}|\\]+$/ const spellableColour = /^#[0-9a-f]{6}$/i @@ -32,7 +32,7 @@ export function inlineLine(nodes: readonly AdfNode[], path: ConvertErrorPath): R // A group that opens with a delimiter or a carry opens with punctuation, which reads as the line's edge does. const following = next === undefined ? undefined : atoms[next.first] const after = following?.marks.length === 0 ? following.spelled?.text : undefined - const written = groupSpelling(atoms.slice(first, last + 1), line.at(-1), after?.[0]) + const written = groupSpelling(atoms.slice(first, last + 1), lastCharacter(line), after === undefined ? undefined : firstCharacter(after)) if (written === undefined) { const carry = inlineCarry(nodes.slice(first, last + 1), [...path, 'content', first]) if (!carry.ok) return carry @@ -91,7 +91,7 @@ function hrefSpelling(node: AdfNode, nodes: readonly AdfNode[], index: number): // `undefined` where wiki markup has no spelling for the mark. function markDelimiters(mark: AdfMark): Delimiters | undefined { const attrs = nodeAttrs(mark) - const character = characterDelimiters[mark.type] + const character = characterDelimiters.get(mark.type) if (character !== undefined) return mark.attrs === undefined ? { checked: true, close: character, open: character } : undefined if (mark.type === 'code') return mark.attrs === undefined ? { checked: true, close: '}}', open: '{{' } : undefined if (mark.type === 'subsup') { @@ -147,7 +147,7 @@ function groupSpelling(atoms: readonly Atom[], before: string | undefined, after open = marks } for (const mark of open.slice().reverse()) tokens.push(delimiterToken(mark, 'close')) - return tokens.every((token, index) => delimiterReads(token, tokens[index - 1]?.text.at(-1) ?? before, tokens[index + 1]?.text[0] ?? after)) ? tokens.map(({ text }) => text).join('') : undefined + return tokens.every((token, index) => delimiterReads(token, lastCharacter(tokens[index - 1]?.text ?? '') ?? before, firstCharacter(tokens[index + 1]?.text ?? '') ?? after)) ? tokens.map(({ text }) => text).join('') : undefined } function delimiterToken({ delimiters: { checked, close, open } }: SpelledMark, kind: 'close' | 'open'): Token { @@ -161,3 +161,13 @@ function delimiterReads({ checked, kind }: Token, before: string | undefined, af const inside = kind === 'open' ? after : before return (outside === undefined || !/[\p{L}\p{N}]/u.test(outside)) && inside !== undefined && !/\s/u.test(inside) } + +// Whole code points, so a letter outside the Basic Multilingual Plane reads as a letter. +function firstCharacter(text: string): string | undefined { + const point = text.codePointAt(0) + return point === undefined ? undefined : String.fromCodePoint(point) +} + +function lastCharacter(text: string): string | undefined { + return /.$/su.exec(text)?.[0] +} diff --git a/src/wiki/emit/spelled-blocks.ts b/src/wiki/emit/spelled-blocks.ts index 6460a1f..9ad9c80 100644 --- a/src/wiki/emit/spelled-blocks.ts +++ b/src/wiki/emit/spelled-blocks.ts @@ -29,7 +29,8 @@ export function spelledBlocks(content: readonly AdfNode[]): Result ({ exit: false, node: child, path: [...path, 'content', index] })) + for (const child of children.reverse()) pending.push(child) } else { const spelling = leafSpelling(node, path) if (!spelling.ok) return spelling