Files
vscode-cowriting-plugin/test/reanchor.test.ts
2026-06-10 06:53:50 -07:00

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");
});
});