Files
brain/tools/registry-render.test.mjs

35 lines
1.3 KiB
JavaScript

// tools/registry-render.test.mjs
import { describe, it, expect } from 'vitest';
import { replaceRegion } from './registry-render.mjs';
describe('registry-render', () => {
it('replaces auto-region between markers', () => {
const input = `Header\n<!-- auto:foo:begin -->\nold content\n<!-- auto:foo:end -->\nFooter`;
const out = replaceRegion(input, 'foo', 'NEW CONTENT');
expect(out).toContain('NEW CONTENT');
expect(out).not.toContain('old content');
expect(out).toContain('Header');
expect(out).toContain('Footer');
});
it('preserves end marker exactly', () => {
const input = `<!-- auto:foo:begin -->\nold\n<!-- auto:foo:end -->`;
const out = replaceRegion(input, 'foo', 'new');
expect(out).toMatch(/<!-- auto:foo:end -->$/);
});
it('throws if markers missing', () => {
expect(() => replaceRegion('no markers here', 'foo', 'x')).toThrow(/Markers.*not found/);
});
it('throws if only begin marker present', () => {
expect(() => replaceRegion('<!-- auto:foo:begin -->\nstuff', 'foo', 'x')).toThrow();
});
it('handles multi-line rendered content', () => {
const input = `<!-- auto:foo:begin -->\n<!-- auto:foo:end -->`;
const out = replaceRegion(input, 'foo', 'line1\nline2\nline3');
expect(out).toMatch(/line1\nline2\nline3/);
});
});