Answer stability round 2: refuse a node or mark holding a key it does not own
This commit is contained in:
@@ -84,7 +84,7 @@ test("reads a node's siblings as a walk rather than as one call's arguments", ()
|
||||
})
|
||||
|
||||
test('refuses a node or an attribute value holding itself, and accepts one shared', () => {
|
||||
const holdsItself = 'an ADF document is a tree: a node or an attribute value holds itself'
|
||||
const holdsItself = 'an ADF document is a tree: an object in it holds itself'
|
||||
const paragraph: { content: unknown[]; type: string } = { content: [], type: 'paragraph' }
|
||||
paragraph.content.push(paragraph)
|
||||
assert.equal(fault({ content: [paragraph], type: 'doc', version: 1 }), holdsItself)
|
||||
@@ -96,6 +96,18 @@ test('refuses a node or an attribute value holding itself, and accepts one share
|
||||
assert.equal(fault({ content: [{ attrs, type: 'paragraph' }], type: 'doc', version: 1 }), holdsItself)
|
||||
assert.equal(fault({ content: [{ marks: [{ attrs, type: 'link' }], text: 'x', type: 'text' }], type: 'doc', version: 1 }), holdsItself)
|
||||
assert.equal(isAdfDocument({ content: [{ attrs, type: 'paragraph' }], type: 'doc', version: 1 }), false)
|
||||
const notANode = "an ADF document's content holds ADF nodes: one of them is not"
|
||||
const inherits: { content?: unknown[] } = {}
|
||||
const heir: Record<string, unknown> = Object.create(inherits)
|
||||
heir['type'] = 'paragraph'
|
||||
inherits.content = [heir]
|
||||
assert.equal(fault({ content: [heir], type: 'doc', version: 1 }), notANode)
|
||||
const hidden: Record<string, unknown> = { type: 'paragraph' }
|
||||
Object.defineProperty(hidden, 'content', { value: [hidden] })
|
||||
assert.equal(fault({ content: [hidden], type: 'doc', version: 1 }), notANode)
|
||||
const link: Record<string, unknown> = Object.create({ attrs })
|
||||
link['type'] = 'link'
|
||||
assert.equal(fault({ content: [{ marks: [link], text: 'x', type: 'text' }], type: 'doc', version: 1 }), notANode)
|
||||
const bold = { type: 'strong' }
|
||||
const text = { marks: [bold], text: 'x', type: 'text' }
|
||||
const shared = { content: [text, text], type: 'paragraph' }
|
||||
|
||||
Reference in New Issue
Block a user