3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-18 22:25:44 +01:00

Answer principles round 1: 3 🔴, 8 🟡 (0 misread); attributes as data-*, carried content as paragraphs, links and notes, no character HTML cannot hold, mutants killed

This commit is contained in:
2026-10-23 19:19:14 +02:00
committed by Lillem4n
parent 1f46111fe4
commit 7a38db2563
27 changed files with 612 additions and 295 deletions
+16 -1
View File
@@ -2,8 +2,9 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import vm from 'node:vm'
import type { AdfDocument } from './document.ts'
import type { JsonValue } from '../json-value.ts'
import { adfDocumentFault, isAdfDocument } from './document.ts'
import { adfDocumentFault, isAdfDocument, writableContent } from './document.ts'
import { largestNesting } from '../nesting.ts'
function fault(value: unknown): string {
@@ -114,3 +115,17 @@ test('refuses an object holding itself, and accepts one shared', () => {
const values = { b: 1 }
assert.equal(fault({ content: [shared, shared, { attrs: { a: [values, values] }, type: 'paragraph' }], type: 'doc', version: 1 }), 'accepted')
})
test('opens every writer with the same checks: a document, version 1, and no more text than the longest output holds', () => {
const checked = (document: AdfDocument): string => {
const result = writableContent(document)
return result.ok ? JSON.stringify(result.value) ?? 'no content key' : result.error.code
}
assert.equal(checked({ type: 'doc', version: Number.NaN }), 'not-an-adf-document')
assert.equal(checked({ type: 'doc', version: 2 }), 'unsupported-document-version')
assert.equal(checked({ type: 'doc', version: 1 }), 'no content key')
assert.equal(checked({ content: [{ type: 'rule' }], type: 'doc', version: 1 }), '[{"type":"rule"}]')
const long = 'a'.repeat(2 ** 28)
const text = { content: [{ text: long, type: 'text' }, { text: long, type: 'text' }, { text: long, type: 'text' }], type: 'paragraph' }
assert.equal(checked({ content: [text], type: 'doc', version: 1 }), 'unsupported-node-shape')
})