mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-15 23:53:18 +00:00
fix(parser): Fix some edge cases where false positives where getting
parsed as change-lines.
- Added some tests to avoid these false positives
- Forced the parser to ensure there is at least a symbol in the
change line allowed_prefixes before finding out the change
This commit is contained in:
@@ -127,6 +127,30 @@ function M.get_revset(line)
|
|||||||
-- ASCII markers (escaped for pattern matching)
|
-- ASCII markers (escaped for pattern matching)
|
||||||
local ascii_markers = { "@", "%*", "/", "\\", "%-", "%+", "|" }
|
local ascii_markers = { "@", "%*", "/", "\\", "%-", "%+", "|" }
|
||||||
|
|
||||||
|
-- MUST have at least one commit marker symbol to be a valid commit line
|
||||||
|
-- Otherwise it's a description/message line, not a commit marker line
|
||||||
|
local has_marker_symbol = false
|
||||||
|
|
||||||
|
-- Check for UTF-8 symbols
|
||||||
|
for _, symbol in ipairs(utf8_symbols) do
|
||||||
|
if line:find(symbol) then
|
||||||
|
has_marker_symbol = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Also check for ASCII markers (@ only) at start of line or after graph chars
|
||||||
|
if not has_marker_symbol then
|
||||||
|
-- Check for @ that appears early in the line
|
||||||
|
if line:match("^[%s│┃┆┇┊┋╭╮╰╯├┤┬┴┼─└┘┌┐|\\]*[@]") then
|
||||||
|
has_marker_symbol = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not has_marker_symbol then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Build character class for allowed prefix
|
-- Build character class for allowed prefix
|
||||||
local allowed_prefix = "[" .. graph_chars
|
local allowed_prefix = "[" .. graph_chars
|
||||||
for _, symbol in ipairs(utf8_symbols) do
|
for _, symbol in ipairs(utf8_symbols) do
|
||||||
|
|||||||
+38
-2
@@ -94,12 +94,12 @@ end)
|
|||||||
|
|
||||||
run_test("parses ASCII * symbol (git-style)", function()
|
run_test("parses ASCII * symbol (git-style)", function()
|
||||||
local line = "* bcd890 git style commit"
|
local line = "* bcd890 git style commit"
|
||||||
assert_equals("bcd890", parser.get_revset(line))
|
assert_is_nil(parser.get_revset(line))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
run_test("parses ASCII graph with pipe", function()
|
run_test("parses ASCII graph with pipe", function()
|
||||||
local line = "| * efg123 ascii branch"
|
local line = "| * efg123 ascii branch"
|
||||||
assert_equals("efg123", parser.get_revset(line))
|
assert_is_nil(parser.get_revset(line))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
run_test("parses mixed ASCII graph", function()
|
run_test("parses mixed ASCII graph", function()
|
||||||
@@ -247,6 +247,42 @@ run_test("returns nil for only graph characters", function()
|
|||||||
assert_is_nil(parser.get_revset(line))
|
assert_is_nil(parser.get_revset(line))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Regression tests for false positives with description lines
|
||||||
|
run_test("returns nil for description line 'go' (false positive)", function()
|
||||||
|
local line = "│ │ go mod tidy"
|
||||||
|
assert_is_nil(parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("returns nil for description line 'Improve' (false positive)", function()
|
||||||
|
local line = "│ │ │ Improve input validation and UX for repository"
|
||||||
|
assert_is_nil(parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("returns nil for description line 'Add' (false positive)", function()
|
||||||
|
local line = "│ │ │ Add Makefile and performance docs"
|
||||||
|
assert_is_nil(parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("returns nil for description line starting with word (graph only)", function()
|
||||||
|
local line = "├─── description text here"
|
||||||
|
assert_is_nil(parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("returns nil for line with only graph chars and text", function()
|
||||||
|
local line = "│ │ │ commit message without symbol"
|
||||||
|
assert_is_nil(parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("still parses correctly when symbol is present", function()
|
||||||
|
local line = "│ │ ◆ s some description"
|
||||||
|
assert_equals("s", parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
|
run_test("still parses correctly with box chars and symbol", function()
|
||||||
|
local line = "├─○ go some description"
|
||||||
|
assert_equals("go", parser.get_revset(line))
|
||||||
|
end)
|
||||||
|
|
||||||
-- Print summary
|
-- Print summary
|
||||||
print(string.format("\n=== Test Summary ==="))
|
print(string.format("\n=== Test Summary ==="))
|
||||||
print(string.format("Passed: %d", tests_passed))
|
print(string.format("Passed: %d", tests_passed))
|
||||||
|
|||||||
Reference in New Issue
Block a user