fix: address newline issues in output window
This commit is contained in:
@@ -186,6 +186,58 @@ describe("watchexec runner", function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("normalize_output", function()
|
||||
it("removes ANSI sequences", function()
|
||||
local result = runner._strip_ansi("\x1b[31mred\x1b[0m")
|
||||
|
||||
assert.equals("red", result)
|
||||
end)
|
||||
|
||||
it("converts \\r\\n to \\n", function()
|
||||
local result, _ = runner._normalize_output("line1\r\nline2\r\nline3")
|
||||
|
||||
assert.equals("line1\nline2\nline3", result)
|
||||
end)
|
||||
|
||||
it("resolves inline overwrites (\\r splits)", function()
|
||||
local result, _ = runner._normalize_output("a\rb\rc")
|
||||
|
||||
assert.equals("c", result)
|
||||
end)
|
||||
|
||||
it("resolves mixed inline and line (\\r in last line)", function()
|
||||
local result, _ = runner._normalize_output("a\rb\nc\rd")
|
||||
|
||||
assert.equals("b\nd", result)
|
||||
end)
|
||||
|
||||
it("detects leading overwrite", function()
|
||||
local _, overwrite = runner._normalize_output("\rxyz")
|
||||
|
||||
assert.is_true(overwrite)
|
||||
end)
|
||||
|
||||
it("does not detect overwrite on normal text", function()
|
||||
local _, overwrite = runner._normalize_output("xyz")
|
||||
|
||||
assert.is_false(overwrite)
|
||||
end)
|
||||
|
||||
|
||||
it("does not detect overwrite on CRLF that starts with \\r", function()
|
||||
local _, overwrite = runner._normalize_output("\r\nxyz")
|
||||
|
||||
assert.is_false(overwrite)
|
||||
end)
|
||||
|
||||
it("handles empty text", function()
|
||||
local result, overwrite = runner._normalize_output("")
|
||||
|
||||
assert.equals("", result)
|
||||
assert.is_false(overwrite)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("on_exit guard", function()
|
||||
it("ignores stale on_exit from replaced job", function()
|
||||
local call_count = 0
|
||||
|
||||
@@ -254,6 +254,48 @@ describe("watchexec window", function()
|
||||
|
||||
assert.equals(line_count, cursor[1])
|
||||
end)
|
||||
|
||||
it("overwrite replaces the last line", function()
|
||||
window.open()
|
||||
local buf = window.get_buf()
|
||||
|
||||
window.append("first")
|
||||
window.append("second")
|
||||
window.append("replacement", true)
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
|
||||
assert.equals(2, #lines)
|
||||
assert.equals("first", lines[1])
|
||||
assert.equals("replacement", lines[2])
|
||||
end)
|
||||
|
||||
it("overwrite with multiple lines replaces last line and appends", function()
|
||||
window.open()
|
||||
local buf = window.get_buf()
|
||||
|
||||
window.append("first")
|
||||
window.append("second")
|
||||
window.append("replacement1\nreplacement2", true)
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
|
||||
assert.equals(3, #lines)
|
||||
assert.equals("first", lines[1])
|
||||
assert.equals("replacement1", lines[2])
|
||||
assert.equals("replacement2", lines[3])
|
||||
end)
|
||||
|
||||
it("overwrite on empty buffer appends normally", function()
|
||||
window.open()
|
||||
local buf = window.get_buf()
|
||||
|
||||
window.append("first", true)
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
|
||||
assert.equals("first", lines[1])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("keymaps", function()
|
||||
@@ -262,12 +304,14 @@ describe("watchexec window", function()
|
||||
local buf = window.get_buf()
|
||||
local maps = vim.api.nvim_buf_get_keymap(buf, "n")
|
||||
local found = false
|
||||
|
||||
for _, m in ipairs(maps) do
|
||||
if m.lhs == "<Esc>" then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_true(found)
|
||||
end)
|
||||
|
||||
@@ -276,12 +320,14 @@ describe("watchexec window", function()
|
||||
local buf = window.get_buf()
|
||||
local maps = vim.api.nvim_buf_get_keymap(buf, "n")
|
||||
local found = false
|
||||
|
||||
for _, m in ipairs(maps) do
|
||||
if m.lhs == "q" then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
assert.is_true(found)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user