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
|
# helptags
|
||||||
doc/tags
|
doc/tags
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
globals = {
|
globals = {
|
||||||
"vim",
|
"vim",
|
||||||
"vimp",
|
"vimp",
|
||||||
|
"assert"
|
||||||
}
|
}
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@luacheck lua/lualine
|
@luacheck lua/lualine
|
||||||
@luacheck tests
|
@luacheck lua/tests
|
||||||
|
|
||||||
format:
|
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:
|
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
|
check: lint test
|
||||||
|
|
|
@ -5,8 +5,9 @@ local FileName = require('lualine.component'):new()
|
||||||
FileName.new = function(self, options, child)
|
FileName.new = function(self, options, child)
|
||||||
local new_instance = self._parent:new(options, child or FileName)
|
local new_instance = self._parent:new(options, child or FileName)
|
||||||
local default_symbols = {modified = '[+]', readonly = '[-]'}
|
local default_symbols = {modified = '[+]', readonly = '[-]'}
|
||||||
new_instance.options.symbols =
|
new_instance.options.symbols = vim.tbl_extend('force', default_symbols,
|
||||||
vim.tbl_extend('force', default_symbols, new_instance.options.symbols or {})
|
new_instance.options.symbols or
|
||||||
|
{})
|
||||||
|
|
||||||
-- setting defaults
|
-- setting defaults
|
||||||
if new_instance.options.file_status == nil then
|
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
|
-- Copyright (c) 2020-2021 hoob3rt
|
||||||
-- MIT license, see LICENSE for more details.
|
-- MIT license, see LICENSE for more details.
|
||||||
local utils_section = require('lualine.utils.section')
|
|
||||||
local highlight = require('lualine.highlight')
|
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 config = config_module.config
|
||||||
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 function statusline(sections, is_focused)
|
local function statusline(sections, is_focused)
|
||||||
local function create_status_builder()
|
local function create_status_builder()
|
||||||
|
@ -239,7 +132,8 @@ local function tabline() return statusline(config.tabline, true) end
|
||||||
|
|
||||||
local function setup_theme()
|
local function setup_theme()
|
||||||
local async_loader
|
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 function get_theme_from_config()
|
||||||
local theme_name = config.options.theme
|
local theme_name = config.options.theme
|
||||||
if type(theme_name) == 'string' then
|
if type(theme_name) == 'string' then
|
||||||
|
@ -249,12 +143,8 @@ local function setup_theme()
|
||||||
-- use the provided theme as-is
|
-- use the provided theme as-is
|
||||||
return config.options.theme
|
return config.options.theme
|
||||||
end
|
end
|
||||||
vim.api.nvim_echo({
|
vim.api.nvim_err_writeln('theme ' .. tostring(theme_name) ..
|
||||||
{
|
' not found, defaulting to gruvbox')
|
||||||
'theme ' .. tostring(theme_name) .. ' not found, defaulting to gruvbox',
|
|
||||||
'ErrorMsg'
|
|
||||||
}
|
|
||||||
}, true, {})
|
|
||||||
return require 'lualine.themes.gruvbox'
|
return require 'lualine.themes.gruvbox'
|
||||||
end
|
end
|
||||||
local theme = get_theme_from_config()
|
local theme = get_theme_from_config()
|
||||||
|
@ -290,13 +180,13 @@ local function set_statusline()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup(user_config)
|
local function setup(user_config)
|
||||||
config = vim.deepcopy(require'lualine.defaults')
|
if user_config then
|
||||||
if user_config then apply_configuration(user_config)
|
config_module.apply_configuration(user_config)
|
||||||
elseif vim.g.lualine then apply_configuration(vim.g.lualine) end
|
elseif vim.g.lualine then
|
||||||
check_single_separator()
|
config_module.apply_configuration(vim.g.lualine)
|
||||||
|
end
|
||||||
setup_theme()
|
setup_theme()
|
||||||
load_components()
|
loader.load_all(config)
|
||||||
load_extensions()
|
|
||||||
set_statusline()
|
set_statusline()
|
||||||
set_tabline()
|
set_tabline()
|
||||||
end
|
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
|
-- Copyright (c) 2020-2021 hoob3rt
|
||||||
-- MIT license, see LICENSE for more details.
|
-- MIT license, see LICENSE for more details.
|
||||||
-- LuaFormatter off
|
|
||||||
|
|
||||||
local Mode = {}
|
local Mode = {}
|
||||||
|
-- LuaFormatter off
|
||||||
Mode.map = {
|
Mode.map = {
|
||||||
['n'] = 'NORMAL',
|
['n'] = 'NORMAL',
|
||||||
['no'] = 'O-PENDING',
|
['no'] = 'O-PENDING',
|
||||||
|
|
|
@ -7,7 +7,8 @@ function M.draw_section(section, highlight_name)
|
||||||
local status = {}
|
local status = {}
|
||||||
for _, component in pairs(section) do
|
for _, component in pairs(section) do
|
||||||
-- load components into status table
|
-- 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
|
return '' -- unknown element in section. section posibly not yet loaded
|
||||||
end
|
end
|
||||||
table.insert(status, component:draw(highlight_name))
|
table.insert(status, component:draw(highlight_name))
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
local luassert = require 'luassert'
|
local eq = assert.are.same
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.eq = luassert.are.same
|
|
||||||
M.neq = luassert.are_not.same
|
|
||||||
M.meths = setmetatable({}, {
|
M.meths = setmetatable({}, {
|
||||||
__index = function(_, key) return vim.api['nvim_' .. key] end
|
__index = function(_, key) return vim.api['nvim_' .. key] end
|
||||||
})
|
})
|
||||||
|
@ -12,7 +11,7 @@ M.assert_component = function(component, opts, result)
|
||||||
-- for testing global options
|
-- for testing global options
|
||||||
if component == nil then component = 'special.function_component' end
|
if component == nil then component = 'special.function_component' end
|
||||||
local comp = require('lualine.components.' .. component):new(opts)
|
local comp = require('lualine.components.' .. component):new(opts)
|
||||||
M.eq(result, comp:draw(opts.hl))
|
eq(result, comp:draw(opts.hl))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sets defaults for component options
|
-- sets defaults for component options
|
|
@ -1,7 +1,7 @@
|
||||||
local helpers = require 'tests.helpers'
|
local helpers = require 'tests.helpers'
|
||||||
|
|
||||||
local eq = helpers.eq
|
local eq = assert.are.same
|
||||||
local neq = helpers.neq
|
local neq = assert.are_not.same
|
||||||
local assert_component = helpers.assert_component
|
local assert_component = helpers.assert_component
|
||||||
local build_component_opts = helpers.build_component_opts
|
local build_component_opts = helpers.build_component_opts
|
||||||
local stub = require 'luassert.stub'
|
local stub = require 'luassert.stub'
|
||||||
|
@ -9,24 +9,24 @@ local stub = require 'luassert.stub'
|
||||||
describe('Component:', function()
|
describe('Component:', function()
|
||||||
it('can select separators', function()
|
it('can select separators', function()
|
||||||
local opts = build_component_opts()
|
local opts = build_component_opts()
|
||||||
local comp =
|
local comp = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts)
|
opts)
|
||||||
-- correct for lualine_c
|
-- correct for lualine_c
|
||||||
eq('', comp.options.separator)
|
eq('', comp.options.separator)
|
||||||
local opts2 = build_component_opts({self = {section = 'lualine_y'}})
|
local opts2 = build_component_opts({self = {section = 'lualine_y'}})
|
||||||
local comp2 =
|
local comp2 = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
opts2)
|
||||||
-- correct for lualine_u
|
-- correct for lualine_u
|
||||||
eq('', comp2.options.separator)
|
eq('', comp2.options.separator)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can provide unique identifier', function()
|
it('can provide unique identifier', function()
|
||||||
local opts1 = build_component_opts()
|
local opts1 = build_component_opts()
|
||||||
local comp1 =
|
local comp1 = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts1)
|
opts1)
|
||||||
local opts2 = build_component_opts()
|
local opts2 = build_component_opts()
|
||||||
local comp2 =
|
local comp2 = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
opts2)
|
||||||
neq(comp1.component_no, comp2.component_no)
|
neq(comp1.component_no, comp2.component_no)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ describe('Component:', function()
|
||||||
local hl = require 'lualine.highlight'
|
local hl = require 'lualine.highlight'
|
||||||
stub(hl, 'create_component_highlight_group')
|
stub(hl, 'create_component_highlight_group')
|
||||||
hl.create_component_highlight_group.returns('MyCompHl')
|
hl.create_component_highlight_group.returns('MyCompHl')
|
||||||
local comp1 =
|
local comp1 = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts1)
|
opts1)
|
||||||
eq('MyCompHl', comp1.options.color_highlight)
|
eq('MyCompHl', comp1.options.color_highlight)
|
||||||
-- color highlight wan't in options when create_comp_hl was
|
-- color highlight wan't in options when create_comp_hl was
|
||||||
-- called so remove it before assert
|
-- called so remove it before assert
|
||||||
|
@ -48,8 +48,8 @@ describe('Component:', function()
|
||||||
comp1.options)
|
comp1.options)
|
||||||
hl.create_component_highlight_group:revert()
|
hl.create_component_highlight_group:revert()
|
||||||
local opts2 = build_component_opts({color = 'MyHl'})
|
local opts2 = build_component_opts({color = 'MyHl'})
|
||||||
local comp2 =
|
local comp2 = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(opts2)
|
opts2)
|
||||||
eq('MyHl', comp2.options.color_highlight_link)
|
eq('MyHl', comp2.options.color_highlight_link)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ describe('Component:', function()
|
||||||
stub(hl, 'component_format_highlight')
|
stub(hl, 'component_format_highlight')
|
||||||
hl.component_format_highlight.returns('%#MyCompHl#')
|
hl.component_format_highlight.returns('%#MyCompHl#')
|
||||||
local comp2 =
|
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_component(nil, opts2, '%#MyCompHl#test')
|
||||||
assert.stub(hl.component_format_highlight).was_called_with(
|
assert.stub(hl.component_format_highlight).was_called_with(
|
||||||
comp2.options.color_highlight)
|
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 helpers = require 'tests.helpers'
|
||||||
|
|
||||||
local eq = helpers.eq
|
local eq = assert.are.same
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local build_component_opts = helpers.build_component_opts
|
local build_component_opts = helpers.build_component_opts
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ describe('Section genarator', function()
|
||||||
it('can draw', function()
|
it('can draw', function()
|
||||||
local opts = build_component_opts()
|
local opts = build_component_opts()
|
||||||
local section = {
|
local section = {
|
||||||
require('lua.lualine.components.special.function_component'):new(opts),
|
require('lualine.components.special.function_component'):new(opts),
|
||||||
require('lua.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#'))
|
eq('%#MyHl# test %#MyHl# test ', sec.draw_section(section, '%#MyHl#'))
|
||||||
end)
|
end)
|
||||||
|
@ -87,24 +87,21 @@ describe('Section genarator', function()
|
||||||
require'lualine.highlight'.create_highlight_groups(
|
require'lualine.highlight'.create_highlight_groups(
|
||||||
require 'lualine.themes.gruvbox')
|
require 'lualine.themes.gruvbox')
|
||||||
local section = {
|
local section = {
|
||||||
require('lua.lualine.components.special.function_component'):new(opts),
|
require('lualine.components.special.function_component'):new(opts),
|
||||||
require('lua.lualine.components.special.function_component'):new(
|
require('lualine.components.special.function_component'):new(opts_colored),
|
||||||
opts_colored),
|
require('lualine.components.special.function_component'):new(opts)
|
||||||
require('lua.lualine.components.special.function_component'):new(opts)
|
|
||||||
}
|
}
|
||||||
-- Removes separator on string color
|
-- Removes separator on string color
|
||||||
eq('%#MyHl# test %#MyHl#%#MyColor# test %#MyHl# test ',
|
eq('%#MyHl# test %#MyHl#%#MyColor# test %#MyHl# test ',
|
||||||
sec.draw_section(section, '%#MyHl#'))
|
sec.draw_section(section, '%#MyHl#'))
|
||||||
section[2] =
|
section[2] = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(
|
|
||||||
opts_colored2)
|
opts_colored2)
|
||||||
local highlight_name =
|
local highlight_name =
|
||||||
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
||||||
-- Removes separator on color with bg
|
-- Removes separator on color with bg
|
||||||
eq('%#MyHl# test %#MyHl#' .. highlight_name .. ' test %#MyHl# test ',
|
eq('%#MyHl# test %#MyHl#' .. highlight_name .. ' test %#MyHl# test ',
|
||||||
sec.draw_section(section, '%#MyHl#'))
|
sec.draw_section(section, '%#MyHl#'))
|
||||||
section[2] =
|
section[2] = require('lualine.components.special.function_component'):new(
|
||||||
require('lua.lualine.components.special.function_component'):new(
|
|
||||||
opts_colored3)
|
opts_colored3)
|
||||||
local highlight_name2 =
|
local highlight_name2 =
|
||||||
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
'%#lualine_c_' .. section[2].options.component_name .. '_normal#'
|
Loading…
Reference in New Issue