2021-09-20 11:46:38 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
|
|
|
-- MIT license, see LICENSE for more details.
|
|
|
|
|
2022-01-02 11:38:39 +00:00
|
|
|
local helpers = require('tests.helpers')
|
2021-05-05 18:04:16 +00:00
|
|
|
|
2021-05-09 21:11:18 +00:00
|
|
|
local eq = assert.are.same
|
2021-05-05 18:04:16 +00:00
|
|
|
local build_component_opts = helpers.build_component_opts
|
2022-03-02 13:37:08 +00:00
|
|
|
local stub = require('luassert.stub')
|
2021-05-05 18:04:16 +00:00
|
|
|
|
|
|
|
describe('Utils', function()
|
2022-01-02 11:38:39 +00:00
|
|
|
local utils = require('lualine.utils.utils')
|
2021-05-05 18:04:16 +00:00
|
|
|
|
|
|
|
it('can retrive highlight groups', function()
|
2021-09-03 18:28:20 +00:00
|
|
|
local hl2 = { fg = '#aabbcc', bg = '#889977', reverse = true }
|
2021-05-05 18:04:16 +00:00
|
|
|
-- handles non existing hl groups
|
2022-01-02 11:38:39 +00:00
|
|
|
eq(utils.extract_highlight_colors('hl2'), nil)
|
2021-05-05 18:04:16 +00:00
|
|
|
-- create highlight
|
2021-09-03 18:28:20 +00:00
|
|
|
vim.cmd(string.format('hi hl2 guifg=%s guibg=%s gui=reverse', hl2.fg, hl2.bg))
|
2022-05-30 14:25:05 +00:00
|
|
|
-- Can retrieve entire highlight table
|
2022-01-02 11:38:39 +00:00
|
|
|
eq(utils.extract_highlight_colors('hl2'), hl2)
|
2022-05-30 14:25:05 +00:00
|
|
|
-- Can retrieve specific parts of highlight
|
2021-05-05 18:04:16 +00:00
|
|
|
eq(utils.extract_highlight_colors('hl2', 'fg'), hl2.fg)
|
|
|
|
-- clear hl2
|
2022-01-02 11:38:39 +00:00
|
|
|
vim.cmd('hi clear hl2')
|
2021-05-05 18:04:16 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can shrink list with holes', function()
|
|
|
|
local list_with_holes = {
|
2021-09-03 18:28:20 +00:00
|
|
|
'2',
|
|
|
|
'4',
|
|
|
|
'6',
|
|
|
|
nil,
|
|
|
|
'43',
|
|
|
|
nil,
|
|
|
|
'2',
|
|
|
|
'',
|
|
|
|
'a',
|
|
|
|
'',
|
|
|
|
'b',
|
|
|
|
' ',
|
2021-05-05 18:04:16 +00:00
|
|
|
}
|
2021-09-03 18:28:20 +00:00
|
|
|
local list_without_holes = { '2', '4', '6', '43', '2', 'a', 'b', ' ' }
|
2021-05-05 18:04:16 +00:00
|
|
|
eq(utils.list_shrink(list_with_holes), list_without_holes)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('Cterm genarator', function()
|
2022-01-02 11:38:39 +00:00
|
|
|
local cterm = require('lualine.utils.color_utils')
|
2021-05-05 18:04:16 +00:00
|
|
|
|
|
|
|
it('can convert rgb to cterm', function()
|
2021-09-03 18:28:20 +00:00
|
|
|
local colors = { ['#112233'] = 235, ['#7928ae'] = 97, ['#017bdc'] = 68 }
|
2021-05-05 18:04:16 +00:00
|
|
|
for rgb, ct in pairs(colors) do
|
2021-08-30 12:07:24 +00:00
|
|
|
eq(cterm.rgb2cterm(rgb), tostring(ct))
|
2021-05-05 18:04:16 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('Section genarator', function()
|
2022-03-02 13:37:08 +00:00
|
|
|
local hl = require('lualine.highlight')
|
|
|
|
stub(hl, 'format_highlight')
|
|
|
|
hl.format_highlight.returns('%#lualine_c_normal#')
|
|
|
|
|
2022-01-02 11:38:39 +00:00
|
|
|
local sec = require('lualine.utils.section')
|
2021-05-05 18:04:16 +00:00
|
|
|
it('can draw', function()
|
2022-02-01 08:04:03 +00:00
|
|
|
local opts = build_component_opts { section_separators = { left = '', right = '' } }
|
2021-05-05 18:04:16 +00:00
|
|
|
local section = {
|
2022-01-02 11:38:39 +00:00
|
|
|
require('lualine.components.special.function_component')(opts),
|
|
|
|
require('lualine.components.special.function_component')(opts),
|
2021-05-05 18:04:16 +00:00
|
|
|
}
|
2022-03-02 13:37:08 +00:00
|
|
|
eq('%#lualine_c_normal# test %#lualine_c_normal# test ', sec.draw_section(section, 'c', true))
|
|
|
|
|
|
|
|
hl.format_highlight:revert()
|
2021-05-05 18:04:16 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can remove separators from component with custom colors', function()
|
2022-03-02 13:37:08 +00:00
|
|
|
stub(hl, 'format_highlight')
|
|
|
|
stub(hl, 'get_lualine_hl')
|
|
|
|
hl.format_highlight.returns('%#lualine_MySection_normal#')
|
|
|
|
hl.get_lualine_hl.returns { fg = '#000000', bg = '#ffffff' }
|
|
|
|
|
|
|
|
vim.g.actual_curwin = tostring(vim.api.nvim_get_current_win())
|
2022-02-01 08:04:03 +00:00
|
|
|
local opts = build_component_opts { section_separators = { left = '', right = '' } }
|
|
|
|
local opts_colored = build_component_opts { color = 'MyColor' }
|
|
|
|
local opts_colored2 = build_component_opts {
|
2021-09-03 18:28:20 +00:00
|
|
|
color = { bg = '#223344' },
|
2021-09-14 15:14:23 +00:00
|
|
|
section_separators = { left = '', right = '' },
|
2022-02-01 08:04:03 +00:00
|
|
|
}
|
|
|
|
local opts_colored3 = build_component_opts {
|
2021-09-03 18:28:20 +00:00
|
|
|
color = { fg = '#223344' },
|
2021-09-14 15:14:23 +00:00
|
|
|
section_separators = { left = '', right = '' },
|
2022-02-01 08:04:03 +00:00
|
|
|
}
|
2022-01-02 11:38:39 +00:00
|
|
|
require('lualine.highlight').create_highlight_groups(require('lualine.themes.gruvbox'))
|
2021-05-05 18:04:16 +00:00
|
|
|
local section = {
|
2022-01-02 11:38:39 +00:00
|
|
|
require('lualine.components.special.function_component')(opts),
|
|
|
|
require('lualine.components.special.function_component')(opts_colored),
|
|
|
|
require('lualine.components.special.function_component')(opts),
|
2021-05-05 18:04:16 +00:00
|
|
|
}
|
2022-03-02 13:37:08 +00:00
|
|
|
local highlight_name2 = 'lualine_c_' .. section[2].options.component_name
|
2021-05-05 18:04:16 +00:00
|
|
|
-- Removes separator on string color
|
2021-09-03 18:28:20 +00:00
|
|
|
eq(
|
|
|
|
'%#lualine_MySection_normal# test %#' .. highlight_name2 .. '#' .. ' test %#lualine_MySection_normal# test ',
|
|
|
|
sec.draw_section(section, 'MySection')
|
|
|
|
)
|
2022-03-02 13:37:08 +00:00
|
|
|
section[2] = require('lualine.components.special.function_component')(opts_colored2)
|
2021-09-03 18:28:20 +00:00
|
|
|
local highlight_name = '%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
2021-05-05 18:04:16 +00:00
|
|
|
-- Removes separator on color with bg
|
2021-09-03 18:28:20 +00:00
|
|
|
eq(
|
|
|
|
'%#lualine_MySection_normal# test ' .. highlight_name .. ' test %#lualine_MySection_normal# test ',
|
|
|
|
sec.draw_section(section, 'MySection')
|
|
|
|
)
|
2022-03-02 13:37:08 +00:00
|
|
|
section[2] = require('lualine.components.special.function_component')(opts_colored3)
|
2021-09-03 18:28:20 +00:00
|
|
|
highlight_name2 = '%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
2021-05-05 18:04:16 +00:00
|
|
|
-- Doesn't remove separator on color without bg
|
2021-09-03 18:28:20 +00:00
|
|
|
eq(
|
|
|
|
'%#lualine_MySection_normal# test '
|
|
|
|
.. highlight_name2
|
|
|
|
.. ' test %#lualine_MySection_normal#%#lualine_MySection_normal# test ',
|
|
|
|
sec.draw_section(section, 'MySection')
|
|
|
|
)
|
2022-03-02 13:37:08 +00:00
|
|
|
vim.g.actual_curwin = nil
|
|
|
|
|
|
|
|
hl.format_highlight:revert()
|
|
|
|
hl.get_lualine_hl:revert()
|
2021-05-05 18:04:16 +00:00
|
|
|
end)
|
|
|
|
end)
|