Skip to content

Commit 0c7dc9b

Browse files
Test nolist option and make all option tests more robust
1 parent 22151b8 commit 0c7dc9b

2 files changed

Lines changed: 52 additions & 21 deletions

File tree

spec/ergoterm/instance/open_spec.lua

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,59 +169,83 @@ describe(".open", function()
169169
end)
170170

171171
it("sets the window as no number", function()
172-
local term = Terminal:new()
172+
test_helpers.with_option("number", true, function()
173+
local term = Terminal:new()
173174

174-
open.open(term)
175+
open.open(term)
175176

176-
assert.is_false(vim.wo[term:get_state("window")].number)
177+
assert.is_false(vim.wo[term:get_state("window")].number)
178+
end)
177179
end)
178180

179181
it("sets the window as no sign column", function()
180-
local term = Terminal:new()
182+
test_helpers.with_option("signcolumn", "yes", function()
183+
local term = Terminal:new()
181184

182-
open.open(term)
185+
open.open(term)
183186

184-
assert.equal("no", vim.wo[term:get_state("window")].signcolumn)
187+
assert.equal("no", vim.wo[term:get_state("window")].signcolumn)
188+
end)
185189
end)
186190

187191
it("sets the window as no relative number", function()
188-
local term = Terminal:new()
192+
test_helpers.with_option("relativenumber", true, function()
193+
local term = Terminal:new()
189194

190-
open.open(term)
195+
open.open(term)
191196

192-
assert.is_false(vim.wo[term:get_state("window")].relativenumber)
197+
assert.is_false(vim.wo[term:get_state("window")].relativenumber)
198+
end)
199+
end)
200+
201+
it("sets the window as no list", function()
202+
test_helpers.with_option("list", true, function()
203+
local term = Terminal:new()
204+
205+
open.open(term)
206+
207+
assert.is_false(vim.wo[term:get_state("window")].list)
208+
end)
193209
end)
194210

195211
it("sets the window with foldmethod manual", function()
196-
local term = Terminal:new()
212+
test_helpers.with_option("foldmethod", "expr", function()
213+
local term = Terminal:new()
197214

198-
open.open(term)
215+
open.open(term)
199216

200-
assert.equal("manual", vim.wo[term:get_state("window")].foldmethod)
217+
assert.equal("manual", vim.wo[term:get_state("window")].foldmethod)
218+
end)
201219
end)
202220

203221
it("sets the window with foldtext foldtext()", function()
204-
local term = Terminal:new()
222+
test_helpers.with_option("foldtext", "custom", function()
223+
local term = Terminal:new()
205224

206-
open.open(term)
225+
open.open(term)
207226

208-
assert.equal("foldtext()", vim.wo[term:get_state("window")].foldtext)
227+
assert.equal("foldtext()", vim.wo[term:get_state("window")].foldtext)
228+
end)
209229
end)
210230

211231
it("sets the window as no side scroll when layout is float", function()
212-
local term = Terminal:new()
232+
test_helpers.with_option("sidescrolloff", 5, function()
233+
local term = Terminal:new()
213234

214-
open.open(term, "float")
235+
open.open(term, "float")
215236

216-
assert.equal(0, vim.wo[term:get_state("window")].sidescrolloff)
237+
assert.equal(0, vim.wo[term:get_state("window")].sidescrolloff)
238+
end)
217239
end)
218240

219241
it("sets the window with float_windblend given in initialization if layout is float", function()
220-
local term = Terminal:new({ float_winblend = 20 })
242+
test_helpers.with_option("winblend", 0, function()
243+
local term = Terminal:new({ float_winblend = 20 })
221244

222-
open.open(term, "float")
245+
open.open(term, "float")
223246

224-
assert.equal(20, vim.wo[term:get_state("window")].winblend)
247+
assert.equal(20, vim.wo[term:get_state("window")].winblend)
248+
end)
225249
end)
226250
end)
227251

spec/support/test_helpers.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ M.mocking_notify = function(callback)
1919
return result
2020
end
2121

22+
M.with_option = function(option, mock_value, callback)
23+
local original_value = vim.o[option]
24+
vim.o[option] = mock_value
25+
callback()
26+
vim.o[option] = original_value
27+
end
28+
2229
return M

0 commit comments

Comments
 (0)