mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 22:25:44 +01:00
Answer architecture round 1: name a non-string by typeof alone, name and comment what the seats could not read, file items 81 and 82
This commit is contained in:
@@ -648,7 +648,7 @@ function markType(character: string, used: number): string {
|
||||
return used === 2 ? 'strong' : 'em'
|
||||
}
|
||||
|
||||
// A node cannot carry one mark type twice (docs/decisions.md §No schema validation).
|
||||
// Nested spellings of one mark (`*(*a*)*`) name it once: a node carries one mark of a type.
|
||||
function applyMark(nodes: readonly Inline[], mark: AdfMark): Inline[] {
|
||||
return nodes.map((node) => {
|
||||
if (!isNode(node)) return node
|
||||
|
||||
@@ -85,7 +85,9 @@ function table(...rows: AdfNode[]): AdfNode {
|
||||
}
|
||||
|
||||
test('refuses a value that is not a string, in both readers, at the start of the input', () => {
|
||||
const found: [unknown, string][] = [[null, 'null'], [undefined, 'undefined'], [42, '42'], [{}, 'an object'], [['x'], 'an array']]
|
||||
const revoked = Proxy.revocable({}, {})
|
||||
revoked.revoke()
|
||||
const found: [unknown, string][] = [[null, 'null'], [undefined, 'undefined'], [42, 'a number'], [10n, 'a bigint'], [['x'], 'an object'], [revoked.proxy, 'an object']]
|
||||
for (const read of [markdownToAdf, plainMarkdownToAdf]) {
|
||||
for (const [value, described] of found) {
|
||||
assert.deepEqual(Reflect.apply(read, undefined, [value]), {
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { LinkDefinitions } from './inline-content.ts'
|
||||
import { carryFenceType, readCarriedBlock } from '../opaque-carry.ts'
|
||||
import { commonMarkSpelling, type SpellingMemo } from '../emit/adf-to-markdown.ts'
|
||||
import { documentAttribute, documentName, documentSpelling, listBreakName, listBreakSpelling } from '../block-directive.ts'
|
||||
import { describe, emptyKeys, nodeAttrs, nodeContent } from '../../adf/document.ts'
|
||||
import { emptyKeys, nodeAttrs, nodeContent } from '../../adf/document.ts'
|
||||
import { failure, faulted, positioned, success, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts'
|
||||
import { inlineLeaves } from '../plain/inline-reduction.ts'
|
||||
import { languageSlot } from '../code-language.ts'
|
||||
@@ -39,7 +39,7 @@ export function plainMarkdownToAdf(markdown: string): Result<AdfDocument, ParseE
|
||||
}
|
||||
|
||||
function readDocument(markdown: string, flavour: Flavour): Result<AdfDocument, ParseError> {
|
||||
if (typeof markdown !== 'string') return positioned(failure('not-a-string', `markdown is a string: found ${describe(markdown)}`, []), documentStart)
|
||||
if (typeof markdown !== 'string') return positioned(failure('not-a-string', `markdown is a string: found ${typeName(markdown)}`, []), documentStart)
|
||||
const parsed = parseBlocks(markdown)
|
||||
const [only] = parsed.blocks
|
||||
if (parsed.blocks.length === 1 && only?.kind === 'directive' && only.name === documentName) {
|
||||
@@ -54,6 +54,14 @@ function readDocument(markdown: string, flavour: Flavour): Result<AdfDocument, P
|
||||
return success(document)
|
||||
}
|
||||
|
||||
// `typeof` alone, since anything more throws on a revoked Proxy.
|
||||
function typeName(value: unknown): string {
|
||||
if (value === null) return 'null'
|
||||
const type = typeof value
|
||||
if (type === 'undefined') return type
|
||||
return type === 'object' ? 'an object' : `a ${type}`
|
||||
}
|
||||
|
||||
function readBlocks(blocks: readonly Block[], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode[]> {
|
||||
if (depth > largestNesting) return failure('unsupported-nesting-depth', `the input nests deeper than the ${largestNesting} levels the parser carries`, path)
|
||||
const content: AdfNode[] = []
|
||||
|
||||
Reference in New Issue
Block a user