diff --git a/src/conformance/adf-property.test.ts b/src/conformance/adf-property.test.ts index 8b6b825..59602c5 100644 --- a/src/conformance/adf-property.test.ts +++ b/src/conformance/adf-property.test.ts @@ -14,12 +14,12 @@ import { portableMarkdownToAdf } from '../markdown/portable/portable-markdown-to import { toEditorNormal } from '../markdown/portable/editor-normal.ts' const gateRuns = 1600 -const htmlPieces = fc.constantFrom('<', '>', '&', '"', '\n', '\r', '\0', '&', '"', ''', '
', '
', '', '
', 'c', 'a', '', 'b', 'a'] const elementLines = ['
\n\n', 'a
\n
a
\na
a
\n', 'a\n', 'Read the manual.
\nCheck the collation.
')}\nAsk ${carry('span', mention, '@Mikael')}
\n`)), document(panel, paragraph(text('Ask '), mention))) assert.deepEqual(read(htmlToAdf(`${carry('span', text('a\u0085b', { type: 'underline' }), 'ab').replace('\u0085', '\\u0085')}
\n`)), document(paragraph(text('a\u0085b', { type: 'underline' })))) }) -test('refuses an edit to what a carry element shows, naming what it found there', () => { - const panel: AdfNode = { attrs: { panelType: 'info' }, content: [paragraph(text('Check the collation.'))], type: 'panel' } - const edited = htmlToAdf(`a
\n${carry('div', panel, 'Check the collation.
')}\n`) - assert.equal(refusal(edited), 'unmappable-html at /content/1 line 2 offset 9') - assert.match(message(edited), /: found "collation<\/b>\.<\/p><\/d"…$/) - const mention: AdfNode = { attrs: { id: ids.mention, text: '@Mikael' }, type: 'mention' } - assert.equal(refusal(htmlToAdf(`Ask ${carry('span', mention, '')}
\n`)), 'unmappable-html at /content/0/content/1 line 1 offset 0') -}) - test('reads a carry element holding a node HTML writes as its own element as that node', () => { assert.deepEqual(read(htmlToAdf(`${carry('div', paragraph(text('x')), 'x
')}\n`)), document(paragraph(text('x')))) assert.deepEqual(read(htmlToAdf(`a${carry('span', text('b'), 'b')}
\n`)), document(paragraph(text('a'), text('b')))) @@ -185,6 +185,21 @@ const refusals: Readonly\n', 'unsupported-node-shape at /content/0/content/0 line 1 offset 0'], ['
a
\n', 'unmappable-html at /content/0/content/0 line 1 offset 0'], ], + 'refuses an edit to what a carry element shows': [ + [`a
\n${carry('div', panel, 'Check the collation.
')}\n`, 'unmappable-html at /content/1 line 2 offset 9'], + [`Ask ${carry('span', mention, '')}
\n`, 'unmappable-html at /content/0/content/1 line 1 offset 0'], + ], + 'refuses the document\'s carry anywhere but as the whole document, a line feed ending it': [ + [documentCarry, 'unmappable-html at / line 1 offset 0'], + [`${documentCarry}\n\n`, `unmappable-html at / line 2 offset ${documentCarry.length + 1}`], + [`${documentCarry}X`, 'unmappable-html at / line 1 offset 0'], + [`${documentCarry}X\n${documentCarry}\n\n`, 'unsupported-node-shape at /content/0/content/0 line 2 offset 13'], + [`${carry('div', { type: 'doc', version: 2 }, '')}\n`, 'unsupported-node-shape at /content/0 line 1 offset 0'], + ], 'refuses a data-* attribute out of the order adfToHtml writes as unmappable-html, and one no attribute of its node spells as unsupported-node-shape': [ ['
\n${documentCarry}\n\n`)), 'unsupported-node-shape at /content/0/content/0 line 2 offset 13') - assert.equal(refusal(htmlToAdf(`${carry('div', { type: 'doc', version: 2 }, '')}\n`)), 'unsupported-node-shape at /content/0 line 1 offset 0') -}) + }) +} test('refuses a tag of three million attributes, past what one pattern over them all holds, as a value', () => { assert.equal(refusal(htmlToAdf(`
x
\n`)), 'unmappable-html at /content/0 line 1 offset 0') }) -test('names what it found where reading stopped, a character no one sees as its escape', () => { - assert.equal(message(htmlToAdf('ab
\n')), ' as written here is no inline element of the dialect: found "b\\n"') - assert.equal(message(htmlToAdf('a > b
\n')), 'text escapes &, <, > and " as &, <, > and ", and holds no character HTML cannot hold: found "> b\\n"') - assert.equal(message(htmlToAdf('\n')), ' holds its attributes as name="value", each value escaped as text is, then >: found "b\\">a\\n"') - assert.equal(message(htmlToAdf('a \u00a0
\n')), 'text escapes &, <, > and " as &, <, > and ", and holds no character HTML cannot hold: found " \\u00a0\\n"') - assert.equal(message(htmlToAdf('a: found "\nab
\n', ' as written here is no inline element of the dialect: found "b\\n"'], + ['a > b
\n', 'text escapes &, <, > and " as &, <, > and ", and holds no character HTML cannot hold: found "> b\\n"'], + ['\n', ' holds its attributes as name="value", each value escaped as text is, then >: found "b\\">a\\n"'], + ['a \u00a0
\n', 'text escapes &, <, > and " as &, <, > and ", and holds no character HTML cannot hold: found " \\u00a0\\n"'], + ['a: found "\na
\n${carry('div', panel, 'Check the collation.
')}\n`, 'a carry element shows its node\'s text as adfToHtml writes it, then ends at ; an edit to it is no edit to the node: found "collation. assert.equal(message(htmlToAdf(html)), expected)) test('reads blocks nested 500 levels, and refuses the next level, a list\'s items one level below it', () => { const quotes = (levels: number): string => `${'\n'.repeat(levels)}'.repeat(levels)}\n` @@ -286,22 +296,24 @@ test('reads blocks nested 500 levels, and refuses the next level, a list\'s item }) test('refuses a carried node whose JSON nests past the levels its depth leaves, and an inline carry past 500', () => { - let value: unknown = 1 - for (let level = 0; level < 498; level += 1) value = [value] - const carried = carry('div', { attrs: { a: value }, type: 'unknownBlock' }, '') + const carried = carry('div', { attrs: { a: nested(1, 498, (inner) => [inner]) }, type: 'unknownBlock' }, '') assert.equal(refusal(htmlToAdf(`${carried}\n`)), 'read') assert.equal(refusal(htmlToAdf(`x
${'\n
\n${carried}\n\n`)), 'unsupported-nesting-depth at /content/0/content/0 line 2 offset 13') - let inline: unknown = { text: 'x', type: 'text' } - for (let level = 0; level < 500; level += 1) inline = { content: [inline], type: 'unknownInline' } + const inline = nested({ text: 'x', type: 'text' }, 500, (inner) => ({ content: [inner], type: 'unknownInline' })) assert.equal(refusal(htmlToAdf(`
${carry('span', inline, '')}
\n`)), 'unsupported-nesting-depth at /content/0/content/0 line 1 offset 0') }) -test('reads back what adfToHtml writes for the documents its own tests write', () => { - const bare: AdfDocument = { type: 'doc', version: 1 } - const panel: AdfNode = { attrs: { panelType: 'info' }, content: [paragraph(text('Run this:')), { attrs: { language: 'python' }, content: [text('if ready:\n deploy()')], type: 'codeBlock' }], type: 'panel' } - for (const written of [document(panel), document(paragraph(text('a'), text('b'), text('c', { type: 'em' }), text('d'), text('e'))), bare]) { - const html = adfToHtml(written) +// The documents adfToHtml's own tests write, by what each holds. +const written: Readonly