Skip to content

Commit 5770f43

Browse files
authored
test: improve coverage (#9)
1 parent 4b8100b commit 5770f43

6 files changed

Lines changed: 204 additions & 54 deletions

File tree

‎tests/scripts/init_with_zen.lua‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ vim.o.lines = 52
66

77
require("mini.test").setup()
88
require("trouble").setup({ open_no_results = true })
9+
require("fyler").setup({})
10+
require("neotest").setup({ adapters = {} })
911
require("zen").setup({
1012
top = {
1113
{ filetype = "fugitive" },
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
vim.cmd([[let &rtp.=','.getcwd()]])
2+
vim.opt.packpath:prepend("deps")
3+
4+
vim.o.columns = 140
5+
vim.o.lines = 52
6+
7+
require("mini.test").setup()
8+
require("trouble").setup({ open_no_results = true })
9+
require("fyler").setup({})
10+
require("neotest").setup({ adapters = {} })
11+
require("zen").setup({
12+
top = {
13+
{ filetype = "fugitive" },
14+
},
15+
bottom = {
16+
{ filetype = "trouble" },
17+
},
18+
left = {
19+
min_width = 46,
20+
{ filetype = "fyler" },
21+
},
22+
right = {
23+
min_width = 46,
24+
{ filetype = "neotest-summary" },
25+
},
26+
})

‎tests/test_autocmd.lua‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
local Helpers = dofile("tests/scripts/helpers.lua")
2+
local child = MiniTest.new_child_neovim()
3+
4+
local T = MiniTest.new_set({
5+
hooks = {
6+
pre_case = function()
7+
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
8+
end,
9+
post_once = child.stop,
10+
},
11+
})
12+
13+
T["close zen side buffers on last main quit"] = function()
14+
Helpers.expect.layout(child, {
15+
type = "row",
16+
children = {
17+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
18+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
19+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
20+
},
21+
})
22+
23+
pcall(child.cmd, "q")
24+
25+
local STOPPED = 0
26+
local exit_code = vim.fn.jobwait({ child.job.id }, 1000)[1]
27+
MiniTest.expect.equality(exit_code, STOPPED)
28+
end
29+
30+
T["open zen side buffers on startup"] = function()
31+
Helpers.expect.layout(child, {
32+
type = "row",
33+
children = {
34+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
35+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
36+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
37+
},
38+
})
39+
end
40+
41+
T["do not open zen side buffers when there is not enough space"] = function()
42+
child.restart({ "-u", "tests/scripts/init_with_zen_small.lua" })
43+
44+
Helpers.expect.layout(child, {
45+
type = "leaf",
46+
filetype = "",
47+
buftype = "",
48+
width = 140,
49+
height = 50,
50+
})
51+
end
52+
53+
T["cursor does not enter zen side buffers"] = MiniTest.new_set({
54+
hooks = {
55+
pre_case = function()
56+
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
57+
child.cmd("edit test.lua")
58+
end,
59+
},
60+
})
61+
62+
T["cursor does not enter zen side buffers"]["from main"] = function()
63+
child.cmd("wincmd h")
64+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
65+
66+
child.cmd("wincmd l")
67+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
68+
end
69+
70+
T["cursor does not enter zen side buffers"]["from top integration"] = function()
71+
child.cmd("Git")
72+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
73+
74+
child.cmd("wincmd j")
75+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
76+
77+
child.cmd("wincmd k")
78+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
79+
80+
child.cmd("wincmd h")
81+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
82+
83+
child.cmd("wincmd l")
84+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "fugitive")
85+
86+
child.cmd("close")
87+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
88+
end
89+
90+
T["cursor does not enter zen side buffers"]["from bottom integration"] = function()
91+
child.cmd("Trouble diagnostics open")
92+
child.cmd("wincmd j")
93+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
94+
95+
child.cmd("wincmd k")
96+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
97+
98+
child.cmd("wincmd j")
99+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
100+
101+
child.cmd("wincmd h")
102+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
103+
104+
child.cmd("wincmd l")
105+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "trouble")
106+
107+
child.cmd("close")
108+
MiniTest.expect.equality(child.lua_get("vim.bo.filetype"), "lua")
109+
end
110+
111+
return T

‎tests/test_closing.lua‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎tests/test_integrations.lua‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
local Helpers = dofile("tests/scripts/helpers.lua")
2+
local child = MiniTest.new_child_neovim()
3+
4+
local T = MiniTest.new_set({
5+
hooks = {
6+
pre_case = function()
7+
child.restart({ "-u", "tests/scripts/init_with_zen.lua" })
8+
end,
9+
post_once = child.stop,
10+
},
11+
})
12+
13+
T["left integration"] = MiniTest.new_set({})
14+
15+
T["left integration"]["opening closes zen side buffer, closing reopens it"] = function()
16+
child.cmd("Fyler kind=split_left_most")
17+
18+
Helpers.expect.layout(child, {
19+
type = "row",
20+
children = {
21+
{ type = "leaf", filetype = "fyler", buftype = "acwrite", width = 46, height = 50 },
22+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
23+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
24+
},
25+
})
26+
27+
child.cmd("close")
28+
29+
Helpers.expect.layout(child, {
30+
type = "row",
31+
children = {
32+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
33+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
34+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
35+
},
36+
})
37+
end
38+
39+
T["right integration"] = MiniTest.new_set({})
40+
41+
T["right integration"]["opening closes zen side buffer, closing reopens it"] = function()
42+
child.cmd("Neotest summary open")
43+
44+
Helpers.expect.layout(child, {
45+
type = "row",
46+
children = {
47+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
48+
{ type = "leaf", filetype = "", buftype = "", width = 142, height = 50 },
49+
{ type = "leaf", filetype = "neotest-summary", buftype = "nofile", width = 50, height = 50 },
50+
},
51+
})
52+
53+
child.cmd("Neotest summary close")
54+
55+
Helpers.expect.layout(child, {
56+
type = "row",
57+
children = {
58+
{ type = "leaf", filetype = "zen-left", buftype = "nofile", width = 46, height = 50 },
59+
{ type = "leaf", filetype = "", buftype = "", width = 146, height = 50 },
60+
{ type = "leaf", filetype = "zen-right", buftype = "nofile", width = 46, height = 50 },
61+
},
62+
})
63+
end
64+
65+
return T

‎tests/test_opening.lua‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)