mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 14:45:44 +01:00
Answer architecture round 2: every builder joins its pieces through one bounded join, the readers take the engine guard, every refusal stands at the document's path, and a portable list's refusal names its own place
This commit is contained in:
@@ -4,12 +4,6 @@ import { fileURLToPath } from 'node:url'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
|
||||
import { success, withinEngineLimits, type Result } from './result.ts'
|
||||
|
||||
function code(result: Result<string>): string {
|
||||
return result.ok ? `converted ${result.value}` : result.error.code
|
||||
}
|
||||
|
||||
const sourceRoot = dirname(fileURLToPath(import.meta.url))
|
||||
const union = /export type ConvertErrorCode =\n((?:\s+\| '[a-z-]+'\n)+)/
|
||||
const declared = /'([a-z-]+)'/g
|
||||
@@ -35,36 +29,3 @@ function calledCodes(): string[] {
|
||||
test('every ConvertErrorCode is the code of a production call site, and every call site names a declared one', () => {
|
||||
assert.deepEqual(calledCodes(), declaredCodes())
|
||||
})
|
||||
|
||||
test('refuses where the engine runs out of string or array, and lets a stack overflow or any other throw through', () => {
|
||||
const overflow = new Error('allocation size overflow')
|
||||
overflow.name = 'InternalError'
|
||||
assert.deepEqual(
|
||||
withinEngineLimits(() => {
|
||||
throw overflow
|
||||
}),
|
||||
{ error: { code: 'unsupported-node-shape', message: 'the output would be longer than the longest string or array this JavaScript engine builds (allocation size overflow)', path: [] }, ok: false },
|
||||
)
|
||||
assert.equal(
|
||||
code(
|
||||
withinEngineLimits(() => {
|
||||
throw new RangeError('Invalid array length')
|
||||
}),
|
||||
),
|
||||
'unsupported-node-shape',
|
||||
)
|
||||
assert.throws(() =>
|
||||
withinEngineLimits(() => {
|
||||
throw new RangeError('Maximum call stack size exceeded')
|
||||
}),
|
||||
)
|
||||
assert.throws(() =>
|
||||
withinEngineLimits(() => {
|
||||
throw new TypeError('a bug')
|
||||
}),
|
||||
)
|
||||
assert.deepEqual(
|
||||
withinEngineLimits(() => success('x')),
|
||||
{ ok: true, value: 'x' },
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user