refactor: moved loading to new module (#182)
* refactor: moved loading to new module * refactor: check_single_separator * refactor: simplified separator fixing * refactor: tests/ -> lua/tests/ * refactor: moved to nvim_err_writeln for errors * feat: moved config parsing to config.lua * feat: get config directly from config module * feat: added load_all function * tests: config parsing tests * added assert to luacheck globals
This commit is contained in:
parent
dc2c711a53
commit
82826ef661
|
@ -44,4 +44,3 @@ tags
|
|||
|
||||
# helptags
|
||||
doc/tags
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
globals = {
|
||||
"vim",
|
||||
"vimp",
|
||||
"assert"
|
||||
}
|
||||
|
|
6
Makefile
6
Makefile
|
@ -2,12 +2,12 @@
|
|||
|
||||
lint:
|
||||
@luacheck lua/lualine
|
||||
@luacheck tests
|
||||
@luacheck lua/tests
|
||||
|
||||
format:
|
||||
@for file in `find -name '*.lua'`;do lua-format $$file -i; done;
|
||||
@for file in `find . -name '*.lua'`;do lua-format $$file -i; done;
|
||||
|
||||
test:
|
||||
@nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = './tests/minimal_init.lua' }"
|
||||
@nvim --headless -u lua/tests/minimal_init.lua -c "PlenaryBustedDirectory lua/tests/ { minimal_init = './lua/tests/minimal_init.lua' }"
|
||||
|
||||
check: lint test
|
||||
|
|
|
@ -5,8 +5,9 @@ local FileName = require('lualine.component'):new()
|
|||
FileName.new = function(self, options, child)
|
||||
local new_instance = self._parent:new(options, child or FileName)
|
||||
local default_symbols = {modified = '[+]', readonly = '[-]'}
|
||||
new_instance.options.symbols =
|
||||
vim.tbl_extend('force', default_symbols, new_instance.options.symbols or {})
|
||||
new_instance.options.symbols = vim.tbl_extend('force', default_symbols,
|
||||
new_instance.options.symbols or
|
||||
{})
|
||||
|
||||
-- setting defaults
|
||||
if new_instance.options.file_status == nil then
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local config = {
|
||||
options = {
|
||||
icons_enabled = true,
|
||||
theme = 'gruvbox',
|
||||
component_separators = {'', ''},
|
||||
section_separators = {'', ''},
|
||||
disabled_filetypes = {}
|
||||
},
|
||||
sections = {
|
||||
lualine_a = {'mode'},
|
||||
lualine_b = {'branch'},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {'encoding', 'fileformat', 'filetype'},
|
||||
lualine_y = {'progress'},
|
||||
lualine_z = {'location'}
|
||||
},
|
||||
inactive_sections = {
|
||||
lualine_a = {},
|
||||
lualine_b = {},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {'location'},
|
||||
lualine_y = {},
|
||||
lualine_z = {}
|
||||
},
|
||||
tabline = {},
|
||||
extensions = {}
|
||||
}
|
||||
|
||||
-- change separator format 'x' or {'x'} to {'x', 'x'}
|
||||
local function fix_separators(separators)
|
||||
if separators ~= nil then
|
||||
if type(separators) == 'string' then
|
||||
return {separators, separators}
|
||||
elseif type(separators) == 'table' and #separators == 1 then
|
||||
return {separators[1], separators[1]}
|
||||
end
|
||||
end
|
||||
return separators
|
||||
end
|
||||
|
||||
local function apply_configuration(config_table)
|
||||
local function parse_sections(section_group_name)
|
||||
if not config_table[section_group_name] then return end
|
||||
for section_name, section in pairs(config_table[section_group_name]) do
|
||||
config[section_group_name][section_name] =
|
||||
config_table[section_group_name][section_name]
|
||||
if type(section) == 'table' then
|
||||
for _, component in pairs(section) do
|
||||
if type(component) == 'table' and type(component[2]) == 'table' then
|
||||
local options = component[2]
|
||||
component[2] = nil
|
||||
for key, val in pairs(options) do component[key] = val end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
parse_sections('options')
|
||||
parse_sections('sections')
|
||||
parse_sections('inactive_sections')
|
||||
parse_sections('tabline')
|
||||
if config_table.extensions then config.extensions = config_table.extensions end
|
||||
config.options.section_separators = fix_separators(
|
||||
config.options.section_separators)
|
||||
config.options.component_separators = fix_separators(
|
||||
config.options.component_separators)
|
||||
end
|
||||
|
||||
return {config = config, apply_configuration = apply_configuration}
|
|
@ -1,33 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
M.options = {
|
||||
icons_enabled = true,
|
||||
theme = 'gruvbox',
|
||||
component_separators = {'', ''},
|
||||
section_separators = {'', ''},
|
||||
disabled_filetypes = {},
|
||||
}
|
||||
|
||||
M.sections = {
|
||||
lualine_a = {'mode'},
|
||||
lualine_b = {'branch'},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {'encoding', 'fileformat', 'filetype'},
|
||||
lualine_y = {'progress'},
|
||||
lualine_z = {'location'}
|
||||
}
|
||||
|
||||
M.inactive_sections = {
|
||||
lualine_a = {},
|
||||
lualine_b = {},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {'location'},
|
||||
lualine_y = {},
|
||||
lualine_z = {}
|
||||
}
|
||||
|
||||
M.tabline = {}
|
||||
|
||||
M.extensions = {}
|
||||
|
||||
return M
|
|
@ -1,118 +1,11 @@
|
|||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local utils_section = require('lualine.utils.section')
|
||||
local highlight = require('lualine.highlight')
|
||||
local config = {}
|
||||
local loader = require('lualine.utils.loader')
|
||||
local utils_section = require('lualine.utils.section')
|
||||
local config_module = require('lualine.config')
|
||||
|
||||
local function apply_configuration(config_table)
|
||||
local function parse_sections(section_group_name)
|
||||
if not config_table[section_group_name] then return end
|
||||
for section_name, section in pairs(config_table[section_group_name]) do
|
||||
config[section_group_name][section_name] =
|
||||
config_table[section_group_name][section_name]
|
||||
if type(section) == 'table' then
|
||||
for _, component in pairs(section) do
|
||||
if type(component) == 'table' and type(component[2]) == 'table' then
|
||||
local options = component[2]
|
||||
component[2] = nil
|
||||
for key, val in pairs(options) do component[key] = val end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
parse_sections('options')
|
||||
parse_sections('sections')
|
||||
parse_sections('inactive_sections')
|
||||
parse_sections('tabline')
|
||||
if config_table.extensions then config.extensions = config_table.extensions end
|
||||
end
|
||||
|
||||
local function check_single_separator()
|
||||
local compoennt_separator = config.options.component_separators
|
||||
local section_separator = config.options.section_separators
|
||||
if config.options.component_separators ~= nil then
|
||||
if type(config.options.component_separators) == 'string' then
|
||||
config.options.component_separators =
|
||||
{compoennt_separator, compoennt_separator}
|
||||
elseif #config.options.component_separators == 1 then
|
||||
config.options.component_separators =
|
||||
{
|
||||
config.options.component_separators[1],
|
||||
config.options.component_separators[1]
|
||||
}
|
||||
end
|
||||
end
|
||||
if config.options.section_separators ~= nil then
|
||||
if type(config.options.section_separators) == 'string' then
|
||||
config.options.section_separators = {section_separator, section_separator}
|
||||
elseif #config.options.section_separators == 1 then
|
||||
config.options.section_separators =
|
||||
{
|
||||
config.options.section_separators[1],
|
||||
config.options.section_separators[1]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function component_loader(component)
|
||||
if type(component[1]) == 'function' then
|
||||
return
|
||||
require 'lualine.components.special.function_component':new(component)
|
||||
end
|
||||
if type(component[1]) == 'string' then
|
||||
-- load the component
|
||||
local ok, loaded_component = pcall(require,
|
||||
'lualine.components.' .. component[1])
|
||||
if ok then
|
||||
component.component_name = component[1]
|
||||
loaded_component = loaded_component:new(component)
|
||||
elseif component[1]:find('[gvtwb]?o?:') == 1 then
|
||||
loaded_component =
|
||||
require 'lualine.components.special.vim_var_component':new(component)
|
||||
else
|
||||
loaded_component =
|
||||
require 'lualine.components.special.eval_func_component':new(component)
|
||||
end
|
||||
return loaded_component
|
||||
end
|
||||
end
|
||||
|
||||
local function load_sections(sections)
|
||||
local async_loader
|
||||
async_loader = vim.loop.new_async(vim.schedule_wrap(function()
|
||||
for section_name, section in pairs(sections) do
|
||||
for index, component in pairs(section) do
|
||||
if type(component) == 'string' or type(component) == 'function' then
|
||||
component = {component}
|
||||
end
|
||||
component.self = {}
|
||||
component.self.section = section_name
|
||||
-- apply default args
|
||||
component = vim.tbl_extend('keep', component, config.options)
|
||||
section[index] = component_loader(component)
|
||||
end
|
||||
end
|
||||
async_loader:close()
|
||||
end))
|
||||
async_loader:send()
|
||||
end
|
||||
|
||||
local function load_components()
|
||||
load_sections(config.sections)
|
||||
load_sections(config.inactive_sections)
|
||||
load_sections(config.tabline)
|
||||
end
|
||||
|
||||
local function load_extensions()
|
||||
for index, extension in pairs(config.extensions) do
|
||||
local local_extension = require('lualine.extensions.' .. extension)
|
||||
load_sections(local_extension.sections)
|
||||
load_sections(local_extension.inactive_sections)
|
||||
config.extensions[index] = local_extension
|
||||
end
|
||||
end
|
||||
local config = config_module.config
|
||||
|
||||
local function statusline(sections, is_focused)
|
||||
local function create_status_builder()
|
||||
|
@ -239,7 +132,8 @@ local function tabline() return statusline(config.tabline, true) end
|
|||
|
||||
local function setup_theme()
|
||||
local async_loader
|
||||
async_loader = vim.loop.new_async(vim.schedule_wrap(function()
|
||||
async_loader = vim.loop.new_async(vim.schedule_wrap(
|
||||
function()
|
||||
local function get_theme_from_config()
|
||||
local theme_name = config.options.theme
|
||||
if type(theme_name) == 'string' then
|
||||
|
@ -249,12 +143,8 @@ local function setup_theme()
|
|||
-- use the provided theme as-is
|
||||
return config.options.theme
|
||||
end
|
||||
vim.api.nvim_echo({
|
||||
{
|
||||
'theme ' .. tostring(theme_name) .. ' not found, defaulting to gruvbox',
|
||||
'ErrorMsg'
|
||||
}
|
||||
}, true, {})
|
||||
vim.api.nvim_err_writeln('theme ' .. tostring(theme_name) ..
|
||||
' not found, defaulting to gruvbox')
|
||||
return require 'lualine.themes.gruvbox'
|
||||
end
|
||||
local theme = get_theme_from_config()
|
||||
|
@ -290,13 +180,13 @@ local function set_statusline()
|
|||
end
|
||||
|
||||
local function setup(user_config)
|
||||
config = vim.deepcopy(require'lualine.defaults')
|
||||
if user_config then apply_configuration(user_config)
|
||||
elseif vim.g.lualine then apply_configuration(vim.g.lualine) end
|
||||
check_single_separator()
|
||||
if user_config then
|
||||
config_module.apply_configuration(user_config)
|
||||
elseif vim.g.lualine then
|
||||
config_module.apply_configuration(vim.g.lualine)
|
||||
end
|
||||
setup_theme()
|
||||
load_components()
|
||||
load_extensions()
|
||||
loader.load_all(config)
|
||||
set_statusline()
|
||||
set_tabline()
|
||||
end
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local function component_loader(component)
|
||||
if type(component[1]) == 'function' then
|
||||
return
|
||||
require 'lualine.components.special.function_component':new(component)
|
||||
end
|
||||
if type(component[1]) == 'string' then
|
||||
-- load the component
|
||||
local ok, loaded_component = pcall(require,
|
||||
'lualine.components.' .. component[1])
|
||||
if ok then
|
||||
component.component_name = component[1]
|
||||
loaded_component = loaded_component:new(component)
|
||||
elseif component[1]:find('[gvtwb]?o?:') == 1 then
|
||||
loaded_component =
|
||||
require 'lualine.components.special.vim_var_component':new(component)
|
||||
else
|
||||
loaded_component =
|
||||
require 'lualine.components.special.eval_func_component':new(component)
|
||||
end
|
||||
return loaded_component
|
||||
end
|
||||
end
|
||||
|
||||
local function load_sections(sections, options)
|
||||
local async_loader
|
||||
async_loader = vim.loop.new_async(vim.schedule_wrap(
|
||||
function()
|
||||
for section_name, section in pairs(sections) do
|
||||
for index, component in pairs(section) do
|
||||
if type(component) == 'string' or type(component) == 'function' then
|
||||
component = {component}
|
||||
end
|
||||
component.self = {}
|
||||
component.self.section = section_name
|
||||
-- apply default args
|
||||
component = vim.tbl_extend('keep', component, options)
|
||||
section[index] = component_loader(component)
|
||||
end
|
||||
end
|
||||
async_loader:close()
|
||||
end))
|
||||
async_loader:send()
|
||||
end
|
||||
|
||||
local function load_components(config)
|
||||
load_sections(config.sections, config.options)
|
||||
load_sections(config.inactive_sections, config.options)
|
||||
load_sections(config.tabline, config.options)
|
||||
end
|
||||
|
||||
local function load_extensions(config)
|
||||
for index, extension in pairs(config.extensions) do
|
||||
local local_extension = require('lualine.extensions.' .. extension)
|
||||
load_sections(local_extension.sections, config.options)
|
||||
load_sections(local_extension.inactive_sections, config.options)
|
||||
config.extensions[index] = local_extension
|
||||
end
|
||||
end
|
||||
|
||||
local function load_all(config)
|
||||
load_components(config)
|
||||
load_extensions(config)
|
||||
end
|
||||
|
||||
return {load_all = load_all}
|
|
@ -1,9 +1,7 @@
|
|||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
-- LuaFormatter off
|
||||
|
||||
local Mode = {}
|
||||
|
||||
-- LuaFormatter off
|
||||
Mode.map = {
|
||||
['n'] = 'NORMAL',
|
||||
['no'] = 'O-PENDING',
|
||||
|
|
|
@ -7,7 +7,8 @@ function M.draw_section(section, highlight_name)
|
|||
local status = {}
|
||||
for _, component in pairs(section) do
|
||||
-- load components into status table
|
||||
if type(component) ~= 'table' or (type(component) == 'table' and not component.component_no) then
|
||||
if type(component) ~= 'table' or
|
||||
(type(component) == 'table' and not component.component_no) then
|
||||
return '' -- unknown element in section. section posibly not yet loaded
|
||||
end
|
||||
table.insert(status, component:draw(highlight_name))
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
local luassert = require 'luassert'
|
||||
local eq = assert.are.same
|
||||
|
||||
local M = {}
|
||||
|
||||
M.eq = luassert.are.same
|
||||
M.neq = luassert.are_not.same
|
||||
M.meths = setmetatable({}, {
|
||||
__index = function(_, key) return vim.api['nvim_' .. key] end
|
||||
})
|
||||
|
@ -12,7 +11,7 @@ M.assert_component = function(component, opts, result)
|
|||
-- for testing global options
|
||||
if component == nil then component = 'special.function_component' end
|
||||
local comp = require('lualine.components.' .. component):new(opts)
|
||||
M.eq(result, comp:draw(opts.hl))
|
||||
eq(result, comp:draw(opts.hl))
|
||||
end
|
||||
|
||||
-- sets defaults for component options
|
|
@ -1,7 +1,7 @@
|
|||
local helpers = require 'tests.helpers'
|
||||
|
||||
local eq = helpers.eq
|
||||
local neq = helpers.neq
|
||||
local eq = assert.are.same
|
||||
local neq = assert.are_not.same
|
||||
local assert_component = helpers.assert_component
|
||||
local build_component_opts = helpers.build_component_opts
|
||||
local stub = require 'luassert.stub'
|
||||
|
@ -9,24 +9,24 @@ local stub = require 'luassert.stub'
|
|||
describe('Component:', function()
|
||||
it('can select separators', function()
|
||||
local opts = build_component_opts()
|
||||
local comp =
|
||||
require('lua.lualine.components.special.function_component'):new(opts)
|
||||
local comp = require('lualine.components.special.function_component'):new(
|
||||
opts)
|
||||
-- correct for lualine_c
|
||||
eq('', comp.options.separator)
|
||||
local opts2 = build_component_opts({self = {section = 'lualine_y'}})
|
||||
local comp2 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
||||
local comp2 = require('lualine.components.special.function_component'):new(
|
||||
opts2)
|
||||
-- correct for lualine_u
|
||||
eq('', comp2.options.separator)
|
||||
end)
|
||||
|
||||
it('can provide unique identifier', function()
|
||||
local opts1 = build_component_opts()
|
||||
local comp1 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts1)
|
||||
local comp1 = require('lualine.components.special.function_component'):new(
|
||||
opts1)
|
||||
local opts2 = build_component_opts()
|
||||
local comp2 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
||||
local comp2 = require('lualine.components.special.function_component'):new(
|
||||
opts2)
|
||||
neq(comp1.component_no, comp2.component_no)
|
||||
end)
|
||||
|
||||
|
@ -36,8 +36,8 @@ describe('Component:', function()
|
|||
local hl = require 'lualine.highlight'
|
||||
stub(hl, 'create_component_highlight_group')
|
||||
hl.create_component_highlight_group.returns('MyCompHl')
|
||||
local comp1 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts1)
|
||||
local comp1 = require('lualine.components.special.function_component'):new(
|
||||
opts1)
|
||||
eq('MyCompHl', comp1.options.color_highlight)
|
||||
-- color highlight wan't in options when create_comp_hl was
|
||||
-- called so remove it before assert
|
||||
|
@ -48,8 +48,8 @@ describe('Component:', function()
|
|||
comp1.options)
|
||||
hl.create_component_highlight_group:revert()
|
||||
local opts2 = build_component_opts({color = 'MyHl'})
|
||||
local comp2 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
||||
local comp2 = require('lualine.components.special.function_component'):new(
|
||||
opts2)
|
||||
eq('MyHl', comp2.options.color_highlight_link)
|
||||
end)
|
||||
|
||||
|
@ -197,7 +197,7 @@ describe('Component:', function()
|
|||
stub(hl, 'component_format_highlight')
|
||||
hl.component_format_highlight.returns('%#MyCompHl#')
|
||||
local comp2 =
|
||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
||||
require('lualine.components.special.function_component'):new(opts2)
|
||||
assert_component(nil, opts2, '%#MyCompHl#test')
|
||||
assert.stub(hl.component_format_highlight).was_called_with(
|
||||
comp2.options.color_highlight)
|
|
@ -0,0 +1,179 @@
|
|||
local eq = assert.are.same
|
||||
|
||||
describe('config parsing', function()
|
||||
local config_module = require 'lualine.config'
|
||||
|
||||
describe('options', function()
|
||||
describe('icons_enabled', function()
|
||||
it('default', function()
|
||||
config_module.apply_configuration({})
|
||||
eq(config_module.config.options.icons_enabled, true)
|
||||
end)
|
||||
it('custom', function()
|
||||
local config = {options = {icons_enabled = false}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.icons_enabled, false)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('theme', function()
|
||||
it('default', function()
|
||||
config_module.apply_configuration({})
|
||||
eq(config_module.config.options.theme, 'gruvbox')
|
||||
end)
|
||||
it('custom', function()
|
||||
local config = {options = {theme = 'nord'}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.theme, 'nord')
|
||||
config = {options = {theme = {}}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.theme, {})
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('separators', function()
|
||||
it('default', function()
|
||||
config_module.apply_configuration({})
|
||||
eq(config_module.config.options.component_separators, {'', ''})
|
||||
eq(config_module.config.options.section_separators, {'', ''})
|
||||
end)
|
||||
it('double separators', function()
|
||||
local config = {
|
||||
options = {
|
||||
component_separators = {'a', 'b'},
|
||||
section_separators = {'c', 'd'}
|
||||
}
|
||||
}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.component_separators, {'a', 'b'})
|
||||
eq(config_module.config.options.section_separators, {'c', 'd'})
|
||||
end)
|
||||
|
||||
describe('single separator', function()
|
||||
it('string', function()
|
||||
local config = {
|
||||
options = {component_separators = 'a', section_separators = 'b'}
|
||||
}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.component_separators, {'a', 'a'})
|
||||
eq(config_module.config.options.section_separators, {'b', 'b'})
|
||||
end)
|
||||
it('table', function()
|
||||
local config = {
|
||||
options = {component_separators = {'a'}, section_separators = {'b'}}
|
||||
}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.component_separators, {'a', 'a'})
|
||||
eq(config_module.config.options.section_separators, {'b', 'b'})
|
||||
end)
|
||||
end)
|
||||
it('no seprarators', function()
|
||||
local config = {
|
||||
options = {component_separators = {}, section_separators = {}}
|
||||
}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.component_separators, {})
|
||||
eq(config_module.config.options.section_separators, {})
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('disabled filetypes', function()
|
||||
it('default', function()
|
||||
config_module.apply_configuration({})
|
||||
eq(config_module.config.options.disabled_filetypes, {})
|
||||
end)
|
||||
it('custom', function()
|
||||
local config = {options = {disabled_filetypes = {'lua'}}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.disabled_filetypes, {'lua'})
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('non default global option', function()
|
||||
it('default', function()
|
||||
local config = {options = {}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.non_default_global_option, nil)
|
||||
end)
|
||||
it('custom', function()
|
||||
local config = {options = {non_default_global_option = 1}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.options.non_default_global_option, 1)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('sections', function()
|
||||
it('default', function()
|
||||
local config = {}
|
||||
config_module.apply_configuration(config)
|
||||
local lualine_default_sections = {
|
||||
lualine_a = {'mode'},
|
||||
lualine_b = {'branch'},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {'encoding', 'fileformat', 'filetype'},
|
||||
lualine_y = {'progress'},
|
||||
lualine_z = {'location'}
|
||||
}
|
||||
eq(config_module.config.sections, lualine_default_sections)
|
||||
end)
|
||||
it('custom', function()
|
||||
local custom_sections = {
|
||||
lualine_a = {{'mode', lower = true}},
|
||||
lualine_b = {'branch', {'branch', lower = true}},
|
||||
lualine_c = nil,
|
||||
lualine_x = {}
|
||||
}
|
||||
local expected_sections = {
|
||||
lualine_a = {{'mode', lower = true}},
|
||||
lualine_b = {'branch', {'branch', lower = true}},
|
||||
lualine_c = {'filename'},
|
||||
lualine_x = {},
|
||||
lualine_y = {'progress'},
|
||||
lualine_z = {'location'}
|
||||
}
|
||||
local config = {sections = custom_sections}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.sections, expected_sections)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('inactive_sections', function() end)
|
||||
|
||||
describe('tabline', function()
|
||||
it('default', function()
|
||||
local config = {}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.tabline, {})
|
||||
end)
|
||||
it('custom', function()
|
||||
local custom_sections = {
|
||||
lualine_a = {{'mode', lower = true}},
|
||||
lualine_b = {'branch', {'branch', lower = true}},
|
||||
lualine_c = nil,
|
||||
lualine_x = {}
|
||||
}
|
||||
local expected_sections = {
|
||||
lualine_a = {{'mode', lower = true}},
|
||||
lualine_b = {'branch', {'branch', lower = true}},
|
||||
lualine_x = {}
|
||||
}
|
||||
local config = {tabline = custom_sections}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.tabline, expected_sections)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('extensions', function()
|
||||
it('default', function()
|
||||
local config = {options = {}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.extensions, {})
|
||||
end)
|
||||
it('custom', function()
|
||||
local config = {extensions = {'fugitive'}}
|
||||
config_module.apply_configuration(config)
|
||||
eq(config_module.config.extensions, {'fugitive'})
|
||||
end)
|
||||
end)
|
||||
end)
|
|
@ -1,6 +1,6 @@
|
|||
local helpers = require 'tests.helpers'
|
||||
|
||||
local eq = helpers.eq
|
||||
local eq = assert.are.same
|
||||
local meths = helpers.meths
|
||||
local build_component_opts = helpers.build_component_opts
|
||||
|
||||
|
@ -73,8 +73,8 @@ describe('Section genarator', function()
|
|||
it('can draw', function()
|
||||
local opts = build_component_opts()
|
||||
local section = {
|
||||
require('lua.lualine.components.special.function_component'):new(opts),
|
||||
require('lua.lualine.components.special.function_component'):new(opts)
|
||||
require('lualine.components.special.function_component'):new(opts),
|
||||
require('lualine.components.special.function_component'):new(opts)
|
||||
}
|
||||
eq('%#MyHl# test %#MyHl# test ', sec.draw_section(section, '%#MyHl#'))
|
||||
end)
|
||||
|
@ -87,24 +87,21 @@ describe('Section genarator', function()
|
|||
require'lualine.highlight'.create_highlight_groups(
|
||||
require 'lualine.themes.gruvbox')
|
||||
local section = {
|
||||
require('lua.lualine.components.special.function_component'):new(opts),
|
||||
require('lua.lualine.components.special.function_component'):new(
|
||||
opts_colored),
|
||||
require('lua.lualine.components.special.function_component'):new(opts)
|
||||
require('lualine.components.special.function_component'):new(opts),
|
||||
require('lualine.components.special.function_component'):new(opts_colored),
|
||||
require('lualine.components.special.function_component'):new(opts)
|
||||
}
|
||||
-- Removes separator on string color
|
||||
eq('%#MyHl# test %#MyHl#%#MyColor# test %#MyHl# test ',
|
||||
sec.draw_section(section, '%#MyHl#'))
|
||||
section[2] =
|
||||
require('lua.lualine.components.special.function_component'):new(
|
||||
section[2] = require('lualine.components.special.function_component'):new(
|
||||
opts_colored2)
|
||||
local highlight_name =
|
||||
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
||||
-- Removes separator on color with bg
|
||||
eq('%#MyHl# test %#MyHl#' .. highlight_name .. ' test %#MyHl# test ',
|
||||
sec.draw_section(section, '%#MyHl#'))
|
||||
section[2] =
|
||||
require('lua.lualine.components.special.function_component'):new(
|
||||
section[2] = require('lualine.components.special.function_component'):new(
|
||||
opts_colored3)
|
||||
local highlight_name2 =
|
||||
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
Loading…
Reference in New Issue