mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-05 12:17:27 +00:00
Co-authored-by: adamelmore <2363879+adamdottv@users.noreply.github.com> Co-authored-by: David Hill <iamdavidhill@gmail.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { buildSessionSearchHits, stepSessionSearchIndex } from "./session-review-search"
|
|
|
|
describe("session review search", () => {
|
|
test("builds hits with line, col, and side", () => {
|
|
const hits = buildSessionSearchHits({
|
|
query: "alpha",
|
|
files: [
|
|
{
|
|
file: "a.txt",
|
|
before: "alpha\nbeta alpha",
|
|
after: "ALPHA",
|
|
},
|
|
],
|
|
})
|
|
|
|
expect(hits).toEqual([
|
|
{ file: "a.txt", side: "deletions", line: 1, col: 1, len: 5 },
|
|
{ file: "a.txt", side: "deletions", line: 2, col: 6, len: 5 },
|
|
{ file: "a.txt", side: "additions", line: 1, col: 1, len: 5 },
|
|
])
|
|
})
|
|
|
|
test("uses non-overlapping matches", () => {
|
|
const hits = buildSessionSearchHits({
|
|
query: "aa",
|
|
files: [{ file: "a.txt", after: "aaaa" }],
|
|
})
|
|
|
|
expect(hits.map((hit) => hit.col)).toEqual([1, 3])
|
|
})
|
|
|
|
test("wraps next and previous navigation", () => {
|
|
expect(stepSessionSearchIndex(5, 0, -1)).toBe(4)
|
|
expect(stepSessionSearchIndex(5, 4, 1)).toBe(0)
|
|
expect(stepSessionSearchIndex(5, 2, 1)).toBe(3)
|
|
expect(stepSessionSearchIndex(0, 0, 1)).toBe(0)
|
|
})
|
|
})
|