tests: add statusline test module & update lualine_spec accordingly(#588)

* enhance: add statusline test module

* update old tests to use statusline test setup

* show diff in statusline:expect

* Revert "show diff in statusline:expect"

This reverts commit cea25185fde1b99110759f198ef1fc724626306c.

* autoformat

* fix testcov reports

* update statusline test module

* revert lualine_spec

* update lualine_spec using statusline module

* apply formater

* add tabline support to statusline test module

* re enable tabline tests

* fix inconsistency in buffers mode test due to bufnr changing

Should we be showing bufnr/buffer_position in buffers component

* autoformat

* minor tweeks to stl test module

* use nvim_eval_statusline in nvim-0.6+

* fix tabs component on nvim-0.5

* enable disabled branch test
This commit is contained in:
Shadman 2022-03-05 13:40:36 +00:00 committed by GitHub
parent 21fdf7b9fa
commit 747ef49b98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1029 additions and 347 deletions

View File

@ -15,6 +15,6 @@ return {
}, },
statsfile = 'luacov.stats', statsfile = 'luacov.stats',
reportfile = 'luacov.report', reportfile = 'luacov.report',
includeuntestedfiles = true, -- includeuntestedfiles = true,
} }
-- vim:ft=lua -- vim:ft=lua

View File

@ -19,7 +19,8 @@ end
--- of the tab. --- of the tab.
---@return string ---@return string
function Tab:label() function Tab:label()
local custom_tabname = vim.t[self.tabId].tabname local ok,custom_tabname = pcall(vim.api.nvim_tabpage_get_var, self.tabId, 'tabname')
if not ok then custom_tabname = nil end
if custom_tabname and custom_tabname ~= '' then if custom_tabname and custom_tabname ~= '' then
return modules.utils.stl_escape(custom_tabname) return modules.utils.stl_escape(custom_tabname)
end end

View File

@ -73,4 +73,27 @@ M.P = function(t)
print(vim.inspect(t)) print(vim.inspect(t))
end end
function M.dedent(str, leave_indent)
-- find minimum common indent across lines
local indent = nil
for line in str:gmatch('[^\n]+') do
local line_indent = line:match('^%s+') or ''
if indent == nil or #line_indent < #indent then
indent = line_indent
end
end
if indent == nil or #indent == 0 then
-- no minimum common indent
return str
end
local left_indent = (' '):rep(leave_indent or 0)
-- create a pattern for the indent
indent = indent:gsub('%s', '[ \t]')
-- strip it from the first line
str = str:gsub('^' .. indent, left_indent)
-- strip it from the remaining lines
str = str:gsub('[\n]' .. indent, '\n' .. left_indent)
return str
end
return M return M

View File

@ -568,7 +568,7 @@ describe('Branch component', function()
local tmpdir local tmpdir
local file local file
local git = function(...) local git = function(...)
return vim.fn.system('git -C ' .. tmpdir .. ' ' .. string.format(...)) return vim.fn.system("git -c user.name='asdf' -c user.email='asdf@jlk.org' -C " .. tmpdir .. ' ' .. string.format(...))
end end
local assert_comp_ins = helpers.assert_component_instence local assert_comp_ins = helpers.assert_component_instence
@ -604,20 +604,19 @@ describe('Branch component', function()
assert_comp_ins(branch_comp, 'test_branch2') assert_comp_ins(branch_comp, 'test_branch2')
end) end)
-- TODO: Figure out why this test fails in CI it('works in detached head mode', function()
-- it('works in detached head mode', function() local opts = build_component_opts {
-- local opts = build_component_opts { component_separators = { left = '', right = '' },
-- component_separators = { left = '', right = '' }, icons_enabled = false,
-- icons_enabled = false, padding = 0,
-- padding = 0, }
-- } git 'checkout -b test_branch2'
-- git 'checkout -b test_branch2' git 'commit --allow-empty -m "test commit1"'
-- git 'commit --allow-empty -m "test commit1"' git 'commit --allow-empty -m "test commit2"'
-- git 'commit --allow-empty -m "test commit2"' git 'commit --allow-empty -m "test commit3"'
-- git 'commit --allow-empty -m "test commit3"' git('checkout HEAD~1')
-- git('checkout HEAD~1') vim.cmd('e ' .. file)
-- vim.cmd('e ' .. file) local rev = git('rev-parse --short=6 HEAD'):sub(1, 6)
-- local rev = git('rev-parse --short=6 HEAD'):sub(1, 6) assert_component('branch', opts, rev)
-- assert_component('branch', opts, rev) end)
-- end)
end) end)

View File

@ -2,15 +2,14 @@
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local eq = assert.are.same local eq = assert.are.same
local statusline = require('tests.statusline').new(120, 'active')
local inactive_statusline = statusline.new(120, 'inactive')
local tabline = statusline.new(120, 'tabline')
describe('Lualine', function() describe('Lualine', function()
local utils = require('lualine.utils.utils') local config
local lualine_focused = true before_each(function()
utils.is_focused = function() config = {
return lualine_focused
end
local config = {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = 'gruvbox', theme = 'gruvbox',
@ -50,26 +49,45 @@ describe('Lualine', function()
tabline = {}, tabline = {},
extensions = {}, extensions = {},
} }
before_each(function()
vim.opt.swapfile = false
vim.cmd('bufdo bdelete') vim.cmd('bufdo bdelete')
pcall(vim.cmd, 'tabdo tabclose') pcall(vim.cmd, 'tabdo tabclose')
lualine_focused = true
require('lualine').setup(config) require('lualine').setup(config)
end) end)
it('shows active statusline', function() it('shows active statusline', function()
eq( statusline:expect([===[
'%#lualine_a_normal# NORMAL %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v ', highlights = {
require('lualine').statusline() 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
) 2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{2:}
{3: master }
{4:}
{5: [No Name] }
{5: }
{5: }
{4:}
{3: 100% }
{2:}
{1: 0:1 }|
]===])
end) end)
it('shows inactive statusline', function() it('shows inactive statusline', function()
lualine_focused = false inactive_statusline:expect([===[
eq( highlights = {
'%<%#lualine_c_inactive# [No Name] %#lualine_c_inactive#%=%#lualine_c_inactive# %3l:%-2v ', 1: lualine_c_inactive = { bg = "#3c3836", fg = "#a89984" }
require('lualine').statusline() }
) |{1: [No Name] }
{1: }
{1: 0:1 }|
]===])
end) end)
it('get_config can retrive config', function() it('get_config can retrive config', function()
@ -80,80 +98,161 @@ describe('Lualine', function()
local conf = require('lualine').get_config() local conf = require('lualine').get_config()
conf.sections.lualine_a = {} conf.sections.lualine_a = {}
require('lualine').setup(conf) require('lualine').setup(conf)
eq( statusline:expect([===[
'%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v ', highlights = {
require('lualine').statusline() 1: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
) 2: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
4: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
5: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
}
|{1: master }
{2:}
{3: [No Name] }
{3: }
{3: }
{2:}
{1: 100% }
{4:}
{5: 0:1 }|
]===])
end) end)
it('Can work without section separators', function() it('Can work without section separators', function()
local conf = vim.deepcopy(config) config.options.section_separators = ''
conf.options.section_separators = '' require('lualine').setup(config)
require('lualine').setup(conf) statusline:expect([===[
eq( highlights = {
'%#lualine_a_normal# NORMAL %#lualine_b_normal#  master %<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_b_normal# %3p%% %#lualine_a_normal# %3l:%-2v ', 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
require('lualine').statusline() 2: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
) 3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{2: master }
{3: [No Name] }
{3: }
{3: }
{2: 100% }
{1: 0:1 }|
]===])
end) end)
it('Can work without component_separators', function() it('Can work without component_separators', function()
local conf = vim.deepcopy(config) table.insert(config.sections.lualine_a, function()
table.insert(conf.sections.lualine_a, function()
return 'test_comp1' return 'test_comp1'
end) end)
table.insert(conf.sections.lualine_z, function() table.insert(config.sections.lualine_z, function()
return 'test_comp2' return 'test_comp2'
end) end)
require('lualine').setup(conf)
eq( require('lualine').setup(config)
'%#lualine_a_normal# NORMAL %#lualine_a_normal# test_comp1 %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v %#lualine_a_normal# test_comp2 ', statusline:expect([===[
require('lualine').statusline() highlights = {
) 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
conf.options.component_separators = '' 2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
require('lualine').setup(conf) 3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
eq( 4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
'%#lualine_a_normal# NORMAL %#lualine_a_normal# test_comp1 %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v %#lualine_a_normal# test_comp2 ', 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
require('lualine').statusline() }
) |{1: NORMAL }
{1: test_comp1 }
{2:}
{3: master }
{4:}
{5: [No Name] }
{5: }
{5: }
{4:}
{3: 100% }
{2:}
{1: 0:1 }
{1: test_comp2 }|
]===])
config.options.component_separators = ''
require('lualine').setup(config)
statusline:expect([===[
highlights = {
1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{1: test_comp1 }
{2:}
{3: master }
{4:}
{5: [No Name] }
{5: }
{5: }
{4:}
{3: 100% }
{2:}
{1: 0:1 }
{1: test_comp2 }|
]===])
end) end)
it('mid divider can be disbled on special case', function() it('mid divider can be disbled on special case', function()
local conf = vim.deepcopy(config) config.options.always_divide_middle = false
conf.options.always_divide_middle = false config.sections.lualine_x = {}
conf.sections.lualine_x = {} config.sections.lualine_y = {}
conf.sections.lualine_y = {} config.sections.lualine_z = {}
conf.sections.lualine_z = {} require('lualine').setup(config)
require('lualine').setup(conf) statusline:expect([===[
eq( highlights = {
'%#lualine_a_normal# NORMAL %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] ', 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
require('lualine').statusline(true) 2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
) 3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{2:}
{3: master }
{4:}
{5: [No Name] }|
]===])
end) end)
it('works with icons disabled', function() it('works with icons disabled', function()
local conf = vim.deepcopy(config) config.options.icons_enabled = false
conf.options.icons_enabled = false config.options.section_separators = ''
conf.options.section_separators = '' require('lualine').setup(config)
require('lualine').setup(conf) statusline:expect([===[
eq( highlights = {
'%#lualine_a_normal# NORMAL %#lualine_b_normal# master %<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal# unix %#lualine_b_normal# %3p%% %#lualine_a_normal# %3l:%-2v ', 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
require('lualine').statusline(true) 2: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
) 3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{2: master }
{3: [No Name] }
{3: }
{3: unix }
{2: 100% }
{1: 0:1 }|
]===])
end) end)
it('can be desabled for specific filetypes', function() it('can be desabled for specific filetypes', function()
local conf = vim.deepcopy(config) config.options.disabled_filetypes = { 'test_ft' }
conf.options.disabled_filetypes = { 'test_ft' } require('lualine').setup(config)
require('lualine').setup(conf)
local old_ft = vim.bo.ft local old_ft = vim.bo.ft
vim.bo.ft = 'test_ft' vim.bo.ft = 'test_ft'
eq('', require('lualine').statusline(true)) statusline:expect([===[
highlights = {
1: StatusLine = { bold = true, reverse = true }
}
||
]===])
vim.bo.ft = old_ft vim.bo.ft = old_ft
end) end)
it('can apply custom extensions', function() it('can apply custom extensions', function()
local conf = vim.deepcopy(config) table.insert(config.extensions, {
table.insert(conf.extensions, {
filetypes = { 'test_ft' }, filetypes = { 'test_ft' },
sections = { sections = {
lualine_a = { lualine_a = {
@ -165,17 +264,22 @@ describe('Lualine', function()
}) })
local old_ft = vim.bo.ft local old_ft = vim.bo.ft
vim.bo.ft = 'test_ft' vim.bo.ft = 'test_ft'
require('lualine').setup(conf) require('lualine').setup(config)
eq( statusline:expect([===[
'%#lualine_a_normal# custom_extension_component %#lualine_transitional_lualine_a_normal_to_lualine_c_normal#%#lualine_c_normal#%=', highlights = {
require('lualine').statusline(true) 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
) 2: lualine_transitional_lualine_a_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: custom_extension_component }
{2:}
{3: }|
]===])
vim.bo.ft = old_ft vim.bo.ft = old_ft
end) end)
it('same extension can be applied to multiple filetypes', function() it('same extension can be applied to multiple filetypes', function()
local conf = vim.deepcopy(config) table.insert(config.extensions, {
table.insert(conf.extensions, {
filetypes = { 'test_ft1', 'test_ft2' }, filetypes = { 'test_ft1', 'test_ft2' },
sections = { sections = {
lualine_a = { lualine_a = {
@ -187,226 +291,465 @@ describe('Lualine', function()
}) })
local old_ft = vim.bo.ft local old_ft = vim.bo.ft
vim.bo.ft = 'test_ft1' vim.bo.ft = 'test_ft1'
require('lualine').setup(conf) require('lualine').setup(config)
eq( statusline:expect([===[
'%#lualine_a_normal# custom_extension_component %#lualine_transitional_lualine_a_normal_to_lualine_c_normal#%#lualine_c_normal#%=', highlights = {
require('lualine').statusline() 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
) 2: lualine_transitional_lualine_a_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: custom_extension_component }
{2:}
{3: }|
]===])
vim.bo.ft = old_ft vim.bo.ft = old_ft
eq( statusline:expect([===[
'%#lualine_a_normal# NORMAL %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v ', highlights = {
require('lualine').statusline() 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
) 2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: NORMAL }
{2:}
{3: master }
{4:}
{5: [No Name] }
{5: }
{5: }
{4:}
{3: 100% }
{2:}
{1: 0:1 }|
]===])
vim.bo.ft = 'test_ft2' vim.bo.ft = 'test_ft2'
eq( statusline:expect([===[
'%#lualine_a_normal# custom_extension_component %#lualine_transitional_lualine_a_normal_to_lualine_c_normal#%#lualine_c_normal#%=', highlights = {
require('lualine').statusline() 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
) 2: lualine_transitional_lualine_a_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: custom_extension_component }
{2:}
{3: }|
]===])
vim.bo.ft = old_ft vim.bo.ft = old_ft
end) end)
-- TODO: figure put why some of the tablines tests fail in CI -- TODO: figure put why some of the tablines tests fail in CI
-- describe('tabline', function() describe('tabline', function()
-- local tab_conf = vim.deepcopy(config) local tab_conf = vim.deepcopy(config)
-- tab_conf.tabline = { tab_conf.tabline = {
-- lualine_a = { lualine_a = {
-- function() function()
-- return 'tabline_component' return 'tabline_component'
-- end, end,
-- }, },
-- lualine_b = {}, lualine_b = {},
-- lualine_c = {}, lualine_c = {},
-- lualine_x = {}, lualine_x = {},
-- lualine_y = {}, lualine_y = {},
-- lualine_z = {}, lualine_z = {},
-- } }
--
-- it('can use tabline', function() it('can use tabline', function()
-- local conf = vim.deepcopy(tab_conf) local conf = vim.deepcopy(tab_conf)
-- conf.tabline.lualine_a = { conf.tabline.lualine_a = {
-- function() function()
-- return 'tabline_component' return 'tabline_component'
-- end, end,
-- } }
-- require('lualine').setup(conf) require('lualine').setup(conf)
-- require('lualine').statusline() require('lualine').statusline()
-- eq( tabline:expect([===[
-- '%#lualine_a_normal# tabline_component %#lualine_transitional_lualine_a_normal_to_lualine_c_normal#%#lualine_c_normal#%=', highlights = {
-- require('lualine').tabline() 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
-- ) 2: lualine_transitional_lualine_a_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- end) 3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- }
-- it('can use tabline as statusline', function() |{1: tabline_component }
-- local conf = vim.deepcopy(config) {2:}
-- conf.tabline = conf.sections {3: }|
-- conf.sections = {} ]===])
-- conf.inactive_sections = {} end)
-- require('lualine').setup(conf)
-- require('lualine').statusline() it('can use tabline as statusline', function()
-- eq('', vim.go.statusline) local conf = vim.deepcopy(config)
-- eq( conf.tabline = conf.sections
-- '%#lualine_a_normal# NORMAL %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_b_normal#  master %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%<%#lualine_c_normal# [No Name] %#lualine_c_normal#%=%#lualine_c_normal#  %#lualine_transitional_lualine_b_normal_to_lualine_c_normal#%#lualine_b_normal# %3p%% %#lualine_transitional_lualine_a_normal_to_lualine_b_normal#%#lualine_a_normal# %3l:%-2v ', conf.sections = {}
-- require('lualine').tabline() conf.inactive_sections = {}
-- ) require('lualine').setup(conf)
-- end) require('lualine').statusline()
-- describe('tabs component', function() eq('', vim.go.statusline)
-- it('works', function()
-- local conf = vim.deepcopy(tab_conf) tabline:expect([===[
-- conf.tabline.lualine_a = { { 'tabs', max_length = 1e3 } } highlights = {
-- vim.cmd 'tabnew' 1: lualine_a_normal = { bg = "#a89984", bold = true, fg = "#282828" }
-- vim.cmd 'tabnew' 2: lualine_transitional_lualine_a_normal_to_lualine_b_normal = { bg = "#504945", fg = "#a89984" }
-- require('lualine').setup(conf) 3: lualine_b_normal = { bg = "#504945", fg = "#ebdbb2" }
-- require('lualine').statusline() 4: lualine_transitional_lualine_b_normal_to_lualine_c_normal = { bg = "#3c3836", fg = "#504945" }
-- eq( 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ 1 %T%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ 2 %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%3@LualineSwitchTab@ 3 %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', }
-- require('lualine').tabline() |{1: NORMAL }
-- ) {2:}
-- vim.cmd 'tabprev' {3: master }
-- eq( {4:}
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ 1 %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%2@LualineSwitchTab@ 2 %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_tabs_active_0_no_mode#%#lualine_tabs_active_0_no_mode#%3@LualineSwitchTab@ 3 %T%#lualine_c_normal#%=', {5: [No Name] }
-- require('lualine').tabline() {5: }
-- ) {5: }
-- vim.cmd 'tabprev' {4:}
-- eq( {3: 100% }
-- '%#lualine_tabs_active_no_mode#%1@LualineSwitchTab@ 1 %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_tabs_active_0_no_mode#%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ 2 %T%#lualine_tabs_active_0_no_mode#%3@LualineSwitchTab@ 3 %T%#lualine_c_normal#%=', {2:}
-- require('lualine').tabline() {1: 0:1 }|
-- ) ]===])
-- end) end)
-- it('mode option can change layout', function() describe('tabs component', function()
-- local conf = vim.deepcopy(tab_conf) it('works', function()
-- conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 0 } } local conf = vim.deepcopy(tab_conf)
-- vim.cmd('tabe ' .. 'a.txt') conf.tabline.lualine_a = { { 'tabs', max_length = 1e3 } }
-- vim.cmd('tabe ' .. 'b.txt') vim.cmd('tabnew')
-- require('lualine').setup(conf) vim.cmd('tabnew')
-- require('lualine').statusline() require('lualine').setup(conf)
-- eq( require('lualine').statusline()
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ 1 %T%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ 2 %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%3@LualineSwitchTab@ 3 %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', tabline:expect([===[
-- require('lualine').tabline() highlights = {
-- ) 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 1 } } 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- require('lualine').setup(conf) 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- require('lualine').statusline() 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- eq( 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ [No Name] %T%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ a.txt %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%3@LualineSwitchTab@ b.txt %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', }
-- require('lualine').tabline() |{1: 1 }
-- ) {1: 2 }
-- conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 2 } } {2:}
-- require('lualine').setup(conf) {3: 3 }
-- require('lualine').statusline() {4:}
-- eq( {5: }|
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ 1 [No Name] %T%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ 2 a.txt %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%3@LualineSwitchTab@ 3 b.txt %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', ]===])
-- require('lualine').tabline()
-- ) vim.cmd('tabprev')
-- end) tabline:expect([===[
-- end) highlights = {
-- 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- describe('buffers component', function() 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- it('works', function() 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- local conf = vim.deepcopy(tab_conf) 4: lualine_transitional_lualine_a_tabs_active_to_lualine_a_tabs_inactive = { bg = "#3c3836", fg = "#a89984" }
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, icons_enabled = false } } 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- vim.cmd('tabe ' .. 'a.txt') }
-- vim.cmd('tabe ' .. 'b.txt') |{1: 1 }
-- require('lualine').setup(conf) {2:}
-- require('lualine').statusline() {3: 2 }
-- eq( {4:}
-- '%#lualine_buffers_active_0_no_mode#%4@LualineSwitchBuffer@ a.txt %T%#lualine_transitional_lualine_buffers_active_0_no_mode_to_lualine_buffers_active_no_mode#%#lualine_buffers_active_no_mode#%5@LualineSwitchBuffer@ b.txt %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_buffers_active_0_no_mode#%#lualine_buffers_active_0_no_mode#%6@LualineSwitchBuffer@ [No Name] %T%#lualine_c_normal#%=', {1: 3 }
-- require('lualine').tabline() {5: }|
-- ) ]===])
-- vim.cmd 'tabprev'
-- eq( vim.cmd('tabprev')
-- '%#lualine_buffers_active_no_mode#%4@LualineSwitchBuffer@ a.txt %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_buffers_active_0_no_mode#%#lualine_buffers_active_0_no_mode#%5@LualineSwitchBuffer@ b.txt %T%#lualine_buffers_active_0_no_mode#%6@LualineSwitchBuffer@ [No Name] %T%#lualine_c_normal#%=', tabline:expect([===[
-- require('lualine').tabline() highlights = {
-- ) 1: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- vim.cmd 'tabprev' 2: lualine_transitional_lualine_a_tabs_active_to_lualine_a_tabs_inactive = { bg = "#3c3836", fg = "#a89984" }
-- eq( 3: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- '%#lualine_buffers_active_0_no_mode#%4@LualineSwitchBuffer@ a.txt %T%#lualine_buffers_active_0_no_mode#%5@LualineSwitchBuffer@ b.txt %T%#lualine_transitional_lualine_buffers_active_0_no_mode_to_lualine_buffers_active_no_mode#%#lualine_buffers_active_no_mode#%6@LualineSwitchBuffer@ [No Name] %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', 4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- require('lualine').tabline() }
-- ) |{1: 1 }
-- end) {2:}
-- it('mode option can change layout', function() {3: 2 }
-- local conf = vim.deepcopy(tab_conf) {3: 3 }
-- conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 0, icons_enabled = false } } {4: }|
-- vim.cmd('tabe ' .. 'a.txt') ]===])
-- vim.cmd('tabe ' .. 'b.txt') end)
-- require('lualine').setup(conf)
-- require('lualine').statusline() it('mode option can change layout', function()
-- eq( local conf = vim.deepcopy(tab_conf)
-- '%#lualine_tabs_active_0_no_mode#%1@LualineSwitchTab@ 1 %T%#lualine_tabs_active_0_no_mode#%2@LualineSwitchTab@ 2 %T%#lualine_transitional_lualine_tabs_active_0_no_mode_to_lualine_tabs_active_no_mode#%#lualine_tabs_active_no_mode#%3@LualineSwitchTab@ 3 %T%#lualine_transitional_lualine_tabs_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 0 } }
-- require('lualine').tabline() vim.cmd('tabe ' .. 'a.txt')
-- ) vim.cmd('tabe ' .. 'b.txt')
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, mode = 1, icons_enabled = false } } require('lualine').setup(conf)
-- require('lualine').setup(conf) require('lualine').statusline()
-- require('lualine').statusline() tabline:expect([===[
-- eq( highlights = {
-- '%#lualine_buffers_active_0_no_mode#%4@LualineSwitchBuffer@ 4 %T%#lualine_transitional_lualine_buffers_active_0_no_mode_to_lualine_buffers_active_no_mode#%#lualine_buffers_active_no_mode#%5@LualineSwitchBuffer@ 5 %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_buffers_active_0_no_mode#%#lualine_buffers_active_0_no_mode#%6@LualineSwitchBuffer@ 6 %T%#lualine_c_normal#%=', 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- require('lualine').tabline() 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- ) 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, mode = 2, icons_enabled = false } } 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- require('lualine').setup(conf) 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- require('lualine').statusline() }
-- eq( |{1: 1 }
-- '%#lualine_buffers_active_0_no_mode#%4@LualineSwitchBuffer@ 4 a.txt %T%#lualine_transitional_lualine_buffers_active_0_no_mode_to_lualine_buffers_active_no_mode#%#lualine_buffers_active_no_mode#%5@LualineSwitchBuffer@ 5 b.txt %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_buffers_active_0_no_mode#%#lualine_buffers_active_0_no_mode#%6@LualineSwitchBuffer@ 6 [No Name] %T%#lualine_c_normal#%=', {1: 2 }
-- require('lualine').tabline() {2:}
-- ) {3: 3 }
-- end) {4:}
-- {5: }|
-- it('can show modified status', function() ]===])
-- local conf = vim.deepcopy(tab_conf)
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_modified_status = true, icons_enabled = false } } tabline:expect([===[
-- require('lualine').setup(conf) highlights = {
-- require('lualine').statusline() 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- eq( 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- '%#lualine_buffers_active_no_mode#%6@LualineSwitchBuffer@ [No Name] %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- require('lualine').tabline() 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- ) 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- vim.bo.modified = true }
-- eq( |{1: 1 }
-- '%#lualine_buffers_active_no_mode#%6@LualineSwitchBuffer@ [No Name] + %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', {1: 2 }
-- require('lualine').tabline() {2:}
-- ) {3: 3 }
-- vim.bo.modified = false {4:}
-- end) {5: }|
-- ]===])
-- it('can show relative path', function()
-- local conf = vim.deepcopy(tab_conf) conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 1 } }
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_filename_only = false, icons_enabled = false } } require('lualine').setup(conf)
-- require('lualine').setup(conf) require('lualine').statusline()
-- require('lualine').statusline() tabline:expect([===[
-- vim.cmd('e ' .. os.tmpname()) highlights = {
-- eq( 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- '%#lualine_buffers_active_no_mode#%6@LualineSwitchBuffer@ ' 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- .. vim.fn.pathshorten(vim.fn.expand '%:p:.') 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- .. ' %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- require('lualine').tabline() 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- ) }
-- end) |{1: [No Name] }
-- {1: a.txt }
-- it('can show ellipsis when max_width is crossed', function() {2:}
-- local conf = vim.deepcopy(tab_conf) {3: b.txt }
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1 } } {4:}
-- vim.cmd 'tabe a.txt' {5: }|
-- vim.cmd 'tabe b.txt' ]===])
-- vim.cmd 'tabprev'
-- require('lualine').setup(conf) conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 2 } }
-- require('lualine').statusline() require('lualine').setup(conf)
-- eq( require('lualine').statusline()
-- '%#lualine_buffers_active_no_mode#%4@LualineSwitchBuffer@ a.txt %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_buffers_active_0_no_mode#%#lualine_buffers_active_0_no_mode#%5@LualineSwitchBuffer@ ... %T%#lualine_c_normal#%=', tabline:expect([===[
-- require('lualine').tabline() highlights = {
-- ) 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
-- end) 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
-- 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
-- it('can show filetype icons', function() 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- local conf = vim.deepcopy(tab_conf) 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
-- conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_filename_only = false } } }
-- require('lualine').setup(conf) |{1: 1 [No Name] }
-- require('lualine').statusline() {1: 2 a.txt }
-- vim.cmd('e t.lua') {2:}
-- eq( {3: 3 b.txt }
-- '%#lualine_buffers_active_no_mode#%7@LualineSwitchBuffer@  t.lua %T%#lualine_transitional_lualine_buffers_active_no_mode_to_lualine_c_normal#%#lualine_c_normal#%=', {4:}
-- require('lualine').tabline() {5: }|
-- ) ]===])
-- end) end)
-- end)
-- end)
-- end) describe('buffers component', function()
it('works', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, icons_enabled = false } }
vim.cmd('tabe ' .. 'a.txt')
vim.cmd('tabe ' .. 'b.txt')
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
2: lualine_transitional_lualine_a_buffers_inactive_to_lualine_a_buffers_active = { bg = "#a89984", fg = "#3c3836" }
3: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
4: lualine_transitional_lualine_a_buffers_active_to_lualine_a_buffers_inactive = { bg = "#3c3836", fg = "#a89984" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: a.txt }
{2:}
{3: b.txt }
{4:}
{1: [No Name] }
{5: }|
]===])
vim.cmd('tabprev')
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_a_buffers_inactive = { bg = "#3c3836", fg = "#a89984" }
3: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: a.txt }
{2:}
{3: b.txt }
{3: [No Name] }
{4: }|
]===])
vim.cmd('tabprev')
tabline:expect([===[
highlights = {
1: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
2: lualine_transitional_lualine_a_buffers_inactive_to_lualine_a_buffers_active = { bg = "#a89984", fg = "#3c3836" }
3: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
4: lualine_transitional_lualine_a_buffers_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: a.txt }
{1: b.txt }
{2:}
{3: [No Name] }
{4:}
{5: }|
]===])
end)
it('mode option can change layout', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'tabs', max_length = 1e3, mode = 0, icons_enabled = false } }
vim.cmd('tabe ' .. 'a.txt')
vim.cmd('tabe ' .. 'b.txt')
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
{MATCH:|{1: %d+ }}
{MATCH:{1: %d+ }}
{2:}
{MATCH:{3: %d+ }}
{4:}
{MATCH:{5:%s+}|}
]===])
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, mode = 1, icons_enabled = false } }
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
2: lualine_transitional_lualine_a_buffers_inactive_to_lualine_a_buffers_active = { bg = "#a89984", fg = "#3c3836" }
3: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
4: lualine_transitional_lualine_a_buffers_active_to_lualine_a_buffers_inactive = { bg = "#3c3836", fg = "#a89984" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
{MATCH:|{1: %d+ }}
{2:}
{MATCH:{3: %d+ }}
{4:}
{MATCH:{1: %d+ }}
{MATCH:{5:%s+}|}
]===])
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, mode = 2, icons_enabled = false } }
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
2: lualine_transitional_lualine_a_buffers_inactive_to_lualine_a_buffers_active = { bg = "#a89984", fg = "#3c3836" }
3: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
4: lualine_transitional_lualine_a_buffers_active_to_lualine_a_buffers_inactive = { bg = "#3c3836", fg = "#a89984" }
5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
{MATCH:|{1: %d+ a.txt }}
{2:}
{MATCH:{3: %d+ b.txt }}
{4:}
{MATCH:{1: %d+ %[No Name%] }}
{MATCH:{5:%s+}|}
]===])
end)
it('can show modified status', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_modified_status = true, icons_enabled = false } }
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: [No Name] }
{2:}
{3: }|
]===])
vim.bo.modified = true
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: [No Name] + }
{2:}
{3: }|
]===])
vim.bo.modified = false
end)
it('can show relative path', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_filename_only = false, icons_enabled = false } }
require('lualine').setup(conf)
require('lualine').statusline()
local path = 'aaaaaa/bbbbb/cccccc/ddddd/eeeee/ffff/gggg'
vim.fn.mkdir(path, 'p')
vim.cmd('e ' .. path .. '/asdf.txt')
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: a/b/c/d/e/f/g/asdf.txt }
{2:}
{3: }|
]===])
vim.fn.delete(path:match('(%w+)/.*'), 'rf')
end)
it('can show ellipsis when max_width is crossed', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'buffers', max_length = 1 } }
vim.cmd('tabe a.txt')
vim.cmd('tabe b.txt')
vim.cmd('tabprev')
require('lualine').setup(conf)
require('lualine').statusline()
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_a_buffers_inactive = { bg = "#3c3836", fg = "#a89984" }
3: lualine_a_buffers_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
4: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: a.txt }
{2:}
{3: ... }
{4: }|
]===])
end)
it('can show filetype icons', function()
local conf = vim.deepcopy(tab_conf)
conf.tabline.lualine_a = { { 'buffers', max_length = 1e3, show_filename_only = false } }
require('lualine').setup(conf)
require('lualine').statusline()
vim.cmd('e t.lua')
tabline:expect([===[
highlights = {
1: lualine_a_buffers_active = { bg = "#a89984", bold = true, fg = "#282828" }
2: lualine_transitional_lualine_a_buffers_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
3: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
}
|{1: t.lua }
{2:}
{3: }|
]===])
end)
end)
end)
end) end)

316
lua/tests/statusline.lua Normal file
View File

@ -0,0 +1,316 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
--- ## Testing module for lualines statusline
---
--- ###Uses:
---
--- Create a new instence with status width 120 & for active statusline
--- like following.
---
--- ``lua
--- local statusline = require('tests.statusline').new(120, 'active')
--- ```
---
--- To create a new instence with status width 80 & for inactive statusline use following.
---
--- ``lua
--- local statusline = require('tests.statusline').new(120, 'inactive')
--- ```
---
--- Now setup the state you want to test.
--- To test you'll call `expect` pmethod on statusline for example.
---
--- To create a new instence with status width 80 & tabline
---
--- ``lua
--- local statusline = require('tests.statusline').new(120, 'tabline')
--- ```
---
--- Now setup the state you want to test.
--- To test you'll call `expect` method on statusline for example.
---
--- ``lua
--- statusline:expect([===[
--- highlights = {
--- 1: lualine_c_inactive = { bg = "#3c3836", fg = "#a89984" }
--- }
--- |{1: [No Name] }
--- {1: }
--- {1: 0:1 }|
---
---]===])
--- ```
---
--- For more flexibility you can match a patten in expect block.
--- ``lua
--- statusline:expect([===[
--- highlights = {
--- 1: lualine_a_tabs_inactive = { bg = "#3c3836", bold = true, fg = "#a89984" }
--- 2: lualine_transitional_lualine_a_tabs_inactive_to_lualine_a_tabs_active = { bg = "#a89984", fg = "#3c3836" }
--- 3: lualine_a_tabs_active = { bg = "#a89984", bold = true, fg = "#282828" }
--- 4: lualine_transitional_lualine_a_tabs_active_to_lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
--- 5: lualine_c_normal = { bg = "#3c3836", fg = "#a89984" }
--- }
--- {MATCH:|{1: %d+ }}
--- {MATCH:{1: %d+ }}
--- {2:}
--- {MATCH:{3: %d+ }}
--- {4:}
--- {MATCH:{5:%s+}|}
---
---]===])
--- ```
---
--- An easy way to create an expect block is to call `snapshot` method
--- on statusline where you'll call expect and run the test. It will print
--- an expect block based on the state of statusline. You can copy it and
--- replace the snapshot call with the expect call.
---
--- ``lua
--- statusline:snapshot()
--- ```
local ffi = require('ffi')
local helpers = require('tests.helpers')
local stub = require('luassert.stub')
local M = {}
ffi.cdef([[
typedef unsigned char char_u;
typedef struct window_S win_T;
extern win_T *curwin;
typedef struct {
char_u *start;
int userhl;
} stl_hlrec_t;
typedef struct {
} StlClickDefinition;
typedef struct {
StlClickDefinition def;
const char *start;
} StlClickRecord;
int build_stl_str_hl(
win_T *wp,
char_u *out,
size_t outlen,
char_u *fmt,
int use_sandbox,
char_u fillchar,
int maxwidth,
stl_hlrec_t **hltab,
StlClickRecord **tabtab
);
]])
local function process_hlrec(hltab, stlbuf, eval_type)
local function default_hl()
if eval_type == 'tabline' then
return "TabLineFill"
elseif eval_type == 'inactive' then
return "StatusLineNC"
else
return "StatusLine"
end
end
local len = #ffi.string(stlbuf)
local hltab_data = hltab[0]
local result = {}
if hltab_data[0].start ~= stlbuf then
table.insert(result, {
group = default_hl(),
start = 0,
})
end
local n = 0
while hltab_data[n].start ~= nil do
local group_name
if hltab_data[n].userhl == 0 then
group_name = default_hl()
elseif hltab_data[n].userhl < 0 then
group_name = vim.fn.synIDattr(-1 * hltab_data[n].userhl, 'name')
else
group_name = string.format('User%d', hltab_data[n].userhl)
end
local hl_pos = { group = group_name }
if n == 0 then
hl_pos.start = hltab_data[n].start - stlbuf
else
hl_pos.start = result[#result].start + result[#result].len
end
if hltab_data[n + 1].start ~= nil then
hl_pos.len = hltab_data[n + 1].start - hltab_data[n].start
else
hl_pos.len = (stlbuf + len) - hltab_data[n].start
end
table.insert(result, hl_pos)
n = n + 1
end
return vim.tbl_filter(function(x)
return x.len ~= 0
end, result)
end
local function gen_stl(stl_fmt, width, eval_type)
local stlbuf = ffi.new('char_u [?]', width + 100)
local fmt = ffi.cast('char_u *', stl_fmt)
local fillchar = ffi.cast('char_u', 0x20)
local hltab = ffi.new('stl_hlrec_t *[1]', ffi.new('stl_hlrec_t *'))
ffi.C.build_stl_str_hl(ffi.C.curwin, stlbuf, width + 100, fmt, 0, fillchar, width, hltab, nil)
return { str = ffi.string(stlbuf), highlights = process_hlrec(hltab, stlbuf, eval_type) }
end
local function eval_stl(stl_expr, width, eval_type)
local stl_buf, hl_list, stl_eval_res
if vim.fn.has('nvim-0.6') == 1 then
stl_eval_res = vim.api.nvim_eval_statusline(
stl_expr,
{ maxwidth = width, highlights = true, fillchar = ' ', use_tabline = (eval_type == 'tabline')}
)
else
stl_eval_res = gen_stl(stl_expr, width, eval_type)
end
stl_buf, hl_list = stl_eval_res.str, stl_eval_res.highlights
local hl_map = {}
local buf = { 'highlights = {' }
local hl_id = 1
for _, hl in ipairs(hl_list) do
local hl_name = hl.group
if not hl_map[hl_name] then
hl_map[hl_name] = require('lualine.utils.utils').extract_highlight_colors(hl_name) or {}
table.insert(
buf,
string.format(' %4d: %s = %s', hl_id, hl_name, vim.inspect(hl_map[hl_name], { newline = ' ', indent = '' }))
)
hl_map[hl_name].id = hl_id
hl_id = hl_id + 1
end
end
table.insert(buf, '}')
local stl = {}
for i = 1, #hl_list do
local start, finish = hl_list[i].start, hl_list[i + 1] and hl_list[i + 1].start or #stl_buf
if start ~= finish then
table.insert(
stl,
string.format('{%d:%s}', hl_map[hl_list[i].group].id, vim.fn.strpart(stl_buf, start, finish - start))
)
end
end
table.insert(buf, '|' .. table.concat(stl, '\n') .. '|')
table.insert(buf, '')
return table.concat(buf, '\n')
end
function M:expect_expr(expect, expr)
expect = helpers.dedent(expect)
local actual = eval_stl(expr, self.width, self.type)
local matched = true
local errmsg = {}
if expect ~= actual then
expect = vim.split(expect, '\n')
actual = vim.split(actual, '\n')
if expect[#expect] == '' then
expect[#expect] = nil
end
if actual[#actual] == '' then
actual[#actual] = nil
end
for i = 1, math.max(#expect, #actual) do
if expect[i] and actual[i] then
local match_pat = expect[i]:match('{MATCH:(.*)}')
if expect[i] == actual[i] or (match_pat and actual[i]:match(match_pat)) then
expect[i] = string.rep(' ', 2) .. expect[i]
actual[i] = string.rep(' ', 2) .. actual[i]
goto loop_end
end
end
matched = false
if expect[i] then
expect[i] = '*' .. string.rep(' ', 1) .. expect[i]
end
if actual[i] then
actual[i] = '*' .. string.rep(' ', 1) .. actual[i]
end
::loop_end::
end
end
if not matched then
table.insert(errmsg, 'Unexpected statusline')
table.insert(errmsg, 'Expected:')
table.insert(errmsg, table.concat(expect, '\n') .. '\n')
table.insert(errmsg, 'Actual:')
table.insert(errmsg, table.concat(actual, '\n'))
end
assert(matched, table.concat(errmsg, '\n'))
end
function M:snapshot_expr(expr)
local type_map = {
active = 'statusline',
inactive = 'inactive_statusline',
tabline = 'tabline',
}
print((type_map[self.type] or 'statusline') .. ':expect([===[')
print(eval_stl(expr, self.width, self.type) .. ']===])')
end
function M:snapshot()
local utils = require('lualine.utils.utils')
stub(utils, 'is_focused')
utils.is_focused.returns(self.type ~= 'inactive')
local expr
if self.type == 'inactive' then
expr = require('lualine').statusline(false)
elseif self.type == 'tabline' then
expr = require('lualine').tabline()
else
expr = require('lualine').statusline(true)
end
self:snapshot_expr(expr)
utils.is_focused:revert()
end
function M:expect(result)
local utils = require('lualine.utils.utils')
stub(utils, 'is_focused')
utils.is_focused.returns(self.type ~= 'inactive')
local expr
if self.type == 'inactive' then
expr = require('lualine').statusline(false)
elseif self.type == 'tabline' then
expr = require('lualine').tabline()
else
expr = require('lualine').statusline(true)
end
self:expect_expr(result, expr)
utils.is_focused:revert()
end
function M.new(_, width, eval_type)
if type(_) ~= 'table' then
eval_type = width
width = _
end
local self = {}
self.width = width or 120
self.type = eval_type
if self.type == nil then
self.type = 'active'
end
return setmetatable(self, {
__index = M,
__call = function(_, ...)
M.new(...)
end,
})
end
return M.new()