import { describe, expect, it } from "vitest"; import { countChanges, findNextChangeIndex, findPreviousChangeIndex } from "./diffNavigation"; import { DiffLine } from "./diffApi"; const lines: DiffLine[] = [ { op: "equal", text: "a" }, { op: "delete", text: "b" }, { op: "equal", text: "c" }, { op: "equal", text: "d" }, { op: "insert", text: "e" }, { op: "equal", text: "f" }, ]; describe("diffNavigation", () => { it("findNextChangeIndex springt zur naechsten Aenderung nach dem aktuellen Index", () => { expect(findNextChangeIndex(lines, -1)).toBe(1); expect(findNextChangeIndex(lines, 1)).toBe(4); expect(findNextChangeIndex(lines, 4)).toBe(-1); }); it("findPreviousChangeIndex springt zur vorherigen Aenderung", () => { expect(findPreviousChangeIndex(lines, 6)).toBe(4); expect(findPreviousChangeIndex(lines, 4)).toBe(1); expect(findPreviousChangeIndex(lines, 1)).toBe(-1); }); it("countChanges zaehlt alle Nicht-equal-Zeilen", () => { expect(countChanges(lines)).toBe(2); }); it("liefert -1 bei einer Liste ohne Aenderungen", () => { const noChanges: DiffLine[] = [{ op: "equal", text: "x" }]; expect(findNextChangeIndex(noChanges, -1)).toBe(-1); expect(countChanges(noChanges)).toBe(0); }); });