refactor(hashline-edit): remove HASHLINE_LEGACY_REF_PATTERN and legacy ref compat
Remove the old LINE:HEX (e.g. "42:ab") reference format support. All refs now use LINE#ID format exclusively (e.g. "42#VK"). Also fixes HASHLINE_OUTPUT_PATTERN to use | separator (was missed in PR #2079).
This commit is contained in:
parent
fb92babee7
commit
d28ebd10c1
@ -7,5 +7,4 @@ export const HASHLINE_DICT = Array.from({ length: 256 }, (_, i) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const HASHLINE_REF_PATTERN = /^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2})$/
|
export const HASHLINE_REF_PATTERN = /^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2})$/
|
||||||
export const HASHLINE_OUTPUT_PATTERN = /^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2}):(.*)$/
|
export const HASHLINE_OUTPUT_PATTERN = /^([0-9]+)#([ZPMQVRWSNKTXJBYH]{2})\|(.*)$/
|
||||||
export const HASHLINE_LEGACY_REF_PATTERN = /^([0-9]+):([0-9a-fA-F]{2,})$/
|
|
||||||
|
|||||||
@ -61,46 +61,3 @@ describe("validateLineRef", () => {
|
|||||||
.toThrow(/>>>\s+2#[ZPMQVRWSNKTXJBYH]{2}\|two/)
|
.toThrow(/>>>\s+2#[ZPMQVRWSNKTXJBYH]{2}\|two/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("legacy LINE:HEX backward compatibility", () => {
|
|
||||||
it("parses legacy LINE:HEX ref", () => {
|
|
||||||
//#given
|
|
||||||
const ref = "42:ab"
|
|
||||||
|
|
||||||
//#when
|
|
||||||
const result = parseLineRef(ref)
|
|
||||||
|
|
||||||
//#then
|
|
||||||
expect(result).toEqual({ line: 42, hash: "ab" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("parses legacy LINE:HEX ref with uppercase hex", () => {
|
|
||||||
//#given
|
|
||||||
const ref = "10:FF"
|
|
||||||
|
|
||||||
//#when
|
|
||||||
const result = parseLineRef(ref)
|
|
||||||
|
|
||||||
//#then
|
|
||||||
expect(result).toEqual({ line: 10, hash: "FF" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("legacy ref fails validation with hash mismatch, not parse error", () => {
|
|
||||||
//#given
|
|
||||||
const lines = ["function hello() {"]
|
|
||||||
|
|
||||||
//#when / #then
|
|
||||||
expect(() => validateLineRef(lines, "1:ab")).toThrow(/>>>\s+1#[ZPMQVRWSNKTXJBYH]{2}\|/)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("extracts legacy ref from content with markers", () => {
|
|
||||||
//#given
|
|
||||||
const ref = ">>> 42:ab|const x = 1"
|
|
||||||
|
|
||||||
//#when
|
|
||||||
const result = parseLineRef(ref)
|
|
||||||
|
|
||||||
//#then
|
|
||||||
expect(result).toEqual({ line: 42, hash: "ab" })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { computeLineHash } from "./hash-computation"
|
import { computeLineHash } from "./hash-computation"
|
||||||
import { HASHLINE_REF_PATTERN, HASHLINE_LEGACY_REF_PATTERN } from "./constants"
|
import { HASHLINE_REF_PATTERN } from "./constants"
|
||||||
|
|
||||||
export interface LineRef {
|
export interface LineRef {
|
||||||
line: number
|
line: number
|
||||||
@ -13,16 +13,13 @@ interface HashMismatch {
|
|||||||
|
|
||||||
const MISMATCH_CONTEXT = 2
|
const MISMATCH_CONTEXT = 2
|
||||||
|
|
||||||
const LINE_REF_EXTRACT_PATTERN = /([0-9]+#[ZPMQVRWSNKTXJBYH]{2}|[0-9]+:[0-9a-fA-F]{2,})/
|
const LINE_REF_EXTRACT_PATTERN = /([0-9]+#[ZPMQVRWSNKTXJBYH]{2})/
|
||||||
|
|
||||||
function normalizeLineRef(ref: string): string {
|
function normalizeLineRef(ref: string): string {
|
||||||
const trimmed = ref.trim()
|
const trimmed = ref.trim()
|
||||||
if (HASHLINE_REF_PATTERN.test(trimmed)) {
|
if (HASHLINE_REF_PATTERN.test(trimmed)) {
|
||||||
return trimmed
|
return trimmed
|
||||||
}
|
}
|
||||||
if (HASHLINE_LEGACY_REF_PATTERN.test(trimmed)) {
|
|
||||||
return trimmed
|
|
||||||
}
|
|
||||||
|
|
||||||
const extracted = trimmed.match(LINE_REF_EXTRACT_PATTERN)
|
const extracted = trimmed.match(LINE_REF_EXTRACT_PATTERN)
|
||||||
if (extracted) {
|
if (extracted) {
|
||||||
@ -41,13 +38,6 @@ export function parseLineRef(ref: string): LineRef {
|
|||||||
hash: match[2],
|
hash: match[2],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const legacyMatch = normalized.match(HASHLINE_LEGACY_REF_PATTERN)
|
|
||||||
if (legacyMatch) {
|
|
||||||
return {
|
|
||||||
line: Number.parseInt(legacyMatch[1], 10),
|
|
||||||
hash: legacyMatch[2],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid line reference format: "${ref}". Expected format: "LINE#ID" (e.g., "42#VK")`
|
`Invalid line reference format: "${ref}". Expected format: "LINE#ID" (e.g., "42#VK")`
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user