@bendyline/squisq 1.5.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -10
- package/dist/{Doc-BBVGq1_9.d.ts → Doc-ylqWKDc_.d.ts} +248 -37
- package/dist/{ImageEditDoc-FuyGtt6o.d.ts → ImageEditDoc-D828IXJ1.d.ts} +1 -1
- package/dist/annotationCoercion-Dr_DY9Hx.d.ts +86 -0
- package/dist/{chunk-VWUFZ6ZG.js → chunk-3E5F2XMR.js} +2 -29
- package/dist/chunk-3E5F2XMR.js.map +1 -0
- package/dist/chunk-4X3JQXNM.js +35 -0
- package/dist/chunk-4X3JQXNM.js.map +1 -0
- package/dist/{chunk-P3K7NLHF.js → chunk-5DKBFXPY.js} +31 -121
- package/dist/chunk-5DKBFXPY.js.map +1 -0
- package/dist/{chunk-DLXZMS5K.js → chunk-5J4HKRJF.js} +51 -3
- package/dist/chunk-5J4HKRJF.js.map +1 -0
- package/dist/chunk-5UYI3RJB.js +2503 -0
- package/dist/chunk-5UYI3RJB.js.map +1 -0
- package/dist/{chunk-BEQODJWV.js → chunk-66QO7XFB.js} +11 -291
- package/dist/chunk-66QO7XFB.js.map +1 -0
- package/dist/{chunk-KKNUBQ6Y.js → chunk-6PJRB2CF.js} +156 -91
- package/dist/chunk-6PJRB2CF.js.map +1 -0
- package/dist/{chunk-HWVFJAAH.js → chunk-AMIR72JP.js} +28 -10
- package/dist/chunk-AMIR72JP.js.map +1 -0
- package/dist/chunk-FVJUUTEM.js +74 -0
- package/dist/chunk-FVJUUTEM.js.map +1 -0
- package/dist/{chunk-5TYS5V3G.js → chunk-GF3BVNLU.js} +4127 -3538
- package/dist/chunk-GF3BVNLU.js.map +1 -0
- package/dist/{chunk-Q3ROPT5H.js → chunk-GZY66SDN.js} +1 -1
- package/dist/{chunk-Q3ROPT5H.js.map → chunk-GZY66SDN.js.map} +1 -1
- package/dist/chunk-JOQYPRDZ.js +127 -0
- package/dist/chunk-JOQYPRDZ.js.map +1 -0
- package/dist/{chunk-A4O7GIWE.js → chunk-LYNJEOAC.js} +10 -73
- package/dist/chunk-LYNJEOAC.js.map +1 -0
- package/dist/{chunk-LDQ2HJIX.js → chunk-PXLVXTLW.js} +252 -54
- package/dist/chunk-PXLVXTLW.js.map +1 -0
- package/dist/{chunk-TQWLI6S2.js → chunk-Q7LROV2H.js} +4 -2
- package/dist/{chunk-TQWLI6S2.js.map → chunk-Q7LROV2H.js.map} +1 -1
- package/dist/{chunk-T5UK6YOB.js → chunk-QTSJOY54.js} +60 -17
- package/dist/chunk-QTSJOY54.js.map +1 -0
- package/dist/chunk-QVANWDPH.js +2358 -0
- package/dist/chunk-QVANWDPH.js.map +1 -0
- package/dist/{chunk-GPLTCSXO.js → chunk-R2GC6RLD.js} +7 -7
- package/dist/chunk-R2GC6RLD.js.map +1 -0
- package/dist/chunk-R2YZTCLO.js +292 -0
- package/dist/chunk-R2YZTCLO.js.map +1 -0
- package/dist/chunk-S7A5D7ZJ.js +174 -0
- package/dist/chunk-S7A5D7ZJ.js.map +1 -0
- package/dist/chunk-T3TI7GSZ.js +884 -0
- package/dist/chunk-T3TI7GSZ.js.map +1 -0
- package/dist/{chunk-LTN6I7QW.js → chunk-TUWMK62B.js} +55 -4
- package/dist/chunk-TUWMK62B.js.map +1 -0
- package/dist/{chunk-IMSCRLLV.js → chunk-VR7UPJ7C.js} +35 -25
- package/dist/chunk-VR7UPJ7C.js.map +1 -0
- package/dist/doc/index.d.ts +2334 -5
- package/dist/doc/index.js +127 -33
- package/dist/generate/index.d.ts +7 -2
- package/dist/generate/index.js +1 -1
- package/dist/imageEdit/index.d.ts +9 -6
- package/dist/imageEdit/index.js +3 -3
- package/dist/index.d.ts +12 -10
- package/dist/index.js +246 -80
- package/dist/jsonForm/index.d.ts +7 -3
- package/dist/jsonForm/index.js +9 -4
- package/dist/markdown/index.d.ts +6 -70
- package/dist/markdown/index.js +13 -9
- package/dist/narration/index.d.ts +618 -0
- package/dist/narration/index.js +82 -0
- package/dist/recommend/index.d.ts +15 -1
- package/dist/recommend/index.js +2 -2
- package/dist/schemas/index.d.ts +28 -6
- package/dist/schemas/index.js +15 -13
- package/dist/spatial/index.d.ts +0 -1
- package/dist/spatial/index.js +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/{themeLibrary-CehcJhzz.d.ts → themeLibrary-RjVgLpUi.d.ts} +10 -11
- package/dist/timing/index.js +5 -3
- package/dist/transform/index.d.ts +35 -24
- package/dist/transform/index.js +9 -10
- package/dist/{types-DlAZ7MW4.d.ts → types-BwMPl2CB.d.ts} +1 -1
- package/dist/{types-D98li1gV.d.ts → types-C4kiRn_k.d.ts} +3 -1
- package/dist/versions/index.d.ts +2 -1
- package/dist/versions/index.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/applyNarrationTiming.test.ts +190 -0
- package/src/__tests__/applyRenderStyle.test.ts +3 -3
- package/src/__tests__/asciiDiagramBattle.test.ts +246 -0
- package/src/__tests__/asciiDiagramDetect.test.ts +162 -0
- package/src/__tests__/asciiDiagramMapping.test.ts +38 -0
- package/src/__tests__/asciiDiagramParse.test.ts +233 -0
- package/src/__tests__/asciiDiagramPipeline.test.ts +273 -0
- package/src/__tests__/asciiDiagramRender.test.ts +162 -0
- package/src/__tests__/asciiDiagramRepair.test.ts +84 -0
- package/src/__tests__/asciiTimelineDetect.test.ts +157 -0
- package/src/__tests__/asciiTimelineParse.test.ts +205 -0
- package/src/__tests__/asciiTimelinePipeline.test.ts +349 -0
- package/src/__tests__/asciiTimelineRender.test.ts +376 -0
- package/src/__tests__/attrTokens.test.ts +5 -0
- package/src/__tests__/contentContainer.test.ts +43 -0
- package/src/__tests__/customTemplatesFrontmatter.test.ts +0 -15
- package/src/__tests__/dataTable.test.ts +25 -15
- package/src/__tests__/diagramBlock.test.ts +3 -3
- package/src/__tests__/diagramText.test.ts +26 -0
- package/src/__tests__/docToMarkdownMedia.test.ts +83 -0
- package/src/__tests__/drawingBlock.test.ts +3 -3
- package/src/__tests__/fixtures/asciiDiagramBattle.ts +512 -0
- package/src/__tests__/fixtures/asciiDiagrams.ts +287 -0
- package/src/__tests__/fixtures/asciiTimelines.ts +35 -0
- package/src/__tests__/fixtures/treeviewFixtures.ts +243 -0
- package/src/__tests__/getLayers.test.ts +32 -18
- package/src/__tests__/getLayersFallback.test.ts +8 -8
- package/src/__tests__/imageEditVersions.test.ts +2 -0
- package/src/__tests__/jsonForm.pointer.test.ts +47 -1
- package/src/__tests__/layoutBlock.test.ts +3 -3
- package/src/__tests__/majorApiTypes.test.ts +18 -0
- package/src/__tests__/markdown.test.ts +41 -0
- package/src/__tests__/matchFontFamily.test.ts +114 -0
- package/src/__tests__/materializeBlockLayers.test.ts +135 -0
- package/src/__tests__/materializeTestUtils.ts +17 -0
- package/src/__tests__/narrationAlign.test.ts +150 -0
- package/src/__tests__/narrationFeatures.test.ts +71 -0
- package/src/__tests__/narrationNuclei.test.ts +45 -0
- package/src/__tests__/narrationPacing.test.ts +189 -0
- package/src/__tests__/narrationScript.test.ts +149 -0
- package/src/__tests__/narrationSessionRepro.test.ts +62 -0
- package/src/__tests__/narrationSidecar.test.ts +88 -0
- package/src/__tests__/narrationSyllables.test.ts +65 -0
- package/src/__tests__/narrationTestSignals.ts +167 -0
- package/src/__tests__/narrationVad.test.ts +66 -0
- package/src/__tests__/resolveDocTheme.test.ts +16 -2
- package/src/__tests__/rootExports.test.ts +18 -0
- package/src/__tests__/scopedContentContainer.test.ts +20 -0
- package/src/__tests__/shapeGeometry.test.ts +12 -0
- package/src/__tests__/templateAnnotationParse.test.ts +10 -0
- package/src/__tests__/templateInputs.test.ts +69 -0
- package/src/__tests__/templateMetadata.test.ts +2 -1
- package/src/__tests__/templates.test.ts +143 -17
- package/src/__tests__/themeCompile.test.ts +49 -22
- package/src/__tests__/transformProvenance.test.ts +160 -0
- package/src/__tests__/transformV2.test.ts +40 -14
- package/src/__tests__/treeviewBattle.test.ts +76 -0
- package/src/__tests__/treeviewDetect.test.ts +168 -0
- package/src/__tests__/treeviewParse.test.ts +118 -0
- package/src/__tests__/treeviewPipeline.test.ts +183 -0
- package/src/__tests__/treeviewRender.test.ts +91 -0
- package/src/__tests__/versions.test.ts +44 -0
- package/src/doc/applyNarrationTiming.ts +244 -0
- package/src/doc/asciiDiagram/chars.ts +210 -0
- package/src/doc/asciiDiagram/detect.ts +175 -0
- package/src/doc/asciiDiagram/index.ts +38 -0
- package/src/doc/asciiDiagram/mapping.ts +225 -0
- package/src/doc/asciiDiagram/parse.ts +1095 -0
- package/src/doc/asciiDiagram/render.ts +963 -0
- package/src/doc/asciiDiagram/repair.ts +400 -0
- package/src/doc/asciiDiagram/types.ts +65 -0
- package/src/doc/asciiTimeline/detect.ts +138 -0
- package/src/doc/asciiTimeline/index.ts +26 -0
- package/src/doc/asciiTimeline/mapping.ts +43 -0
- package/src/doc/asciiTimeline/parse.ts +870 -0
- package/src/doc/asciiTimeline/render.ts +427 -0
- package/src/doc/asciiTimeline/types.ts +73 -0
- package/src/doc/asciiTimeline/wrappedFlow.ts +427 -0
- package/src/doc/audioMapping.ts +60 -46
- package/src/doc/customTemplatesFrontmatter.ts +0 -41
- package/src/doc/docToMarkdown.ts +70 -2
- package/src/doc/index.ts +76 -4
- package/src/doc/markdownToDoc.ts +135 -1
- package/src/doc/materializeBlockLayers.ts +304 -0
- package/src/doc/mediaAnnotations.ts +20 -0
- package/src/doc/resolveDocTheme.ts +8 -7
- package/src/doc/templateInputs.ts +185 -2
- package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +22 -8
- package/src/doc/templates/diagramBlock.ts +237 -38
- package/src/doc/templates/fallbackBlock.ts +1 -1
- package/src/doc/templates/index.ts +134 -279
- package/src/doc/templates/inputDescriptors.ts +20 -1
- package/src/doc/templates/metadata.ts +10 -0
- package/src/doc/templates/persistentLayers.ts +12 -126
- package/src/doc/templates/registry.ts +88 -0
- package/src/doc/templates/templateNames.ts +22 -0
- package/src/doc/templates/timelineBlock.ts +613 -0
- package/src/doc/templates/treeBlock.ts +131 -0
- package/src/doc/treeview/chars.ts +72 -0
- package/src/doc/treeview/detect.ts +145 -0
- package/src/doc/treeview/index.ts +30 -0
- package/src/doc/treeview/mapping.ts +95 -0
- package/src/doc/treeview/parse.ts +201 -0
- package/src/doc/treeview/render.ts +41 -0
- package/src/doc/treeview/types.ts +43 -0
- package/src/doc/utils/applyRenderStyle.ts +2 -9
- package/src/doc/utils/diagramText.ts +78 -0
- package/src/doc/utils/shapeGeometry.ts +67 -5
- package/src/doc/validate.ts +1 -1
- package/src/generate/templateMapper.ts +7 -0
- package/src/imageEdit/export.ts +6 -5
- package/src/imageEdit/versionPaths.ts +13 -26
- package/src/imageEdit/versions.ts +21 -100
- package/src/index.ts +1 -0
- package/src/internal/immutable.ts +58 -0
- package/src/jsonForm/index.ts +9 -1
- package/src/jsonForm/pointer.ts +68 -23
- package/src/markdown/attrTokens.ts +7 -5
- package/src/markdown/index.ts +1 -0
- package/src/markdown/stringify.ts +4 -9
- package/src/markdown/utils.ts +36 -14
- package/src/narration/align.ts +514 -0
- package/src/narration/features.ts +231 -0
- package/src/narration/index.ts +86 -0
- package/src/narration/nuclei.ts +118 -0
- package/src/narration/pacing.ts +211 -0
- package/src/narration/script.ts +239 -0
- package/src/narration/session.ts +100 -0
- package/src/narration/sidecar.ts +187 -0
- package/src/narration/syllables.ts +85 -0
- package/src/narration/trace.ts +50 -0
- package/src/narration/types.ts +299 -0
- package/src/narration/vad.ts +131 -0
- package/src/recommend/numberHighlight.ts +25 -0
- package/src/recommend/templates.ts +108 -12
- package/src/schemas/BlockTemplates.ts +156 -7
- package/src/schemas/Doc.ts +72 -9
- package/src/schemas/Media.ts +12 -2
- package/src/schemas/Theme.ts +45 -25
- package/src/schemas/Viewport.ts +2 -2
- package/src/schemas/fontStacks.ts +79 -0
- package/src/schemas/themeCompile.ts +15 -0
- package/src/schemas/themeConstants.ts +2 -0
- package/src/schemas/themeLibrary.ts +25 -19
- package/src/schemas/themeValidator.ts +1 -1
- package/src/spatial/Geohash.ts +0 -3
- package/src/storage/ContentContainer.ts +17 -9
- package/src/storage/ScopedContentContainer.ts +45 -15
- package/src/transform/applyTransform.ts +5 -5
- package/src/transform/index.ts +3 -1
- package/src/transform/registry.ts +169 -49
- package/src/transform/templateSelector.ts +21 -2
- package/src/transform/timingAllocator.ts +152 -21
- package/src/transform/types.ts +14 -1
- package/src/versions/gitignore.ts +34 -0
- package/src/versions/index.ts +2 -0
- package/src/versions/operations.ts +18 -104
- package/src/versions/paths.ts +13 -28
- package/src/versions/snapshotStore.ts +202 -0
- package/src/versions/types.ts +3 -1
- package/dist/chunk-5TYS5V3G.js.map +0 -1
- package/dist/chunk-A4O7GIWE.js.map +0 -1
- package/dist/chunk-BEQODJWV.js.map +0 -1
- package/dist/chunk-DLXZMS5K.js.map +0 -1
- package/dist/chunk-GPLTCSXO.js.map +0 -1
- package/dist/chunk-HWVFJAAH.js.map +0 -1
- package/dist/chunk-IMSCRLLV.js.map +0 -1
- package/dist/chunk-JELIRVDP.js +0 -24
- package/dist/chunk-JELIRVDP.js.map +0 -1
- package/dist/chunk-KKNUBQ6Y.js.map +0 -1
- package/dist/chunk-LDQ2HJIX.js.map +0 -1
- package/dist/chunk-LTN6I7QW.js.map +0 -1
- package/dist/chunk-P3K7NLHF.js.map +0 -1
- package/dist/chunk-T5UK6YOB.js.map +0 -1
- package/dist/chunk-UY7KGQ5R.js +0 -192
- package/dist/chunk-UY7KGQ5R.js.map +0 -1
- package/dist/chunk-VLJJHDAC.js +0 -218
- package/dist/chunk-VLJJHDAC.js.map +0 -1
- package/dist/chunk-VWUFZ6ZG.js.map +0 -1
- package/dist/story/index.d.ts +0 -1801
- package/dist/story/index.js +0 -279
- package/src/doc/getLayers.ts +0 -195
- /package/dist/{story → narration}/index.js.map +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
detectTree,
|
|
4
|
+
parseTree,
|
|
5
|
+
renderTree,
|
|
6
|
+
treeFromTemplateData,
|
|
7
|
+
treeToTemplateData,
|
|
8
|
+
type Tree,
|
|
9
|
+
} from '../doc/treeview/index.js';
|
|
10
|
+
import { TREE_FIXTURES } from './fixtures/treeviewFixtures.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Battle test: a broad corpus of AI-style trees (project scaffolds,
|
|
14
|
+
* monorepos, dependency trees, category/decision outlines, forests) each
|
|
15
|
+
* asserting detect + parse-accuracy + fixpoint + byte-stability + mapping
|
|
16
|
+
* round-trip. Peer to asciiDiagramBattle.test.ts.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function flat(t: Tree): string[] {
|
|
20
|
+
const out: string[] = [];
|
|
21
|
+
const walk = (nodes: Tree['roots'], depth: number): void => {
|
|
22
|
+
for (const n of nodes) {
|
|
23
|
+
out.push(`${depth}:${n.label}${n.comment ? ` #${n.comment}` : ''}`);
|
|
24
|
+
walk(n.children, depth + 1);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
walk(t.roots, 0);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('tree battle — every fixture', () => {
|
|
32
|
+
for (const fx of TREE_FIXTURES) {
|
|
33
|
+
describe(`${fx.category}: ${fx.name}`, () => {
|
|
34
|
+
const t = parseTree(fx.art);
|
|
35
|
+
|
|
36
|
+
it('detects as a tree', () => {
|
|
37
|
+
expect(detectTree(fx.art).isTree).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('parses the intended hierarchy', () => {
|
|
41
|
+
expect(flat(t)).toEqual(fx.expect);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('render→parse preserves the semantic (fixpoint)', () => {
|
|
45
|
+
expect(flat(parseTree(renderTree(t)))).toEqual(flat(t));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('render→parse→render is byte-stable across three cycles', () => {
|
|
49
|
+
const t1 = renderTree(t);
|
|
50
|
+
const t2 = renderTree(parseTree(t1));
|
|
51
|
+
const t3 = renderTree(parseTree(t2));
|
|
52
|
+
expect(t2).toBe(t1);
|
|
53
|
+
expect(t3).toBe(t1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('templateData round-trips', () => {
|
|
57
|
+
const back = treeFromTemplateData(treeToTemplateData(t).items, { style: t.style });
|
|
58
|
+
expect(flat(back)).toEqual(flat(t));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('tree battle — coverage sanity', () => {
|
|
65
|
+
it('covers every intended category', () => {
|
|
66
|
+
const categories = new Set(TREE_FIXTURES.map((f) => f.category));
|
|
67
|
+
for (const c of ['scaffold', 'style', 'comments', 'outline', 'shape']) {
|
|
68
|
+
expect(categories.has(c)).toBe(true);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('fixture names are unique', () => {
|
|
73
|
+
const names = TREE_FIXTURES.map((f) => f.name);
|
|
74
|
+
expect(new Set(names).size).toBe(names.length);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
detectTree,
|
|
4
|
+
isTreeFence,
|
|
5
|
+
isEligibleTreeFenceLang,
|
|
6
|
+
isExplicitTreeLang,
|
|
7
|
+
} from '../doc/treeview/index.js';
|
|
8
|
+
import { detectAsciiDiagram, isAsciiDiagramFence } from '../doc/asciiDiagram/index.js';
|
|
9
|
+
import type { MarkdownCodeBlock } from '../markdown/types.js';
|
|
10
|
+
import { TREE_FIXTURES } from './fixtures/treeviewFixtures.js';
|
|
11
|
+
|
|
12
|
+
const NEGATIVES: Record<string, string> = {
|
|
13
|
+
boxDiagram: [
|
|
14
|
+
'┌────────┐',
|
|
15
|
+
'│ Alpha │',
|
|
16
|
+
'└───┬────┘',
|
|
17
|
+
' │',
|
|
18
|
+
' ▼',
|
|
19
|
+
'┌────────┐',
|
|
20
|
+
'│ Beta │',
|
|
21
|
+
'└────────┘',
|
|
22
|
+
].join('\n'),
|
|
23
|
+
// A hand-drawn box diagram whose right borders are misaligned (e.g. a
|
|
24
|
+
// rename widened the labels), so NO box traces as a closed rectangle. It
|
|
25
|
+
// must still be rejected as a tree — the top corners (┌ ┐) give it away.
|
|
26
|
+
misalignedBoxDiagram: [
|
|
27
|
+
'┌─────────────────┐',
|
|
28
|
+
'│ @scope/tooling │',
|
|
29
|
+
'│ CLI + MCP server │',
|
|
30
|
+
'└───────┬─────────┘',
|
|
31
|
+
' │',
|
|
32
|
+
' ▼',
|
|
33
|
+
'┌───────┴──┐ ┌──────────┐',
|
|
34
|
+
'│ kernel │ │ client │',
|
|
35
|
+
'└──────────┘ └──────────┘',
|
|
36
|
+
].join('\n'),
|
|
37
|
+
markdownTable: ['| Name | Role |', '|-------|----------|', '| Ada | Engineer |'].join(
|
|
38
|
+
'\n',
|
|
39
|
+
),
|
|
40
|
+
prose: [
|
|
41
|
+
'This is a paragraph of ordinary text.',
|
|
42
|
+
'It has multiple lines but no tree structure at all.',
|
|
43
|
+
'Nothing here should look like a hierarchy.',
|
|
44
|
+
].join('\n'),
|
|
45
|
+
indentedCode: [
|
|
46
|
+
'function foo() {',
|
|
47
|
+
' const x = 1;',
|
|
48
|
+
' if (x) {',
|
|
49
|
+
' return x;',
|
|
50
|
+
' }',
|
|
51
|
+
'}',
|
|
52
|
+
].join('\n'),
|
|
53
|
+
yaml: ['services:', ' web:', ' image: nginx', ' ports:', ' - "80:80"'].join('\n'),
|
|
54
|
+
singleLine: 'just one line',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
describe('detectTree — negative corpus (must all reject)', () => {
|
|
58
|
+
for (const [name, art] of Object.entries(NEGATIVES)) {
|
|
59
|
+
it(`rejects ${name}`, () => {
|
|
60
|
+
const d = detectTree(art);
|
|
61
|
+
expect(d.isTree).toBe(false);
|
|
62
|
+
expect(d.reasons.length).toBeGreaterThan(0);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
it('rejects a misaligned box diagram via the corner signal, not the box count', () => {
|
|
67
|
+
// No box traces closed (misaligned), so the ≥2-box rule can't catch it —
|
|
68
|
+
// the corner rejector is what keeps it out of the tree widget.
|
|
69
|
+
const d = detectTree(NEGATIVES.misalignedBoxDiagram);
|
|
70
|
+
expect(d.isTree).toBe(false);
|
|
71
|
+
expect(d.reasons).toContain('has-box-corners');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('rejects box-corner art even when explicitly `tree`-tagged', () => {
|
|
75
|
+
expect(detectTree(NEGATIVES.misalignedBoxDiagram, { explicit: true }).isTree).toBe(false);
|
|
76
|
+
expect(detectTree(NEGATIVES.boxDiagram, { explicit: true }).isTree).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('detectTree — positive fixtures (must all accept)', () => {
|
|
81
|
+
for (const fx of TREE_FIXTURES) {
|
|
82
|
+
it(`accepts ${fx.name}`, () => {
|
|
83
|
+
const d = detectTree(fx.art);
|
|
84
|
+
expect(d.isTree).toBe(true);
|
|
85
|
+
expect(d.tree).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('mutual exclusion with the diagram codec', () => {
|
|
91
|
+
it('a box diagram is a diagram, not a tree', () => {
|
|
92
|
+
expect(detectAsciiDiagram(NEGATIVES.boxDiagram).isDiagram).toBe(true);
|
|
93
|
+
expect(detectTree(NEGATIVES.boxDiagram).isTree).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('every tree fixture is a tree, not a diagram', () => {
|
|
97
|
+
for (const fx of TREE_FIXTURES) {
|
|
98
|
+
expect(detectTree(fx.art).isTree).toBe(true);
|
|
99
|
+
expect(detectAsciiDiagram(fx.art).isDiagram).toBe(false);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('explicit `tree` tag (lenient detection)', () => {
|
|
105
|
+
const FLAT = ['README.md', 'index.ts', 'package.json'].join('\n');
|
|
106
|
+
const SINGLE = 'src/';
|
|
107
|
+
|
|
108
|
+
it('isExplicitTreeLang matches only the `tree` tag', () => {
|
|
109
|
+
for (const lang of ['tree', ' Tree ', 'TREE']) expect(isExplicitTreeLang(lang)).toBe(true);
|
|
110
|
+
for (const lang of [undefined, null, '', 'text', 'ascii', 'diagram', 'js'])
|
|
111
|
+
expect(isExplicitTreeLang(lang)).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('a flat connector-less list is rejected untagged but accepted when explicit', () => {
|
|
115
|
+
// The exact bug the fence tag fixes: flattening a tree drops its
|
|
116
|
+
// connectors, so auto-detection rejects it on round-trip. The explicit
|
|
117
|
+
// `tree` tag trusts the author and keeps it a tree.
|
|
118
|
+
expect(detectTree(FLAT).isTree).toBe(false);
|
|
119
|
+
const explicit = detectTree(FLAT, { explicit: true });
|
|
120
|
+
expect(explicit.isTree).toBe(true);
|
|
121
|
+
expect(explicit.tree?.roots).toHaveLength(3);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('a single-node tree is accepted when explicit', () => {
|
|
125
|
+
expect(detectTree(SINGLE).isTree).toBe(false);
|
|
126
|
+
expect(detectTree(SINGLE, { explicit: true }).isTree).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('still rejects a box diagram even when explicitly tagged', () => {
|
|
130
|
+
expect(detectTree(NEGATIVES.boxDiagram, { explicit: true }).isTree).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('still rejects a markdown table even when explicitly tagged', () => {
|
|
134
|
+
expect(detectTree(NEGATIVES.markdownTable, { explicit: true }).isTree).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('isTreeFence accepts a flat `tree`-tagged fence via the lang gate', () => {
|
|
138
|
+
const fence: MarkdownCodeBlock = { type: 'code', lang: 'tree', value: FLAT };
|
|
139
|
+
expect(isTreeFence(fence)).toBe(true);
|
|
140
|
+
// The same content in a bare fence is not auto-detected.
|
|
141
|
+
expect(isTreeFence({ type: 'code', value: FLAT })).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('fence language gate', () => {
|
|
146
|
+
it('allows inert langs incl. tree; rejects real languages', () => {
|
|
147
|
+
for (const lang of [undefined, null, '', 'text', 'txt', 'plain', 'tree', 'ascii']) {
|
|
148
|
+
expect(isEligibleTreeFenceLang(lang)).toBe(true);
|
|
149
|
+
}
|
|
150
|
+
for (const lang of ['js', 'python', 'yaml', 'json', 'bash']) {
|
|
151
|
+
expect(isEligibleTreeFenceLang(lang)).toBe(false);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('isTreeFence combines the lang gate with content detection', () => {
|
|
156
|
+
const art = TREE_FIXTURES[0].art;
|
|
157
|
+
const fence = (lang?: string): MarkdownCodeBlock => ({
|
|
158
|
+
type: 'code',
|
|
159
|
+
...(lang !== undefined ? { lang } : {}),
|
|
160
|
+
value: art,
|
|
161
|
+
});
|
|
162
|
+
expect(isTreeFence(fence())).toBe(true);
|
|
163
|
+
expect(isTreeFence(fence('tree'))).toBe(true);
|
|
164
|
+
expect(isTreeFence(fence('js'))).toBe(false);
|
|
165
|
+
// And it is NOT an ascii-diagram fence.
|
|
166
|
+
expect(isAsciiDiagramFence(fence())).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseTree, type TreeNode } from '../doc/treeview/index.js';
|
|
3
|
+
|
|
4
|
+
/** Flatten to "depth:label[ #comment]" lines, depth-first. */
|
|
5
|
+
function flat(nodes: readonly TreeNode[], depth = 0, out: string[] = []): string[] {
|
|
6
|
+
for (const n of nodes) {
|
|
7
|
+
out.push(`${depth}:${n.label}${n.comment ? ` #${n.comment}` : ''}`);
|
|
8
|
+
flat(n.children, depth + 1, out);
|
|
9
|
+
}
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('parseTree — renditions', () => {
|
|
14
|
+
it('parses a Unicode file tree', () => {
|
|
15
|
+
const art = [
|
|
16
|
+
'src/',
|
|
17
|
+
'├── index.ts',
|
|
18
|
+
'├── components/',
|
|
19
|
+
'│ ├── App.tsx',
|
|
20
|
+
'│ └── Button.tsx',
|
|
21
|
+
'└── utils/',
|
|
22
|
+
' └── math.ts',
|
|
23
|
+
].join('\n');
|
|
24
|
+
expect(flat(parseTree(art).roots)).toEqual([
|
|
25
|
+
'0:src/',
|
|
26
|
+
'1:index.ts',
|
|
27
|
+
'1:components/',
|
|
28
|
+
'2:App.tsx',
|
|
29
|
+
'2:Button.tsx',
|
|
30
|
+
'1:utils/',
|
|
31
|
+
'2:math.ts',
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('parses ASCII `|-- ` / `` `-- `` style with identical semantics', () => {
|
|
36
|
+
const art = ['src/', '|-- a.ts', '|-- sub/', '| `-- b.ts', '`-- c.ts'].join('\n');
|
|
37
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:src/', '1:a.ts', '1:sub/', '2:b.ts', '1:c.ts']);
|
|
38
|
+
expect(parseTree(art).style).toBe('ascii');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('parses `+-- ` style', () => {
|
|
42
|
+
const art = ['root', '+-- a', '| +-- a1', '+-- b'].join('\n');
|
|
43
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:root', '1:a', '2:a1', '1:b']);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('parses pure 2-space indentation', () => {
|
|
47
|
+
const art = ['src/', ' a.ts', ' sub/', ' b.ts'].join('\n');
|
|
48
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:src/', '1:a.ts', '1:sub/', '2:b.ts']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('parses 4-space indentation', () => {
|
|
52
|
+
const art = ['src/', ' a.ts', ' sub/', ' b.ts'].join('\n');
|
|
53
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:src/', '1:a.ts', '1:sub/', '2:b.ts']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('parses bullet-indented lists', () => {
|
|
57
|
+
const art = ['- src/', ' - a.ts', ' - sub/', ' - b.ts'].join('\n');
|
|
58
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:src/', '1:a.ts', '1:sub/', '2:b.ts']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('captures trailing comments (# and <--)', () => {
|
|
62
|
+
const art = ['p/', '├── a.ts # first', '└── b.ts <-- second'].join('\n');
|
|
63
|
+
const roots = parseTree(art).roots;
|
|
64
|
+
expect(flat(roots)).toEqual(['0:p/', '1:a.ts #first', '1:b.ts #second']);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('marks directories (trailing slash or has children)', () => {
|
|
68
|
+
const art = ['top', '├── leaf.txt', '└── branch', ' └── deep.txt'].join('\n');
|
|
69
|
+
const roots = parseTree(art).roots;
|
|
70
|
+
expect(roots[0].isDir).toBe(true); // has children
|
|
71
|
+
const leaf = roots[0].children.find((n) => n.id === 'leaf-txt');
|
|
72
|
+
expect(leaf?.isDir).toBe(false);
|
|
73
|
+
const branch = roots[0].children.find((n) => n.id === 'branch');
|
|
74
|
+
expect(branch?.isDir).toBe(true); // has children
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('parses a forest (multiple roots)', () => {
|
|
78
|
+
const art = ['a/', '└── a1', 'b/', '└── b1'].join('\n');
|
|
79
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:a/', '1:a1', '0:b/', '1:b1']);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('assigns stable, deduplicated ids', () => {
|
|
83
|
+
const art = ['root/', '├── index.ts', '└── sub/', ' └── index.ts'].join('\n');
|
|
84
|
+
const roots = parseTree(art).roots;
|
|
85
|
+
const ids: string[] = [];
|
|
86
|
+
const walk = (ns: TreeNode[]) => ns.forEach((n) => (ids.push(n.id), walk(n.children)));
|
|
87
|
+
walk(roots);
|
|
88
|
+
expect(ids).toEqual(['root', 'index-ts', 'sub', 'index-ts-2']);
|
|
89
|
+
// Stable across re-parses.
|
|
90
|
+
const ids2: string[] = [];
|
|
91
|
+
const walk2 = (ns: TreeNode[]) => ns.forEach((n) => (ids2.push(n.id), walk2(n.children)));
|
|
92
|
+
walk2(parseTree(art).roots);
|
|
93
|
+
expect(ids2).toEqual(ids);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('tolerates ragged dedents (clamp to nearest shallower level)', () => {
|
|
97
|
+
const art = ['a/', ' b/', ' c', ' d'].join('\n'); // d dedents to an in-between column
|
|
98
|
+
const roots = parseTree(art).roots;
|
|
99
|
+
// d clamps under a/ (the nearest shallower node).
|
|
100
|
+
expect(flat(roots)).toEqual(['0:a/', '1:b/', '2:c', '1:d']);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('skips rails-only spacer lines', () => {
|
|
104
|
+
const art = ['a/', '├── b', '│', '└── c'].join('\n');
|
|
105
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:a/', '1:b', '1:c']);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('never throws on garbage / empty', () => {
|
|
109
|
+
expect(parseTree('').roots).toEqual([]);
|
|
110
|
+
expect(() => parseTree('|||\n---')).not.toThrow();
|
|
111
|
+
expect(parseTree('single line').roots.length).toBe(1);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('handles CRLF input', () => {
|
|
115
|
+
const art = 'a/\r\n├── b\r\n└── c';
|
|
116
|
+
expect(flat(parseTree(art).roots)).toEqual(['0:a/', '1:b', '1:c']);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseMarkdown, stringifyMarkdown } from '../markdown/index';
|
|
3
|
+
import { markdownToDoc } from '../doc/markdownToDoc';
|
|
4
|
+
import { docToMarkdown } from '../doc/docToMarkdown';
|
|
5
|
+
import { materializeLayers } from './materializeTestUtils';
|
|
6
|
+
import { profileBlockContents, recommendTemplatesForBlock } from '../recommend/templates';
|
|
7
|
+
import type { Block, Layer } from '../schemas/Doc';
|
|
8
|
+
import type { TreeTemplateItem } from '../schemas/BlockTemplates';
|
|
9
|
+
|
|
10
|
+
const TREE_ART = ['src/', '├── index.ts', '├── components/', '│ └── App.tsx', '└── utils/'].join(
|
|
11
|
+
'\n',
|
|
12
|
+
);
|
|
13
|
+
const fenced = (art: string, lang = ''): string => '```' + lang + '\n' + art + '\n```';
|
|
14
|
+
const AUTO_DOC = ['# Project', '', '## Layout', '', fenced(TREE_ART), ''].join('\n');
|
|
15
|
+
|
|
16
|
+
function convert(md: string, options?: Parameters<typeof markdownToDoc>[1]) {
|
|
17
|
+
return markdownToDoc(parseMarkdown(md), { generateCoverBlock: false, ...options });
|
|
18
|
+
}
|
|
19
|
+
function findBlock(doc: { blocks: Block[] }, title: string): Block | undefined {
|
|
20
|
+
const walk = (blocks: Block[]): Block | undefined => {
|
|
21
|
+
for (const b of blocks) {
|
|
22
|
+
if (b.title === title) return b;
|
|
23
|
+
const inner = b.children ? walk(b.children) : undefined;
|
|
24
|
+
if (inner) return inner;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
28
|
+
return walk(doc.blocks);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('auto-template conversion of tree fences', () => {
|
|
32
|
+
it('converts a heading with a lone tree fence into an ephemeral tree block', () => {
|
|
33
|
+
const block = findBlock(convert(AUTO_DOC), 'Layout');
|
|
34
|
+
expect(block?.template).toBe('tree');
|
|
35
|
+
expect(block?.autoTemplate).toBe(true);
|
|
36
|
+
const items = block?.templateData?.items as TreeTemplateItem[];
|
|
37
|
+
expect(items?.map((i) => i.label)).toEqual(['src/']);
|
|
38
|
+
expect(items?.[0].children.map((c) => c.label)).toEqual(['index.ts', 'components/', 'utils/']);
|
|
39
|
+
expect(block?.templateData?.title).toBe('Layout');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('round-trips losslessly: fence byte-identical, no annotation injected', () => {
|
|
43
|
+
const output = stringifyMarkdown(docToMarkdown(convert(AUTO_DOC)));
|
|
44
|
+
expect(output).toContain(TREE_ART);
|
|
45
|
+
expect(output).not.toContain('{[tree');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('respects the autoTemplates kill switch', () => {
|
|
49
|
+
expect(findBlock(convert(AUTO_DOC, { autoTemplates: false }), 'Layout')?.template).not.toBe(
|
|
50
|
+
'tree',
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('respects the frontmatter kill switch', () => {
|
|
55
|
+
const md = `---\nsquisq-auto-templates: false\n---\n\n${AUTO_DOC}`;
|
|
56
|
+
expect(findBlock(convert(md), 'Layout')?.template).not.toBe('tree');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('does not convert a real-language fence', () => {
|
|
60
|
+
const md = ['## Layout', '', fenced(TREE_ART, 'bash'), ''].join('\n');
|
|
61
|
+
expect(findBlock(convert(md), 'Layout')?.template).not.toBe('tree');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('does not convert when a table competes with the fence', () => {
|
|
65
|
+
const md = [
|
|
66
|
+
'## Layout',
|
|
67
|
+
'',
|
|
68
|
+
'| a | b |',
|
|
69
|
+
'|---|---|',
|
|
70
|
+
'| 1 | 2 |',
|
|
71
|
+
'',
|
|
72
|
+
fenced(TREE_ART),
|
|
73
|
+
'',
|
|
74
|
+
].join('\n');
|
|
75
|
+
expect(findBlock(convert(md), 'Layout')?.template).not.toBe('tree');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('does not steal a box-diagram fence (mutual exclusion)', () => {
|
|
79
|
+
const diagram = [
|
|
80
|
+
'┌────────┐',
|
|
81
|
+
'│ Alpha │',
|
|
82
|
+
'└───┬────┘',
|
|
83
|
+
' ▼',
|
|
84
|
+
'┌────────┐',
|
|
85
|
+
'│ Beta │',
|
|
86
|
+
'└────────┘',
|
|
87
|
+
].join('\n');
|
|
88
|
+
const block = findBlock(convert(['## Arch', '', fenced(diagram), ''].join('\n')), 'Arch');
|
|
89
|
+
expect(block?.template).toBe('diagram');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('explicit `tree`-tagged fence (survives flatten → round-trip)', () => {
|
|
94
|
+
// A flattened tree loses its connector lines, so an untagged fence would no
|
|
95
|
+
// longer auto-detect. The `tree` fence LANGUAGE is the durable "block tag"
|
|
96
|
+
// (it round-trips through markdown ↔ Tiptap as `class="language-tree"`),
|
|
97
|
+
// and explicit-lang detection accepts the flat art.
|
|
98
|
+
const FLAT_ART = ['README.md', 'index.ts', 'package.json'].join('\n');
|
|
99
|
+
const FLAT_DOC = ['# Project', '', '## Files', '', fenced(FLAT_ART, 'tree'), ''].join('\n');
|
|
100
|
+
|
|
101
|
+
it('a bare flat fence does NOT become a tree', () => {
|
|
102
|
+
const md = ['## Files', '', fenced(FLAT_ART), ''].join('\n');
|
|
103
|
+
expect(findBlock(convert(md), 'Files')?.template).not.toBe('tree');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('a `tree`-tagged flat fence DOES become a tree', () => {
|
|
107
|
+
const block = findBlock(convert(FLAT_DOC), 'Files');
|
|
108
|
+
expect(block?.template).toBe('tree');
|
|
109
|
+
expect(block?.autoTemplate).toBe(true);
|
|
110
|
+
const items = block?.templateData?.items as TreeTemplateItem[];
|
|
111
|
+
expect(items?.map((i) => i.label)).toEqual(['README.md', 'index.ts', 'package.json']);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('round-trips losslessly: fence + `tree` lang preserved, no annotation injected', () => {
|
|
115
|
+
const output = stringifyMarkdown(docToMarkdown(convert(FLAT_DOC)));
|
|
116
|
+
expect(output).toContain('```tree');
|
|
117
|
+
expect(output).toContain(FLAT_ART);
|
|
118
|
+
expect(output).not.toContain('{[tree');
|
|
119
|
+
// Re-importing the output keeps it a tree — the identity is sticky.
|
|
120
|
+
expect(findBlock(convert(output), 'Files')?.template).toBe('tree');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('profiles a `tree`-tagged flat fence as hasTree', () => {
|
|
124
|
+
const md = parseMarkdown(fenced(FLAT_ART, 'tree'));
|
|
125
|
+
const profile = profileBlockContents(md.children as Parameters<typeof profileBlockContents>[0]);
|
|
126
|
+
expect(profile.hasTree).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('explicit {[tree]} annotation', () => {
|
|
131
|
+
it('derives items even with autoTemplates off', () => {
|
|
132
|
+
const md = ['## Files {[tree]}', '', fenced(TREE_ART), ''].join('\n');
|
|
133
|
+
const block = findBlock(convert(md, { autoTemplates: false }), 'Files');
|
|
134
|
+
expect(block?.template).toBe('tree');
|
|
135
|
+
expect((block?.templateData?.items as TreeTemplateItem[])?.length).toBe(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('converts a nested markdown list under an explicit annotation', () => {
|
|
139
|
+
const md = ['## Files {[tree]}', '', '- src/', ' - index.ts', ' - utils/', ''].join('\n');
|
|
140
|
+
const block = findBlock(convert(md, { autoTemplates: false }), 'Files');
|
|
141
|
+
const items = block?.templateData?.items as TreeTemplateItem[];
|
|
142
|
+
expect(items?.[0].label).toBe('src/');
|
|
143
|
+
expect(items?.[0].children.map((c) => c.label)).toEqual(['index.ts', 'utils/']);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('records a diagnostic when the body does not parse as a tree', () => {
|
|
147
|
+
const md = ['## Files {[tree]}', '', 'just prose, no hierarchy at all', ''].join('\n');
|
|
148
|
+
const doc = convert(md);
|
|
149
|
+
expect(doc.diagnostics?.some((d) => d.code === 'tree-parse')).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('rendering a derived tree through materializeBlockLayers', () => {
|
|
154
|
+
it('emits a single tree layer with the item hierarchy', () => {
|
|
155
|
+
const block = findBlock(convert(AUTO_DOC), 'Layout') as Block;
|
|
156
|
+
const layers = materializeLayers(block, {});
|
|
157
|
+
const treeLayer = layers.find((l: Layer) => l.type === 'tree');
|
|
158
|
+
expect(treeLayer).toBeDefined();
|
|
159
|
+
if (treeLayer?.type === 'tree') {
|
|
160
|
+
expect(treeLayer.content.items[0].label).toBe('src/');
|
|
161
|
+
expect(treeLayer.content.items[0].isDir).toBe(true);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('duration/caption hygiene', () => {
|
|
167
|
+
it('excludes the consumed tree fence from captions', () => {
|
|
168
|
+
const doc = convert(AUTO_DOC);
|
|
169
|
+
const captionText = (doc.captions?.phrases ?? []).map((p) => p.text).join(' ');
|
|
170
|
+
expect(captionText).not.toContain('├──');
|
|
171
|
+
expect(captionText).not.toContain('index.ts');
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('template picker recommendation', () => {
|
|
176
|
+
it('surfaces tree for a tree-fence profile', () => {
|
|
177
|
+
const md = parseMarkdown(fenced(TREE_ART));
|
|
178
|
+
const profile = profileBlockContents(md.children as Parameters<typeof profileBlockContents>[0]);
|
|
179
|
+
expect(profile.hasTree).toBe(true);
|
|
180
|
+
const { recommended } = recommendTemplatesForBlock(profile, ['tree', 'list', 'title']);
|
|
181
|
+
expect(recommended).toContain('tree');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
parseTree,
|
|
4
|
+
renderTree,
|
|
5
|
+
treeFromTemplateData,
|
|
6
|
+
treeToTemplateData,
|
|
7
|
+
type Tree,
|
|
8
|
+
} from '../doc/treeview/index.js';
|
|
9
|
+
import { TREE_FIXTURES } from './fixtures/treeviewFixtures.js';
|
|
10
|
+
|
|
11
|
+
function semantic(t: Tree): string[] {
|
|
12
|
+
const out: string[] = [];
|
|
13
|
+
const walk = (nodes: Tree['roots'], depth: number): void => {
|
|
14
|
+
for (const n of nodes) {
|
|
15
|
+
out.push(`${depth}:${n.label}${n.comment ? ` #${n.comment}` : ''}`);
|
|
16
|
+
walk(n.children, depth + 1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
walk(t.roots, 0);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('renderTree — output', () => {
|
|
24
|
+
it('renders a clean Unicode tree with connectors', () => {
|
|
25
|
+
const t = parseTree(['a/', '├── b', '└── c/', ' └── d'].join('\n'));
|
|
26
|
+
expect(renderTree(t)).toBe(['a/', '├── b', '└── c/', ' └── d'].join('\n'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('renders ASCII vocabulary for ascii-style trees', () => {
|
|
30
|
+
const t = parseTree(['a/', '|-- b', '`-- c'].join('\n'));
|
|
31
|
+
const out = renderTree(t);
|
|
32
|
+
expect(out).toContain('|-- b');
|
|
33
|
+
expect(out).toContain('`-- c');
|
|
34
|
+
expect(out).not.toMatch(/[├└│─]/u);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('honours a style override', () => {
|
|
38
|
+
const t = parseTree(['a/', '├── b', '└── c'].join('\n'));
|
|
39
|
+
expect(renderTree(t, { style: 'ascii' })).toContain('|-- b');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('renders trailing comments', () => {
|
|
43
|
+
const t = parseTree(['p/', '└── a.ts # note'].join('\n'));
|
|
44
|
+
expect(renderTree(t)).toContain('a.ts # note');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('roots carry no connector; children do', () => {
|
|
48
|
+
const t = parseTree(['root/', '└── only'].join('\n'));
|
|
49
|
+
const lines = renderTree(t).split('\n');
|
|
50
|
+
expect(lines[0]).toBe('root/');
|
|
51
|
+
expect(lines[1]).toBe('└── only');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('renderTree ↔ parseTree fixpoint', () => {
|
|
56
|
+
for (const fx of TREE_FIXTURES) {
|
|
57
|
+
it(`fixpoint + byte-idempotence: ${fx.name}`, () => {
|
|
58
|
+
const d1 = parseTree(fx.art);
|
|
59
|
+
const t1 = renderTree(d1);
|
|
60
|
+
const d2 = parseTree(t1);
|
|
61
|
+
expect(semantic(d2)).toEqual(semantic(d1));
|
|
62
|
+
const t2 = renderTree(d2);
|
|
63
|
+
const t3 = renderTree(parseTree(t2));
|
|
64
|
+
expect(t2).toBe(t1);
|
|
65
|
+
expect(t3).toBe(t1);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
it('anti-churn: a structural edit only changes locally, then is stable', () => {
|
|
70
|
+
const t = parseTree(['a/', '├── b', '└── c'].join('\n'));
|
|
71
|
+
// Rename one node (structure-only edit) via the template-data round-trip.
|
|
72
|
+
const { items } = treeToTemplateData(t);
|
|
73
|
+
items[0].children[0].label = 'renamed';
|
|
74
|
+
const edited = treeFromTemplateData(items);
|
|
75
|
+
const r1 = renderTree(edited);
|
|
76
|
+
expect(r1).toContain('renamed');
|
|
77
|
+
expect(renderTree(parseTree(r1))).toBe(r1);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('templateData mapping round-trip', () => {
|
|
82
|
+
for (const fx of TREE_FIXTURES) {
|
|
83
|
+
it(`grid → items → grid preserves semantics: ${fx.name}`, () => {
|
|
84
|
+
const t = parseTree(fx.art);
|
|
85
|
+
const back = treeFromTemplateData(treeToTemplateData(t).items, { style: t.style });
|
|
86
|
+
expect(semantic(back)).toEqual(semantic(t));
|
|
87
|
+
// And renders identically.
|
|
88
|
+
expect(renderTree(back)).toBe(renderTree(t));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|