Skip to content

Commit 99db1e1

Browse files
committed
test: add tests for the focused window minwidth and minheight options
Testing focusedwindow_minwidth and focusedwindow_minheight when value is bigger and smaller then the expected width and height value from golden ratio function. Testing integration of focusedwindow_minwidth and focusedwindow_minheight with minwidth and minheight values.
1 parent 003aaad commit 99db1e1

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

tests/test_autoresize.lua

+123
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,129 @@ T['autoresize']['vsplit minwidth'] = function()
211211
validate_win_dims(win_id_right, { 30, 23 })
212212
end
213213

214+
-- focused minwidth for vertical splits
215+
T['autoresize']['vsplit focusedwindow_minwidth'] = function()
216+
reload_module({ autoresize = { focusedwindow_minwidth = 55 } })
217+
edit(lorem_ipsum_file)
218+
child.set_cursor(15, 1)
219+
child.cmd('vsplit')
220+
local resize_state = child.get_resize_state()
221+
local win_id_left = resize_state.windows[1]
222+
local win_id_right = resize_state.windows[2]
223+
224+
eq(win_id_left, child.api.nvim_get_current_win())
225+
226+
-- Expect the left window's width to be at least 55.
227+
-- In the default test, the left width is 49.
228+
-- With forced focusedwindow_minwidth, we now expect 55.
229+
validate_win_dims(win_id_left, { 55, 23 })
230+
-- The right window should take the remaining width
231+
validate_win_dims(win_id_right, { 24, 23 })
232+
end
233+
234+
-- focused minwidth for vertical splits inferior to the default one obtained by
235+
-- the golden ratio
236+
T['autoresize']['vsplit focusedwindow_minwidth < golden_ratio expected value'] = function()
237+
reload_module({ autoresize = { focusedwindow_minwidth = 40 } })
238+
edit(lorem_ipsum_file)
239+
child.set_cursor(15, 1)
240+
child.cmd('vsplit')
241+
local resize_state = child.get_resize_state()
242+
local win_id_left = resize_state.windows[1]
243+
local win_id_right = resize_state.windows[2]
244+
245+
eq(win_id_left, child.api.nvim_get_current_win())
246+
247+
-- The expected value is the golden ratio one
248+
validate_win_dims(win_id_left, { 49, 23 })
249+
-- The right window should take the remaining width
250+
validate_win_dims(win_id_right, { 30, 23 })
251+
end
252+
253+
-- focused minheight for horizontal splits
254+
T['autoresize']['split focusedwindow_minheight'] = function()
255+
reload_module({ autoresize = { focusedwindow_minheight = 17 } })
256+
edit(lorem_ipsum_file)
257+
child.set_cursor(15, 1)
258+
child.cmd('split')
259+
local resize_state = child.get_resize_state()
260+
local win_id_upper = resize_state.windows[1]
261+
local win_id_lower = resize_state.windows[2]
262+
263+
-- In the default test, the upper window height is 15.
264+
-- With forced focusedwindow_minheight, we now expect 17.
265+
validate_win_dims(win_id_upper, { 80, 17 })
266+
-- The lower window gets the rest (assuming total height used equals 22)
267+
validate_win_dims(win_id_lower, { 80, 5 })
268+
end
269+
270+
-- focused minheight for horizontal splits inferior to the default one obtained by
271+
-- the golden ratio
272+
T['autoresize']['split focusedwindow_minheight < golden_ratio expected value'] = function()
273+
reload_module({ autoresize = { focusedwindow_minheight = 10 } })
274+
edit(lorem_ipsum_file)
275+
child.set_cursor(15, 1)
276+
child.cmd('split')
277+
local resize_state = child.get_resize_state()
278+
local win_id_upper = resize_state.windows[1]
279+
local win_id_lower = resize_state.windows[2]
280+
281+
-- The expected value is the golden ratio one
282+
validate_win_dims(win_id_upper, { 80, 15 })
283+
-- The lower window gets the rest
284+
validate_win_dims(win_id_lower, { 80, 7 })
285+
end
286+
287+
-- focused minwidth for vertical splits with minwidth + focusedwindow_minwidth >
288+
-- maxwidth.
289+
T['autoresize']['vsplit minwidth focusedwindow_minwidth'] = function()
290+
reload_module({
291+
autoresize = { minwidth = 20, focusedwindow_minwidth = 80 },
292+
})
293+
edit(lorem_ipsum_file)
294+
child.set_cursor(15, 1)
295+
child.cmd('vsplit')
296+
local resize_state = child.get_resize_state()
297+
local win_id_left = resize_state.windows[1]
298+
local win_id_right = resize_state.windows[2]
299+
300+
eq(win_id_left, child.api.nvim_get_current_win())
301+
302+
-- Expect the left window's width to be at least the maxwidth (80) minus 21,
303+
-- 20 from the right window as the minimum width possible and 1 from the
304+
-- separator.
305+
-- With forced focusedwindow_minwidth, we now expect 59.
306+
validate_win_dims(win_id_left, { 78, 23 })
307+
-- The right window should have the minwidth.
308+
validate_win_dims(win_id_right, { 1, 23 })
309+
310+
child.api.nvim_set_current_win(win_id_right)
311+
312+
validate_win_dims(win_id_left, { 1, 23 })
313+
-- The right window should have the minwidth.
314+
validate_win_dims(win_id_right, { 78, 23 })
315+
end
316+
317+
-- focused minheight for horizontal splits with minheight as 0
318+
T['autoresize']['split minheight focusedwindow_minheight'] = function()
319+
reload_module({
320+
autoresize = { minheight = 10, focusedwindow_minheight = 25 },
321+
})
322+
edit(lorem_ipsum_file)
323+
child.set_cursor(15, 1)
324+
child.cmd('split')
325+
local resize_state = child.get_resize_state()
326+
local win_id_upper = resize_state.windows[1]
327+
local win_id_lower = resize_state.windows[2]
328+
329+
-- Expect the upper window's height to be at least the maxheight (23) minus 2,
330+
-- 1 from the lower window as the minimum height and 1 from the separator.
331+
-- With forced focusedwindow_minheight, we now expect 21.
332+
validate_win_dims(win_id_upper, { 80, 21 })
333+
-- The lower window should have the minimum height.
334+
validate_win_dims(win_id_lower, { 80, 1 })
335+
end
336+
214337
T['autoresize']['quickfix'] = function()
215338
reload_module({ autoresize = { height_quickfix = 10 } })
216339
child.cmd('vimgrep /ipsum/' .. lorem_ipsum_file)

0 commit comments

Comments
 (0)