3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer architecture round 1: 0 🔴, 2 🟡; join empty-keys to the directive grammar and name the readers by direction

This commit is contained in:
2026-10-21 23:49:15 +02:00
committed by Lillem4n
parent b080410852
commit 3f7b3a386e
11 changed files with 46 additions and 28 deletions
+23 -9
View File
@@ -1,17 +1,22 @@
import assert from 'node:assert/strict'
import { dirname, join } from 'node:path'
import { dirname, join, relative } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readdirSync, readFileSync } from 'node:fs'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import test from 'node:test'
const markdown = join(dirname(fileURLToPath(import.meta.url)), '..', 'markdown')
const importSpecifier = /\bfrom '([^']+)'/g
function importsOf(directory: string): { file: string; specifier: string }[] {
const imports: { file: string; specifier: string }[] = []
for (const file of readdirSync(join(markdown, directory)).filter((name) => name.endsWith('.ts') && !name.endsWith('.test.ts'))) {
for (const match of readFileSync(join(markdown, directory, file), 'utf8').matchAll(importSpecifier)) {
imports.push({ file: `${directory}/${file}`, specifier: match[1] ?? '' })
function importsOf(directory: string): { file: string; target: string }[] {
const imports: { file: string; target: string }[] = []
for (const name of readdirSync(join(markdown, directory))) {
const path = join(directory, name)
if (statSync(join(markdown, path)).isDirectory()) {
imports.push(...importsOf(path))
} else if (name.endsWith('.ts') && !name.endsWith('.test.ts')) {
for (const match of readFileSync(join(markdown, path), 'utf8').matchAll(importSpecifier)) {
imports.push({ file: path, target: relative(markdown, join(markdown, directory, match[1] ?? '')) })
}
}
}
return imports
@@ -19,10 +24,19 @@ function importsOf(directory: string): { file: string; specifier: string }[] {
// docs/decisions.md §The source parts by ADF and format
test('parse/ asks emit/ only through the module that names its questions', () => {
const reached = importsOf('parse').filter(({ specifier }) => specifier.startsWith('../emit/'))
const reached = importsOf('parse').filter(({ target }) => target.startsWith('emit/'))
assert.ok(reached.length > 0)
assert.deepEqual(
reached.filter(({ specifier }) => specifier !== '../emit/spelling-questions.ts'),
reached.filter(({ target }) => target !== 'emit/spelling-questions.ts'),
[],
)
})
test('directive/ imports nothing from emit/ or parse/', () => {
const imports = importsOf('directive')
assert.ok(imports.length > 0)
assert.deepEqual(
imports.filter(({ target }) => target.startsWith('emit/') || target.startsWith('parse/')),
[],
)
})