From 18a0d2d4d5ba484b9791ca6f0e385788e2dc4fc3 Mon Sep 17 00:00:00 2001 From: user <17591696+sand4rt@users.noreply.github.com> Date: Thu, 24 Sep 2026 15:13:11 +0200 Subject: [PATCH 1/3] chore: migrate to busted api --- tests/scripts/minimal_init.lua | 6 +- tests/test_autocmd.lua | 113 +++--- tests/test_integrations.lua | 658 ++++++++++++++++----------------- tests/test_resizing.lua | 217 ++++++----- tests/test_splits.lua | 125 +++---- tests/test_tabs.lua | 24 +- 6 files changed, 557 insertions(+), 586 deletions(-) diff --git a/tests/scripts/minimal_init.lua b/tests/scripts/minimal_init.lua index b06eb79..44836bf 100644 --- a/tests/scripts/minimal_init.lua +++ b/tests/scripts/minimal_init.lua @@ -1,4 +1,8 @@ vim.cmd([[let &rtp.=','.getcwd()]]) vim.opt.packpath:prepend("deps") -require("mini.test").setup() +require("mini.test").setup({ + collect = { + emulate_busted = true, + }, +}) diff --git a/tests/test_autocmd.lua b/tests/test_autocmd.lua index 13d2724..c1f6b80 100644 --- a/tests/test_autocmd.lua +++ b/tests/test_autocmd.lua @@ -1,16 +1,13 @@ local Helpers = dofile("tests/scripts/helpers.lua") local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - end, - post_once = child.stop, - }, -}) - -T["close zen side buffers on last main quit"] = function() +before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) +end) + +teardown(child.stop) + +it("closes zen side buffers on last main quit", function() Helpers.expect.layout(child, { type = "row", children = { @@ -25,9 +22,9 @@ T["close zen side buffers on last main quit"] = function() local STOPPED = 0 local exit_code = vim.fn.jobwait({ child.job.id }, 1000)[1] MiniTest.expect.equality(exit_code, STOPPED) -end +end) -T["open zen side buffers on startup"] = function() +it("opens zen side buffers on startup", function() Helpers.expect.layout(child, { type = "row", children = { @@ -36,9 +33,9 @@ T["open zen side buffers on startup"] = function() { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, }) -end +end) -T["do not open zen side buffers when there is not enough space"] = function() +it("does not open zen side buffers when there is not enough space", function() child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" }) Helpers.expect.layout(child, { @@ -48,64 +45,60 @@ T["do not open zen side buffers when there is not enough space"] = function() width = 140, height = 50, }) -end - -T["cursor does not enter zen side buffers"] = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - child.cmd("edit test.lua") - end, - }, -}) +end) -T["cursor does not enter zen side buffers"]["from main"] = function() - child.cmd("wincmd h") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") +describe("cursor does not enter zen side buffers", function() + before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) + child.cmd("edit test.lua") + end) - child.cmd("wincmd l") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") -end + it("from main", function() + child.cmd("wincmd h") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") -T["cursor does not enter zen side buffers"]["from top integration"] = function() - child.cmd("Git") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") + child.cmd("wincmd l") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") + end) - child.cmd("wincmd j") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") + it("from top integration", function() + child.cmd("Git") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") - child.cmd("wincmd k") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") + child.cmd("wincmd j") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") - child.cmd("wincmd h") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") + child.cmd("wincmd k") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") - child.cmd("wincmd l") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") + child.cmd("wincmd h") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") - child.cmd("close") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") -end + child.cmd("wincmd l") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive") -T["cursor does not enter zen side buffers"]["from bottom integration"] = function() - child.cmd("Trouble diagnostics open") - child.cmd("wincmd j") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") + child.cmd("close") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") + end) - child.cmd("wincmd k") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") + it("from bottom integration", function() + child.cmd("Trouble diagnostics open") + child.cmd("wincmd j") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") - child.cmd("wincmd j") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") + child.cmd("wincmd k") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") - child.cmd("wincmd h") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") + child.cmd("wincmd j") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") - child.cmd("wincmd l") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") + child.cmd("wincmd h") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") - child.cmd("close") - MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") -end + child.cmd("wincmd l") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble") -return T + child.cmd("close") + MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua") + end) +end) diff --git a/tests/test_integrations.lua b/tests/test_integrations.lua index e342da3..2ee956b 100644 --- a/tests/test_integrations.lua +++ b/tests/test_integrations.lua @@ -1,155 +1,78 @@ local Helpers = dofile("tests/scripts/helpers.lua") local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - end, - post_once = child.stop, - }, -}) - -T["left integration"] = MiniTest.new_set({}) - -T["left integration"]["opening closes zen side buffer, closing reopens it"] = function() - child.cmd("Fyler kind=split_left_most") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) - - child.cmd("close") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) -end - - -T["left integration"]["opening an integration should close the existing integration on the same side"] = function() - child.cmd("Fyler kind=split_left_most") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) - - child.cmd("DBUI") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "dbui", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) -end - -T["left integration"]["opening an integration on a small window"] = function() - child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" }) - - child.cmd("Fyler kind=split_left_most") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 35, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 104, height = 50 }, - }, - }) -end - -T["top integration"] = MiniTest.new_set({}) - -T["top integration"]["opening"] = function() - child.cmd("Git") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, - }, +before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) +end) + +teardown(child.stop) + +describe("left integration", function() + it("opening closes zen side buffer, closing reopens it", function() + child.cmd("Fyler kind=split_left_most") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, - }, - }) -end - -T["top integration"]["opening an integration should close the existing integration on the same side"] = function() - child.cmd("Git") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, - }, + }) + + child.cmd("close") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, - }, - }) + }) + end) - child.cmd("Man ls") + it("opening an integration should close the existing integration on the same side", function() + child.cmd("Fyler kind=split_left_most") - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "man", buftype = "nofile", width = 240, height = 25 }, - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, - }, + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, - }, - }) -end + }) + child.cmd("DBUI") -for _, case in ipairs({ { name = "above", }, { name = "below", } }) do - T["top integration"]["stacks " .. case.name .. " when configured " .. case.name .. " with replace=false"] = function() - if case.name == "below" then - child.restart({ "-u", "tests/scripts/init_with_zen_top_order.lua" }) - end + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "dbui", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, + }, + }) + end) - child.lua([[ - local tmpdir = vim.fn.tempname() - vim.fn.mkdir(tmpdir, "p") - vim.fn.system({ "git", "init", tmpdir }) - vim.fn.system({ "git", "-C", tmpdir, "config", "user.name", "Test" }) - vim.fn.system({ "git", "-C", tmpdir, "config", "user.email", "test@test.com" }) - vim.fn.system({ "git", "-C", tmpdir, "commit", "--allow-empty", "-m", "initial" }) - vim.fn.writefile({ "hello" }, tmpdir .. "/file") - vim.cmd("edit " .. tmpdir .. "/file") - ]]) + it("opening an integration on a small window", function() + child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" }) + + child.cmd("Fyler kind=split_left_most") + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "fyler_finder", buftype = "acwrite", width = 35, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 104, height = 50 }, + }, + }) + end) +end) + +describe("top integration", function() + it("opening", function() child.cmd("Git") Helpers.expect.layout(child, { @@ -166,26 +89,15 @@ for _, case in ipairs({ { name = "above", }, { name = "below", } }) do }, }, }) + end) - child.cmd("Git commit --allow-empty") + it("opening an integration should close the existing integration on the same side", function() + child.cmd("Git") Helpers.expect.layout(child, { type = "col", children = { - { - type = "leaf", - filetype = case.name == "above" and "gitcommit" or "fugitive", - buftype = case.name == "above" and "" or "nowrite", - width = 240, - height = 12, - }, - { - type = "leaf", - filetype = case.name == "above" and "fugitive" or "gitcommit", - buftype = case.name == "above" and "nowrite" or "", - width = 240, - height = 12, - }, + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, { type = "row", children = { @@ -197,12 +109,12 @@ for _, case in ipairs({ { name = "above", }, { name = "below", } }) do }, }) - child.cmd("q") + child.cmd("Man ls") Helpers.expect.layout(child, { type = "col", children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { type = "leaf", filetype = "man", buftype = "nofile", width = 240, height = 25 }, { type = "row", children = { @@ -213,16 +125,98 @@ for _, case in ipairs({ { name = "above", }, { name = "below", } }) do }, }, }) + end) + + for _, case in ipairs({ { name = "above" }, { name = "below" } }) do + it("stacks " .. case.name .. " when configured " .. case.name .. " with replace=false", function() + if case.name == "below" then + child.restart({ "-u", "tests/scripts/init_with_zen_top_order.lua" }) + end + + child.lua([[ + local tmpdir = vim.fn.tempname() + vim.fn.mkdir(tmpdir, "p") + vim.fn.system({ "git", "init", tmpdir }) + vim.fn.system({ "git", "-C", tmpdir, "config", "user.name", "Test" }) + vim.fn.system({ "git", "-C", tmpdir, "config", "user.email", "test@test.com" }) + vim.fn.system({ "git", "-C", tmpdir, "commit", "--allow-empty", "-m", "initial" }) + vim.fn.writefile({ "hello" }, tmpdir .. "/file") + vim.cmd("edit " .. tmpdir .. "/file") + ]]) + + child.cmd("Git") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + }, + }, + }, + }) + + child.cmd("Git commit --allow-empty") + + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "leaf", + filetype = case.name == "above" and "gitcommit" or "fugitive", + buftype = case.name == "above" and "" or "nowrite", + width = 240, + height = 12, + }, + { + type = "leaf", + filetype = case.name == "above" and "fugitive" or "gitcommit", + buftype = case.name == "above" and "nowrite" or "", + width = 240, + height = 12, + }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + }, + }, + }, + }) + + child.cmd("q") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + }, + }, + }, + }) + end) end -end - -T["top integration"]["closing a git commit keeps the top and bottom stacks intact"] = function() - -- Regression: creating a commit in fugitive and then closing the gitcommit - -- window used to abort the reposition handlers with `E242: Can't split a - -- window while closing another`, because recreating a side buffer on - -- `WinClosed` re-enters `reposition_stack` mid-close. The close must leave - -- the fugitive (top) and trouble (bottom) stacks intact instead. - child.lua([[ + + it("closing a git commit keeps the top and bottom stacks intact", function() + -- Regression: creating a commit in fugitive and then closing the gitcommit + -- window used to abort the reposition handlers with `E242: Can't split a + -- window while closing another`, because recreating a side buffer on + -- `WinClosed` re-enters `reposition_stack` mid-close. The close must leave + -- the fugitive (top) and trouble (bottom) stacks intact instead. + child.lua([[ local tmpdir = vim.fn.tempname() vim.fn.mkdir(tmpdir, "p") vim.fn.system({ "git", "init", tmpdir }) @@ -233,190 +227,188 @@ T["top integration"]["closing a git commit keeps the top and bottom stacks intac vim.cmd("edit " .. tmpdir .. "/file") ]]) - child.cmd("Git") - child.cmd("Trouble diagnostics") - child.cmd("wincmd t") - child.cmd("Git commit --allow-empty") - child.cmd("q") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 13 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 13 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 }, + child.cmd("Git") + child.cmd("Trouble diagnostics") + child.cmd("wincmd t") + child.cmd("Git commit --allow-empty") + child.cmd("q") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 13 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 13 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 13 }, + }, }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, - }, - }) -end - -T["bottom integration"] = MiniTest.new_set({}) + }) + end) +end) -T["bottom integration"]["opening"] = function() - child.cmd("Trouble diagnostics") +describe("bottom integration", function() + it("opening", function() + child.cmd("Trouble diagnostics") - Helpers.expect.layout(child, { - type = "col", - children = { - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }, }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, - }, - }) -end - -T["bottom integration"]["opening an integration should close the existing integration on the same side"] = function() - child.cmd("Trouble diagnostics") - - Helpers.expect.layout(child, { - type = "col", - children = { - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }) + end) + + it("opening an integration should close the existing integration on the same side", function() + child.cmd("Trouble diagnostics") + + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }, }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, - }, - }) + }) - child.cmd("copen") + child.cmd("copen") - Helpers.expect.layout(child, { - type = "col", - children = { - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }, }, + { type = "leaf", filetype = "qf", buftype = "quickfix", width = 240, height = 10 }, }, - { type = "leaf", filetype = "qf", buftype = "quickfix", width = 240, height = 10 }, - }, - }) -end - -T["right integration"] = MiniTest.new_set({}) - -T["right integration"]["opening closes zen side buffer, closing reopens it"] = function() - child.cmd("Neotest summary open") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 142, height = 50 }, - { type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 }, - }, - }) - - child.cmd("Neotest summary close") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) -end - -T["right integration"]["opening an integration should close the existing integration on the same side"] = function() - child.cmd("Neotest summary open") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 142, height = 50 }, - { type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 }, - }, - }) - - child.lua([[vim.o.splitright = true; require("CopilotChat").open()]]) - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "copilot-chat", buftype = "nofile", width = 46, height = 50 }, - }, - }) -end - -T["right integration"]["opening an integration with table filetype"] = function() - child.lua([[require("dapui").open()]]) - - Helpers.expect.layout(child, { - type = "row", - children = { - { - type = "col", - children = { - { type = "leaf", filetype = "dapui_watches", buftype = "prompt", width = 40, height = 12 }, - { type = "leaf", filetype = "dapui_stacks", buftype = "nofile", width = 40, height = 12 }, - { type = "leaf", filetype = "dapui_breakpoints", buftype = "nofile", width = 40, height = 12 }, - { type = "leaf", filetype = "dapui_scopes", buftype = "nofile", width = 40, height = 11 }, - }, + }) + end) +end) + +describe("right integration", function() + it("opening closes zen side buffer, closing reopens it", function() + child.cmd("Neotest summary open") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 142, height = 50 }, + { type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 }, }, - { - type = "col", - children = { - { type = "leaf", filetype = "", buftype = "", width = 199, height = 39 }, - { - type = "row", - children = { - { type = "leaf", filetype = "dapui_console", buftype = "nofile", width = 99, height = 10 }, - { type = "leaf", filetype = "dap-repl", buftype = "prompt", width = 99, height = 10 }, + }) + + child.cmd("Neotest summary close") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, + }, + }) + end) + + it("opening an integration should close the existing integration on the same side", function() + child.cmd("Neotest summary open") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 142, height = 50 }, + { type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 }, + }, + }) + + child.lua([[vim.o.splitright = true; require("CopilotChat").open()]]) + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "copilot-chat", buftype = "nofile", width = 46, height = 50 }, + }, + }) + end) + + it("opening an integration with table filetype", function() + child.lua([[require("dapui").open()]]) + + Helpers.expect.layout(child, { + type = "row", + children = { + { + type = "col", + children = { + { type = "leaf", filetype = "dapui_watches", buftype = "prompt", width = 40, height = 12 }, + { type = "leaf", filetype = "dapui_stacks", buftype = "nofile", width = 40, height = 12 }, + { type = "leaf", filetype = "dapui_breakpoints", buftype = "nofile", width = 40, height = 12 }, + { type = "leaf", filetype = "dapui_scopes", buftype = "nofile", width = 40, height = 11 }, + }, + }, + { + type = "col", + children = { + { type = "leaf", filetype = "", buftype = "", width = 199, height = 39 }, + { + type = "row", + children = { + { type = "leaf", filetype = "dapui_console", buftype = "nofile", width = 99, height = 10 }, + { type = "leaf", filetype = "dap-repl", buftype = "prompt", width = 99, height = 10 }, + }, }, }, }, }, - }, - }) -end + }) + end) +end) local min_width_child = MiniTest.new_child_neovim() -T["min_width"] = MiniTest.new_set({ - hooks = { - pre_case = function() - min_width_child.restart({ "-u", "tests/scripts/init_with_zen_min_width.lua" }) - end, - post_once = min_width_child.stop, - }, -}) - -T["min_width"]["integration with a larger min_width should override the wildcard default"] = function() - min_width_child.lua([[vim.o.splitright = true; require("CopilotChat").open()]]) - - Helpers.expect.layout(min_width_child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "", buftype = "", width = 132, height = 50 }, - { type = "leaf", filetype = "copilot-chat", buftype = "nofile", width = 60, height = 50 }, - }, - }) -end - -return T +describe("min_width", function() + before_each(function() + min_width_child.restart({ "-u", "tests/scripts/init_with_zen_min_width.lua" }) + end) + + teardown(min_width_child.stop) + + it("integration with a larger min_width should override the wildcard default", function() + min_width_child.lua([[vim.o.splitright = true; require("CopilotChat").open()]]) + + Helpers.expect.layout(min_width_child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "", buftype = "", width = 132, height = 50 }, + { type = "leaf", filetype = "copilot-chat", buftype = "nofile", width = 60, height = 50 }, + }, + }) + end) +end) diff --git a/tests/test_resizing.lua b/tests/test_resizing.lua index eb7a30d..a0f6951 100644 --- a/tests/test_resizing.lua +++ b/tests/test_resizing.lua @@ -1,16 +1,13 @@ local Helpers = dofile("tests/scripts/helpers.lua") local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - end, - post_once = child.stop, - }, -}) - -T["resizing below minimum width closes the side buffers"] = function() +before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) +end) + +teardown(child.stop) + +it("resizing below minimum width closes the side buffers", function() child.cmd("set columns-=100") child.cmd("doautocmd VimResized") @@ -21,9 +18,9 @@ T["resizing below minimum width closes the side buffers"] = function() width = 140, height = 50, }) -end +end) -T["resizing above minimum width reopens the side buffers"] = function() +it("resizing above minimum width reopens the side buffers", function() child.cmd("set columns-=100") child.cmd("doautocmd VimResized") @@ -38,109 +35,107 @@ T["resizing above minimum width reopens the side buffers"] = function() { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, }) -end +end) -T["with top integration"] = MiniTest.new_set({}) +describe("with top integration", function() + it("resizing below minimum width closes the side buffers", function() + child.cmd("Git") -T["with top integration"]["resizing below minimum width closes the side buffers"] = function() - child.cmd("Git") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, - { type = "leaf", filetype = "", buftype = "", width = 140, height = 24 }, - }, - }) -end - -T["with top integration"]["resizing above minimum width reopens the side buffers"] = function() - child.cmd("Git") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") - - child.cmd("set columns+=100") - child.cmd("doautocmd VimResized") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, + { type = "leaf", filetype = "", buftype = "", width = 140, height = 24 }, + }, + }) + end) + + it("resizing above minimum width reopens the side buffers", function() + child.cmd("Git") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("set columns+=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 240, height = 25 }, + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 24 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 24 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 24 }, + }, }, }, - }, - }) -end - -T["with bottom integration"] = MiniTest.new_set({}) - -T["with bottom integration"]["resizing below minimum width closes the side buffers"] = function() - child.cmd("Trouble diagnostics") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "", buftype = "", width = 140, height = 39 }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, - }, - }) -end - -T["with bottom integration"]["resizing above minimum width reopens the side buffers"] = function() - child.cmd("Trouble diagnostics") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") - - child.cmd("set columns+=100") - child.cmd("doautocmd VimResized") - - Helpers.expect.layout(child, { - type = "col", - children = { - { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, - { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }) + end) +end) + +describe("with bottom integration", function() + it("resizing below minimum width closes the side buffers", function() + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "", buftype = "", width = 140, height = 39 }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, + }, + }) + end) + + it("resizing above minimum width reopens the side buffers", function() + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("set columns+=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 39 }, + { type = "leaf", filetype = "", buftype = "", width = 146, height = 39 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 39 }, + }, }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 240, height = 10 }, - }, - }) -end - -T["with top and bottom integration"] = MiniTest.new_set({}) - -T["with top and bottom integration"]["resizing below minimum width closes the side buffers"] = function() - child.cmd("Git") - child.cmd("Trouble diagnostics") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") - - Helpers.expect.layout(child, { - type = "col", - children = { - { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, - { type = "leaf", filetype = "", buftype = "", width = 140, height = 13 }, - { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, - }, - }) -end - -return T + }) + end) +end) + +describe("with top and bottom integration", function() + it("resizing below minimum width closes the side buffers", function() + child.cmd("Git") + child.cmd("Trouble diagnostics") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + Helpers.expect.layout(child, { + type = "col", + children = { + { type = "leaf", filetype = "fugitive", buftype = "nowrite", width = 140, height = 25 }, + { type = "leaf", filetype = "", buftype = "", width = 140, height = 13 }, + { type = "leaf", filetype = "trouble", buftype = "nofile", width = 140, height = 10 }, + }, + }) + end) +end) diff --git a/tests/test_splits.lua b/tests/test_splits.lua index 35e680f..d9ec267 100644 --- a/tests/test_splits.lua +++ b/tests/test_splits.lua @@ -1,69 +1,62 @@ local Helpers = dofile("tests/scripts/helpers.lua") local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - end, - post_once = child.stop, - }, -}) - -T["vsplit"] = MiniTest.new_set({}) - -T["vsplit"]["opening closes zen side buffers"] = function() - child.cmd("edit test.lua") - child.cmd("vsplit test2.lua") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "lua", buftype = "", width = 120, height = 50 }, - { type = "leaf", filetype = "lua", buftype = "", width = 119, height = 50 }, - }, - }) -end - -T["vsplit"]["closing reopens zen side buffers"] = function() - child.cmd("edit test.lua") - child.cmd("vsplit test2.lua") - child.cmd("q") - - Helpers.expect.layout(child, { - type = "row", - children = { - { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, - { type = "leaf", filetype = "lua", buftype = "", width = 146, height = 50 }, - { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, - }, - }) -end - - -T["vsplit"]["closing does not reopen zen side buffers when below minimum width"] = function() - child.cmd("edit test.lua") - child.cmd("vsplit test2.lua") - - child.cmd("set columns-=100") - child.cmd("doautocmd VimResized") - - child.cmd("q") - - Helpers.expect.layout(child, { - type = "leaf", - filetype = "lua", - buftype = "", - width = 140, - height = 50, - }) -end - - -T["hsplit"] = MiniTest.new_set({}) - -T["hsplit"]["opening does not close the side buffers"] = function() - -- TODO -end - -return T +before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) +end) + +teardown(child.stop) + +describe("vsplit", function() + it("opening closes zen side buffers", function() + child.cmd("edit test.lua") + child.cmd("vsplit test2.lua") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "lua", buftype = "", width = 120, height = 50 }, + { type = "leaf", filetype = "lua", buftype = "", width = 119, height = 50 }, + }, + }) + end) + + it("closing reopens zen side buffers", function() + child.cmd("edit test.lua") + child.cmd("vsplit test2.lua") + child.cmd("q") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "lua", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, + }, + }) + end) + + it("closing does not reopen zen side buffers when below minimum width", function() + child.cmd("edit test.lua") + child.cmd("vsplit test2.lua") + + child.cmd("set columns-=100") + child.cmd("doautocmd VimResized") + + child.cmd("q") + + Helpers.expect.layout(child, { + type = "leaf", + filetype = "lua", + buftype = "", + width = 140, + height = 50, + }) + end) +end) + +describe("hsplit", function() + it("opening does not close the side buffers", function() + -- TODO + end) +end) diff --git a/tests/test_tabs.lua b/tests/test_tabs.lua index 9de6286..d6edd35 100644 --- a/tests/test_tabs.lua +++ b/tests/test_tabs.lua @@ -1,16 +1,13 @@ local Helpers = dofile("tests/scripts/helpers.lua") local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set({ - hooks = { - pre_case = function() - child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) - end, - post_once = child.stop, - }, -}) +before_each(function() + child.restart({ "-u", "tests/scripts/init_with_zen.lua" }) +end) -T["open zen side buffers on a new tab"] = function() +teardown(child.stop) + +it("opens zen side buffers on a new tab", function() child.cmd("tabnew") Helpers.expect.layout(child, { @@ -21,10 +18,9 @@ T["open zen side buffers on a new tab"] = function() { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 49 }, }, }) -end - +end) -T["close tab on last main quit"] = function() +it("closes tab on last main quit", function() child.cmd("tabnew") child.cmd("q") @@ -36,6 +32,4 @@ T["close tab on last main quit"] = function() { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, }, }) -end - -return T +end) From 983a553b17fd8a6a9feec0cbd58fd38cd4fd6594 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:21:09 +0000 Subject: [PATCH 2/3] fix: ignore plugin-created side windows on WinNew Co-authored-by: sand4rt <17591696+sand4rt@users.noreply.github.com> --- lua/zen/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/zen/init.lua b/lua/zen/init.lua index 62054b0..cfb55e1 100644 --- a/lua/zen/init.lua +++ b/lua/zen/init.lua @@ -31,6 +31,7 @@ local opts = { local state = { [vim.api.nvim_get_current_tabpage()] = { left = nil, right = nil }, } +local is_creating_side_window = false local function get_main_width() local width = opts.main and opts.main.width @@ -44,6 +45,7 @@ local function get_main_width() end local function create_window(position) + is_creating_side_window = true if position == "left" then vim.cmd("topleft vnew") elseif position == "right" then @@ -62,6 +64,7 @@ local function create_window(position) vim.api.nvim_set_option_value("filetype", "zen-" .. position, { buf = buf_id }) vim.api.nvim_set_option_value("buftype", "nofile", { buf = buf_id }) vim.api.nvim_set_option_value("buflisted", false, { buf = buf_id }) + is_creating_side_window = false return vim.api.nvim_get_current_win() end @@ -565,6 +568,9 @@ local function setup(options) if is_popup_window(vim.api.nvim_get_current_win()) then return end + if args.event == "WinNew" and is_creating_side_window then + return + end local filetype = vim.bo[args.buf].filetype local is_integration = is_buff_integration(args.buf) if args.event == "BufWinEnter" or args.event == "WinNew" then From cdaf6691d825ab4d643136d6b64b51c9d57487d3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:21:52 +0000 Subject: [PATCH 3/3] test: cover WinNew side-window reopen regression Co-authored-by: sand4rt <17591696+sand4rt@users.noreply.github.com> --- tests/test_splits.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_splits.lua b/tests/test_splits.lua index 50df472..7ce06f8 100644 --- a/tests/test_splits.lua +++ b/tests/test_splits.lua @@ -49,6 +49,21 @@ describe("vsplit", function() }) end) + it("reopening zen side buffers after a split keeps them open", function() + child.cmd("edit test.lua") + child.cmd("vsplit") + child.cmd("q") + + Helpers.expect.layout(child, { + type = "row", + children = { + { type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 }, + { type = "leaf", filetype = "lua", buftype = "", width = 146, height = 50 }, + { type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 }, + }, + }) + end) + it("closing does not reopen zen side buffers when below minimum width", function() child.cmd("edit test.lua") child.cmd("vsplit test2.lua")