feat(config): add experimental.hashline_edit flag and provider state module

This commit is contained in:
YeonGyu-Kim
2026-02-16 15:59:12 +09:00
parent fcf26d9898
commit 149de9da66
12 changed files with 531 additions and 0 deletions
+105
View File
@@ -0,0 +1,105 @@
import { describe, it, expect } from "bun:test"
import { parseLineRef, validateLineRef } from "./validation"
describe("parseLineRef", () => {
it("parses valid line reference", () => {
//#given
const ref = "42:a3"
//#when
const result = parseLineRef(ref)
//#then
expect(result).toEqual({ line: 42, hash: "a3" })
})
it("parses line reference with different hash", () => {
//#given
const ref = "1:ff"
//#when
const result = parseLineRef(ref)
//#then
expect(result).toEqual({ line: 1, hash: "ff" })
})
it("throws on invalid format - no colon", () => {
//#given
const ref = "42a3"
//#when & #then
expect(() => parseLineRef(ref)).toThrow()
})
it("throws on invalid format - non-numeric line", () => {
//#given
const ref = "abc:a3"
//#when & #then
expect(() => parseLineRef(ref)).toThrow()
})
it("throws on invalid format - invalid hash", () => {
//#given
const ref = "42:xyz"
//#when & #then
expect(() => parseLineRef(ref)).toThrow()
})
it("throws on empty string", () => {
//#given
const ref = ""
//#when & #then
expect(() => parseLineRef(ref)).toThrow()
})
})
describe("validateLineRef", () => {
it("validates matching hash", () => {
//#given
const lines = ["function hello() {", " return 42", "}"]
const ref = "1:42"
//#when & #then
expect(() => validateLineRef(lines, ref)).not.toThrow()
})
it("throws on hash mismatch", () => {
//#given
const lines = ["function hello() {", " return 42", "}"]
const ref = "1:00" // Wrong hash
//#when & #then
expect(() => validateLineRef(lines, ref)).toThrow()
})
it("throws on line out of bounds", () => {
//#given
const lines = ["function hello() {", " return 42", "}"]
const ref = "99:a3"
//#when & #then
expect(() => validateLineRef(lines, ref)).toThrow()
})
it("throws on invalid line number", () => {
//#given
const lines = ["function hello() {"]
const ref = "0:a3" // Line numbers start at 1
//#when & #then
expect(() => validateLineRef(lines, ref)).toThrow()
})
it("error message includes current hash", () => {
//#given
const lines = ["function hello() {"]
const ref = "1:00"
//#when & #then
expect(() => validateLineRef(lines, ref)).toThrow(/current hash/)
})
})