36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
|
|
import { describe, it, expect } from 'vitest';
|
|||
|
|
import { parseAnchoredSections, buildArtifact } from './artifact-from-spec.mjs';
|
|||
|
|
|
|||
|
|
describe('artifact-from-spec', () => {
|
|||
|
|
const md = [
|
|||
|
|
'# Spec',
|
|||
|
|
'## Решение А {#dec-a}',
|
|||
|
|
'Текст А.',
|
|||
|
|
'## Решение Б {#dec-b}',
|
|||
|
|
'Текст Б.',
|
|||
|
|
].join('\n');
|
|||
|
|
|
|||
|
|
for (const [name, fn] of [['parses anchored sections', () => {
|
|||
|
|
const { sections } = parseAnchoredSections(md);
|
|||
|
|
expect(Object.keys(sections).sort()).toEqual(['dec-a', 'dec-b']);
|
|||
|
|
expect(sections['dec-a']).toContain('Текст А.');
|
|||
|
|
}]]) it(name, fn);
|
|||
|
|
|
|||
|
|
it('heading WITHOUT anchor is not a section key', () => {
|
|||
|
|
const { sections } = parseAnchoredSections('## Без якоря\nx');
|
|||
|
|
expect(Object.keys(sections)).toEqual([]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('empty-content section is dropped (fail-CLOSE)', () => {
|
|||
|
|
const { sections } = parseAnchoredSections('## Пусто {#e}\n\n## Полно {#f}\ny');
|
|||
|
|
expect(Object.keys(sections)).toEqual(['f']);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('buildArtifact returns {sections, source_sha} deterministically', () => {
|
|||
|
|
const a1 = buildArtifact(md); const a2 = buildArtifact(md);
|
|||
|
|
expect(a1.source_sha).toEqual(a2.source_sha);
|
|||
|
|
expect(typeof a1.source_sha).toBe('string');
|
|||
|
|
expect(a1.sections['dec-a']).toBeTruthy();
|
|||
|
|
});
|
|||
|
|
});
|