Keep the browser leg on dist/index.js: tag -0 in the JSON it hands back
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
try {
|
try {
|
||||||
const { adfToMarkdown, isAdfDocument, markdownToAdf } = await import('/dist/index.js')
|
const { adfToMarkdown, isAdfDocument, markdownToAdf } = await import('/dist/index.js')
|
||||||
const { serializeCanonicalJson } = await import('/dist/canonical-json.js')
|
// WebDriver's JSON reads -0 back as 0, so a document crosses as JSON text with -0 tagged; run.js revives it.
|
||||||
// WebDriver's JSON reads -0 back as 0, so a document crosses as its canonical spelling.
|
const spelled = (result) => (result.ok ? { ok: true, value: JSON.stringify(result.value, (_, value) => (Object.is(value, -0) ? '\u0000-0' : value)) } : result)
|
||||||
const spelled = (result) => (result.ok ? { ok: true, value: `${serializeCanonicalJson(result.value, 'two-space')}\n` } : result)
|
|
||||||
window.convertCorpus = (corpus) => ({
|
window.convertCorpus = (corpus) => ({
|
||||||
errors: corpus.errors.map(({ markdown, name }) => ({ name, parsed: markdownToAdf(markdown) })),
|
errors: corpus.errors.map(({ markdown, name }) => ({ name, parsed: markdownToAdf(markdown) })),
|
||||||
normalization: corpus.normalization.map(({ markdown, name }) => ({ name, parsed: spelled(markdownToAdf(markdown)) })),
|
normalization: corpus.normalization.map(({ markdown, name }) => ({ name, parsed: spelled(markdownToAdf(markdown)) })),
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ function fixtureNames(kind, extension) {
|
|||||||
.sort()
|
.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert-corpus.js tags -0 so it survives WebDriver's JSON.
|
||||||
|
function revived(text) {
|
||||||
|
return JSON.parse(text, (_, value) => (value === '\u0000-0' ? -0 : value))
|
||||||
|
}
|
||||||
|
|
||||||
function refusal(result) {
|
function refusal(result) {
|
||||||
return result.ok ? '' : `${result.error.code}: ${result.error.message}`
|
return result.ok ? '' : `${result.error.code}: ${result.error.message}`
|
||||||
}
|
}
|
||||||
@@ -106,7 +111,7 @@ for (const [index, { json, markdown, name }] of corpus.roundTrip.entries()) {
|
|||||||
assert.ok(result.emitted.ok, `it did not emit — ${refusal(result.emitted)}`)
|
assert.ok(result.emitted.ok, `it did not emit — ${refusal(result.emitted)}`)
|
||||||
assert.equal(result.emitted.value, markdown)
|
assert.equal(result.emitted.value, markdown)
|
||||||
assert.ok(result.parsed.ok, `it did not parse — ${refusal(result.parsed)}`)
|
assert.ok(result.parsed.ok, `it did not parse — ${refusal(result.parsed)}`)
|
||||||
assert.equal(result.parsed.value, json)
|
assert.deepEqual(revived(result.parsed.value), JSON.parse(json))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +119,7 @@ for (const [index, { name }] of corpus.normalization.entries()) {
|
|||||||
const result = results.normalization[index]
|
const result = results.normalization[index]
|
||||||
checking(name, result, () => {
|
checking(name, result, () => {
|
||||||
assert.ok(result.parsed.ok, `it did not parse — ${refusal(result.parsed)}`)
|
assert.ok(result.parsed.ok, `it did not parse — ${refusal(result.parsed)}`)
|
||||||
assert.equal(result.parsed.value, fixture(name, '.json'))
|
assert.deepEqual(revived(result.parsed.value), JSON.parse(fixture(name, '.json')))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +129,7 @@ for (const [index, { json, name }] of corpus.realPayloads.entries()) {
|
|||||||
assert.ok(result.isDocument, `${name}.json is no ADF document`)
|
assert.ok(result.isDocument, `${name}.json is no ADF document`)
|
||||||
assert.ok(result.emitted.ok, `it did not emit — ${refusal(result.emitted)}`)
|
assert.ok(result.emitted.ok, `it did not emit — ${refusal(result.emitted)}`)
|
||||||
assert.ok(result.parsed.ok, `it did not parse back — ${refusal(result.parsed)}`)
|
assert.ok(result.parsed.ok, `it did not parse back — ${refusal(result.parsed)}`)
|
||||||
assert.equal(result.parsed.value, json)
|
assert.deepEqual(revived(result.parsed.value), JSON.parse(json))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user