feat(f9): splitBlocksWithRanges — block offsets aligned to the source
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { splitBlocks, diffBlocks, renderTrackChanges } from "../src/trackChangesModel";
|
||||
import { splitBlocks, splitBlocksWithRanges, diffBlocks, renderTrackChanges } from "../src/trackChangesModel";
|
||||
|
||||
describe("splitBlocks", () => {
|
||||
it("splits prose paragraphs on blank lines, dropping empties", () => {
|
||||
@@ -137,3 +137,22 @@ describe("error chip (PUC-6)", () => {
|
||||
expect(html).toContain("<p>Good one.</p>"); // the healthy block still rendered
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitBlocksWithRanges — block offsets align with the source string", () => {
|
||||
it("each block's [start,end) slices back to its raw from the source", () => {
|
||||
const text = "# Title\n\nA prose paragraph.\n\n```js\ncode()\n```\n";
|
||||
const blocks = splitBlocksWithRanges(text);
|
||||
expect(blocks.map((b) => b.type)).toEqual(["prose", "prose", "code"]);
|
||||
for (const b of blocks) {
|
||||
expect(text.slice(b.start, b.end)).toBe(b.raw);
|
||||
}
|
||||
expect(blocks[1].raw).toBe("A prose paragraph.");
|
||||
});
|
||||
|
||||
it("marks a mermaid fence and preserves its source offsets", () => {
|
||||
const text = "intro\n\n```mermaid\ngraph TD; A-->B;\n```\n";
|
||||
const blocks = splitBlocksWithRanges(text);
|
||||
expect(blocks[1].type).toBe("mermaid");
|
||||
expect(text.slice(blocks[1].start, blocks[1].end)).toBe(blocks[1].raw);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user