aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEric Bartels <ebartels@gmail.com>2024-01-02 08:26:14 -0800
committerGitHub <noreply@github.com>2024-01-02 08:26:14 -0800
commitc4b2efb8aee4af0ef179a9b49ba401de3c4ef5d2 (patch)
tree27e8cea8fdf74db1466a0d5b6fb7c938b2b4dff2 /tests
parent053b8b8617dc2a64100c16f66750367170132de9 (diff)
Fix(black): formatting excluded files results in blank buffer (#254)
* Fix(black): formatting excluded files results in blank buffer (#249) * Fixed stylua formatting * Fixed more stylua formatting * Log buffer name and change from trace to warning * Test fix: set_formatter_output funtion was moved out of test_util * Avoid blank output triggering errors in fuzzer tests
Diffstat (limited to 'tests')
-rw-r--r--tests/fuzzer_spec.lua7
-rw-r--r--tests/runner_spec.lua13
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/fuzzer_spec.lua b/tests/fuzzer_spec.lua
index fc68680..c47f1e5 100644
--- a/tests/fuzzer_spec.lua
+++ b/tests/fuzzer_spec.lua
@@ -97,6 +97,7 @@ describe("fuzzer", function()
end
local function make_edits(lines)
+ local was_empty = table.concat(lines):match("^%s*$")
lines = vim.deepcopy(lines)
for _ = 1, math.random(0, 3) do
do_insert(lines)
@@ -107,6 +108,12 @@ describe("fuzzer", function()
for _ = 1, math.random(0, 3) do
do_delete(lines)
end
+ -- avoid blank output (whitepsace only) which is ignored when applying formatting
+ if not was_empty then
+ while table.concat(lines):match("^%s*$") do
+ do_replace(lines)
+ end
+ end
return lines
end
diff --git a/tests/runner_spec.lua b/tests/runner_spec.lua
index 5ab7893..0c45117 100644
--- a/tests/runner_spec.lua
+++ b/tests/runner_spec.lua
@@ -307,6 +307,19 @@ print("a")
assert.are.same({ "newcontent" }, vim.api.nvim_buf_get_lines(0, 0, -1, false))
end)
+ it("discards formatting changes if formatter output is empty /w non-empty input", function()
+ local bufnr = vim.fn.bufadd("testfile")
+ vim.fn.bufload(bufnr)
+ vim.api.nvim_set_current_buf(bufnr)
+ local original_lines = { "line one", "line two" }
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, original_lines)
+ vim.bo[bufnr].modified = false
+ set_formatter_output({ "" })
+ conform.format({ formatters = { "test" }, quiet = true })
+ local output_lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
+ assert.are.same(original_lines, output_lines)
+ end)
+
it("formats on save", function()
conform.setup({
formatters_by_ft = { ["*"] = { "test" } },