@@ -1,45 +1,13 @@
11 import { describe, expect, test } from "bun:test";
2-import { findLineByHash, formatHashLine, hashLine } from "./hashline.ts";
3-
4-describe("hashLine", () => {
5- test("returns a stable two-character lowercase hex digest", () => {
6- const hash = hashLine("hello");
7- expect(hash).toHaveLength(2);
8- expect(hash).toMatch(/^[0-9a-f]{2}$/);
9- expect(hashLine("hello")).toBe(hash);
10- });
11-});
2+import { formatHashLine } from "./hashline.ts";
123
134 describe("formatHashLine", () => {
14- test("formats the line number, hash, and content", () => {
15- expect(formatHashLine(12, "alpha")).toBe(`12:${hashLine("alpha")}| alpha`);
16- });
17-});
18-
19-describe("findLineByHash", () => {
20- test("returns the hinted line when it matches exactly", () => {
21- const lines = ["alpha", "beta", "gamma", "beta"];
22- expect(findLineByHash(lines, hashLine("beta"), 2)).toBe(2);
23- });
24-
25- test("finds a unique nearby match within the scan range", () => {
26- const lines = ["alpha", "beta", "gamma", "delta"];
27- expect(findLineByHash(lines, hashLine("gamma"), 2)).toBe(3);
28- });
29-
30- test("treats anchor hashes case-insensitively", () => {
31- const lines = ["alpha", "beta"];
32- expect(findLineByHash(lines, hashLine("beta").toUpperCase(), 1)).toBe(2);
33- });
34-
35- test("returns null when nearby matches are ambiguous", () => {
36- const lines = ["alpha", "beta", "gamma", "beta"];
37- expect(findLineByHash(lines, hashLine("beta"), 3)).toBeNull();
5+ test("formats the line number, short hash, and content", () => {
6+ const formatted = formatHashLine(12, "alpha");
7+ expect(formatted).toMatch(/^12:[0-9a-f]{2}\| alpha$/);
388 });
399
40- test("returns null when the only match is outside the scan range", () => {
41- const lines = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`);
42- lines[22] = "needle";
43- expect(findLineByHash(lines, hashLine("needle"), 1)).toBeNull();
10+ test("keeps the same hash for the same content", () => {
11+ expect(formatHashLine(1, "hello")).toBe(formatHashLine(1, "hello"));
4412 });
4513 });