import { describe, expect, it } from "vitest"; import { findMatches, wrapIndex } from "#lib/components/lines/search.ts"; describe("findMatches", () => { it("finds every case-insensitive hit with one-based lines", () => { expect(findMatches(["Foo foo", "bar", "xfoo"], "foo")).toEqual([ { line: 1, start: 0, end: 3 }, { line: 1, start: 4, end: 7 }, { line: 3, start: 1, end: 4 } ]); }); it("treats the query as text, not a pattern", () => { expect(findMatches(["a.b", "axb"], "a.b")).toEqual([{ line: 1, start: 0, end: 3 }]); }); it("finds nothing for an empty query and stops at the limit", () => { expect(findMatches(["a"], "")).toEqual([]); expect(findMatches(["aaaa"], "a", 2)).toHaveLength(2); }); }); describe("wrapIndex", () => { it("wraps both ways", () => { expect(wrapIndex(-1, 3)).toBe(2); expect(wrapIndex(3, 3)).toBe(0); expect(wrapIndex(0, 0)).toBe(-1); }); });