repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/tests/bugabinga/statusline_spec.lua
Rawrequire('bugabinga.statusline')
local icon = require('std.icon')
describe('statusline', function()
describe('plugins_component', function()
before_each(function()
BugabingaStatusline.reset()
end)
after_each(function()
BugabingaStatusline.reset()
end)
it('filters out empty string results from registered components', function()
BugabingaStatusline.register(function() return 'foo' end)
BugabingaStatusline.register(function() return '' end)
BugabingaStatusline.register(function() return 'bar' end)
BugabingaStatusline.register(function() return '' end)
local result = BugabingaStatusline.plugins_component()
assert.is_equal('foo bar', result)
end)
it('returns empty string when all components return empty', function()
BugabingaStatusline.register(function() return '' end)
BugabingaStatusline.register(function() return '' end)
local result = BugabingaStatusline.plugins_component()
assert.is_equal('', result)
end)
end)
describe('git_component', function()
local initial_cwd
before_each(function()
initial_cwd = vim.uv.cwd()
BugabingaStatusline._get_cache().git_branch = {}
end)
after_each(function()
BugabingaStatusline._get_cache().git_branch = {}
end)
it('returns empty string on first call (async loading)', function()
local result = BugabingaStatusline.git_component()
assert.is_equal('', result)
end)
it('returns cached branch string when available', function()
local fake_branch = icon.branch .. ' test-branch'
BugabingaStatusline._get_cache().git_branch[initial_cwd] = fake_branch
local result = BugabingaStatusline.git_component()
assert.is_equal(fake_branch, result)
end)
it('DirChanged clears git branch cache', function()
local fake_branch = icon.branch .. ' test-branch'
BugabingaStatusline._get_cache().git_branch[initial_cwd] = fake_branch
assert.is_true(vim.tbl_count(BugabingaStatusline._get_cache().git_branch) > 0, 'cache should have entry before')
vim.api.nvim_exec_autocmds('DirChanged', {})
assert.equals(0, vim.tbl_count(BugabingaStatusline._get_cache().git_branch), 'cache should be cleared after DirChanged')
end)
end)
end)