diff --git a/src/markdown-property.test.ts b/src/markdown-property.test.ts index b0cd732..4213794 100644 --- a/src/markdown-property.test.ts +++ b/src/markdown-property.test.ts @@ -27,6 +27,10 @@ type Choice = { arbitrary: Arbitrary; hostile?: true; weight: number } type Edit = [at: number, removed: number, inserted: string] +type InlineMarkdown = { destination: Arbitrary; inlines: Arbitrary; label: Arbitrary; oneLine: Arbitrary; text: Arbitrary; word: Arbitrary } + +type LeafMarkdown = { fencedCode: Arbitrary; leafBlock: Arbitrary } + const gateRuns = 1000 const vocabularies = [...Object.values(blockDirectives).map((directive) => directive.attributes), ...Object.values(inlineDirectives).map((directive) => directive.attributes), ...Object.values(markAttributes)] @@ -179,7 +183,11 @@ const indentDrift = fc.oneof({ arbitrary: fc.constant(0), weight: 6 }, { arbitra const closerDrift = fc.option(fc.integer({ max: 5, min: 2 }), { freq: 6 }) function markdownOf(hostile: boolean): Arbitrary { - const blockDepth = fc.createDepthIdentifier() + const inline = inlineMarkdown(hostile) + return blockMarkdown(hostile, inline, leafBlocks(hostile, inline)) +} + +function inlineMarkdown(hostile: boolean): InlineMarkdown { const inlineDepth = fc.createDepthIdentifier() const text = hostile ? fc.oneof(cleanText, textOf(0)) : cleanText const word = fc.oneof({ arbitrary: prose, weight: 3 }, { arbitrary: text.filter((held) => held !== ''), weight: 2 }) @@ -228,8 +236,10 @@ function markdownOf(hostile: boolean): Arbitrary { ), inlines: fc.array(tie('inline'), { depthIdentifier: inlineDepth, maxLength: 4, minLength: 1 }).map((parts) => parts.join('')), })) + return { destination, inlines, label, oneLine: inlines.map((held) => held.replace(/[\n\r]/g, ' ')), text, word } +} - const oneLine = inlines.map((held) => held.replace(/[\n\r]/g, ' ')) +function leafBlocks(hostile: boolean, { destination, inlines, label, oneLine, text, word }: InlineMarkdown): LeafMarkdown { const fencedCode = fc .tuple( fc.constantFrom('```', '```', '~~~', '````', '``'), @@ -287,7 +297,11 @@ function markdownOf(hostile: boolean): Arbitrary { }, { arbitrary: fc.constantFrom(':::', '::', '::::', ':::panel', '::: panel', ':::panel info extra'), hostile: true, weight: 1 }, ]) + return { fencedCode, leafBlock } +} +function blockMarkdown(hostile: boolean, { inlines, oneLine }: InlineMarkdown, { fencedCode, leafBlock }: LeafMarkdown): Arbitrary { + const blockDepth = fc.createDepthIdentifier() const { blocks } = fc.letrec<{ block: string; blocks: string }>((tie) => { const bodyByModel = { block: fc.oneof(tie('blocks'), fc.constant('')), code: fencedCode, inline: fc.oneof(oneLine, fc.constant('')) } const tableDirectives = Object.entries(blockDirectives).map(([name, directive]) => {