fix: fuzzy match (#2221)

This commit is contained in:
yetone
2025-06-13 16:46:55 +08:00
committed by GitHub
parent f766b42d85
commit fdf4716ec0
4 changed files with 99 additions and 105 deletions

View File

@@ -65,16 +65,16 @@ describe("Utils", function()
end)
end)
describe("remove_indentation", function()
describe("trime_space", function()
it("should remove indentation correctly", function()
assert.equals("test", Utils.remove_indentation(" test"))
assert.equals("test", Utils.remove_indentation("\ttest"))
assert.equals("test", Utils.remove_indentation("test"))
assert.equals("test", Utils.trim_space(" test"))
assert.equals("test", Utils.trim_space("\ttest"))
assert.equals("test", Utils.trim_space("test"))
end)
it("should handle empty or nil input", function()
assert.equals("", Utils.remove_indentation(""))
assert.equals(nil, Utils.remove_indentation(nil))
assert.equals("", Utils.trim_space(""))
assert.equals(nil, Utils.trim_space(nil))
end)
end)
@@ -208,4 +208,27 @@ describe("Utils", function()
assert.equals(5, result)
end)
end)
describe("fuzzy_match", function()
it("should match exact lines", function()
local lines = { "test", "test2", "test3", "test4" }
local start_line, end_line = Utils.fuzzy_match(lines, { "test2", "test3" })
assert.equals(2, start_line)
assert.equals(3, end_line)
end)
it("should match lines with suffix", function()
local lines = { "test", "test2", "test3", "test4" }
local start_line, end_line = Utils.fuzzy_match(lines, { "test2 \t", "test3" })
assert.equals(2, start_line)
assert.equals(3, end_line)
end)
it("should match lines with space", function()
local lines = { "test", "test2", "test3", "test4" }
local start_line, end_line = Utils.fuzzy_match(lines, { "test2 ", " test3" })
assert.equals(2, start_line)
assert.equals(3, end_line)
end)
end)
end)