2a9c198859
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { buildFingerprint, resolve } from "../src/anchorer";
|
|
|
|
const ORIGINAL = "intro\nThe quick brown fox\noutro\n";
|
|
|
|
describe("re-anchor scenarios (SLICE-4 decision logic)", () => {
|
|
it("reload, document unchanged: resolves to the same range", () => {
|
|
const start = ORIGINAL.indexOf("quick brown");
|
|
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
|
|
expect(resolve(ORIGINAL, fp)).toEqual({ start, end: start + "quick brown".length });
|
|
});
|
|
|
|
it("external edit that moves the anchored text down: re-resolves to the new range", () => {
|
|
const start = ORIGINAL.indexOf("quick brown");
|
|
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
|
|
const edited = "a new first line\nanother line\n" + ORIGINAL;
|
|
const newStart = edited.indexOf("quick brown");
|
|
expect(newStart).not.toBe(start);
|
|
expect(resolve(edited, fp)).toEqual({ start: newStart, end: newStart + "quick brown".length });
|
|
});
|
|
|
|
it("external edit that deletes the anchored text: orphaned, never moved (INV-1)", () => {
|
|
const start = ORIGINAL.indexOf("quick brown");
|
|
const fp = buildFingerprint(ORIGINAL, { start, end: start + "quick brown".length });
|
|
const edited = "intro\nThe lazy dog\noutro\n";
|
|
expect(resolve(edited, fp)).toBe("orphaned");
|
|
});
|
|
});
|