Skip to content

Commit

Permalink
Less flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Nov 19, 2024
1 parent b5a2289 commit fac6b27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lua/winmove/resize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ local function adjust_neighbors_in_direction(dir, get_dimension, min_dimension,
resize.resize_window,
neighbor_win_id,
dir,
count,
min_dimension - dimension,
anchor
)

Expand Down
50 changes: 24 additions & 26 deletions tests/resize_adjust_neighbors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,30 @@ describe("resize", function()
},
})

---@type table<integer, integer>
local minwidth_map = {}
vim.go.winwidth = vim.o.columns / 5 / 2

for _, _win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
vim.api.nvim_win_call(_win_id, function()
local minwidth = vim.api.nvim_win_get_width(win_id) - count * 3
vim.opt_local.signcolumn = "no"
vim.opt_local.winwidth = minwidth
minwidth_map[_win_id] = minwidth
end)
vim.wo[_win_id].signcolumn = "no"
end

vim.api.nvim_set_current_win(win_id)

local _, _, main_width_before, _ = get_win_pos_and_dimensions(win_id)
local _, col_before1, _, _ = get_win_pos_and_dimensions(layout["neighbor1"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, col_before1, n1_width_before, _ =
get_win_pos_and_dimensions(layout["neighbor1"])
local _, _, n2_width_before, _ = get_win_pos_and_dimensions(layout["neighbor2"])
local _, _, n3_width_before, _ = get_win_pos_and_dimensions(layout["neighbor3"])
local _, _, _, _ = get_win_pos_and_dimensions(layout["bottom neighbor"])
local _, col_before4, width_before4, _ =
get_win_pos_and_dimensions(layout["neighbor4"])

for _ = 1, 10 do
local resize_count = n1_width_before
+ n2_width_before
+ n3_width_before
- (vim.go.winwidth * 3)
+ 1

for _ = 1, resize_count do
winmove.resize_window(win_id, "h", count, winmove.ResizeAnchor.BottomRight)
end

Expand All @@ -305,37 +306,34 @@ describe("resize", function()

assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor1"]),
minwidth_map[layout["neighbor1"]]
vim.go.winwidth
)
assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor2"]),
minwidth_map[layout["neighbor2"]]
vim.go.winwidth
)
assert.are.same(
vim.api.nvim_win_get_width(layout["neighbor3"]),
minwidth_map[layout["neighbor3"]]
vim.go.winwidth
)

-- + 3 for the window separators
local left_total_width = minwidth_map[layout["neighbor1"]]
+ minwidth_map[layout["neighbor2"]]
+ minwidth_map[layout["neighbor3"]]
local left_total_width = vim.api.nvim_win_get_width(layout["neighbor1"])
+ vim.api.nvim_win_get_width(layout["neighbor2"])
+ vim.api.nvim_win_get_width(layout["neighbor3"])
+ 3

assert.are.same(main_col_after, left_total_width)
assert.is._true(main_width_after > main_width_before)

assert.are.same(col_before1, col_after1)
assert.are.same(width_after1, minwidth_map[layout["neighbor1"]])
assert.are.same(width_after1, vim.go.winwidth)

assert.are.same(col_after2, minwidth_map[layout["neighbor1"]] + 1)
assert.are.same(width_after2, minwidth_map[layout["neighbor2"]])
assert.are.same(col_after2, vim.go.winwidth + 1)
assert.are.same(width_after2, vim.go.winwidth)

assert.are.same(
col_after3,
minwidth_map[layout["neighbor1"]] + minwidth_map[layout["neighbor2"]] + 2
)
assert.are.same(width_after3, minwidth_map[layout["neighbor3"]])
assert.are.same(col_after3, vim.go.winwidth * 2 + 2)
assert.are.same(width_after3, vim.go.winwidth)

-- + 2 for the window separators
local top_column_width = vim.api.nvim_win_get_width(layout["neighbor2"])
Expand Down

0 comments on commit fac6b27

Please sign in to comment.