repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
neovim/tests/bugabinga/image/geometry_spec.lua
Rawlocal geometry = require 'bugabinga.image.geometry'
describe('image geometry', function()
it('uses text origin and excludes gutters without subtracting the winbar twice', function()
local rect = geometry.rectangle(
{ winrow = 3, wincol = 12, width = 50, height = 20, textoff = 6, winbar = 1 },
{ width = 4000, height = 4000 },
{ cell_width = 10, cell_height = 23 }
)
assert.equal(4, rect.row)
assert.equal(18, rect.col)
assert.is_true(rect.cols <= 44)
assert.is_true(rect.rows <= 20)
end)
it('fits compact, wide, tall and short viewports with measured cells', function()
for _, viewport in ipairs({ { 63, 20 }, { 98, 29 }, { 148, 38 }, { 63, 42 }, { 148, 18 } }) do
local rect = geometry.rectangle(
{ winrow = 2, wincol = 1, width = viewport[1], height = viewport[2] - 3, textoff = 0 },
{ width = 3840, height = 2160 },
{ cell_width = 10, cell_height = 23 }
)
assert.is_true(rect.cols <= viewport[1])
assert.is_true(rect.rows <= viewport[2] - 3)
local ratio = rect.cols * 10 / (rect.rows * 23)
assert.is_true(math.abs(ratio / (3840 / 2160) - 1) < 0.05)
end
end)
it('minimizes cell-grid distortion when the terminal requires both dimensions', function()
for _, viewport in ipairs({ { 63, 20 }, { 98, 29 }, { 148, 38 }, { 63, 42 }, { 148, 18 } }) do
local rect = geometry.rectangle(
{ winrow = 2, wincol = 1, width = viewport[1], height = viewport[2] - 3, textoff = 0 },
{ width = 600, height = 400 },
{ cell_width = 10, cell_height = 23, explicit_size = true }
)
assert.equal('both', rect.axis)
assert.is_true(math.abs(rect.cols * 10 / (rect.rows * 23) / 1.5 - 1) < 0.02)
end
end)
it('does not upscale small images or draw into a zero-width text area', function()
local info = { winrow = 1, wincol = 1, width = 100, height = 40, textoff = 0 }
local image = { width = 20, height = 46 }
assert.same({ row = 1, col = 1, cols = 2, rows = 2, axis = 'cols' },
geometry.rectangle(info, image, { cell_width = 10, cell_height = 23 }))
info.textoff = 100
assert.is_nil(geometry.rectangle(info, image, { cell_width = 10, cell_height = 23 }))
end)
it('treats touching edges as non-overlapping', function()
local rect = { row = 2, col = 3, rows = 5, cols = 8 }
assert.is_false(geometry.overlaps(rect, { row = 7, col = 3, rows = 1, cols = 8 }))
assert.is_true(geometry.overlaps(rect, { row = 6, col = 10, rows = 2, cols = 2 }))
end)
end)