diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80a1ead..a9c538a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: Tests -on: +on: push: branches: [master] pull_request: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index db2f6cb..6c3fb18 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,6 @@ name: Linting -on: +on: push: branches: [master] pull_request: diff --git a/.gitignore b/.gitignore index 345c51d..1e1f76d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,3 @@ tags # helptags doc/tags - diff --git a/.luacheckrc b/.luacheckrc index f97f58b..a89548c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,4 +1,5 @@ globals = { "vim", "vimp", + "assert" } diff --git a/Makefile b/Makefile index 88c5c2f..926981f 100644 --- a/Makefile +++ b/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 diff --git a/doc/lualine.txt b/doc/lualine.txt index b91b928..5669462 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -296,7 +296,7 @@ option (default_value) Supported components: all • disabled_filetypes ({}) - Disables lualine for specific filetypes. It works on entire + Disables lualine for specific filetypes. It works on entire statusline instead of on a single component. Example: @@ -325,7 +325,7 @@ option (default_value) `lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}` the members of color table are optional and default to theme Color option can also be a string containing highlight group name > - color = "WarningMsg"` + color = "WarningMsg"` < One neat trick set the color to highlight group name then change that highlight with :hi command to change color of that component at runtime. @@ -410,7 +410,7 @@ In addition, some components have unique options. Displays relative path if set to `true`, absolute path if set to `false` • shorten (true) - if `full_path` is `true` and `shorten` is `false` it shortens + if `full_path` is `true` and `shorten` is `false` it shortens absolute path `aaa/bbb/ccc/file` to `a/b/c/file` • symbols (`{modified = '[+]', readonly = '[-]'}`) diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index 2e96e20..15f05be 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -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 diff --git a/lua/lualine/config.lua b/lua/lualine/config.lua new file mode 100644 index 0000000..41e24a1 --- /dev/null +++ b/lua/lualine/config.lua @@ -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} diff --git a/lua/lualine/defaults.lua b/lua/lualine/defaults.lua deleted file mode 100644 index 33763f7..0000000 --- a/lua/lualine/defaults.lua +++ /dev/null @@ -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 diff --git a/lua/lualine/init.lua b/lua/lualine/init.lua index 615b3c0..be24320 100644 --- a/lua/lualine/init.lua +++ b/lua/lualine/init.lua @@ -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,33 +132,30 @@ 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() - local function get_theme_from_config() - local theme_name = config.options.theme - if type(theme_name) == 'string' then - local ok, theme = pcall(require, 'lualine.themes.' .. theme_name) - if ok then return theme end - elseif type(theme_name) == 'table' then - -- 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, {}) - return require 'lualine.themes.gruvbox' - end - local theme = get_theme_from_config() - highlight.create_highlight_groups(theme) - vim.api.nvim_exec([[ - augroup lualine - autocmd ColorScheme * lua require'lualine.utils.utils'.reload_highlights() - augroup END - ]], false) - async_loader:close() - end)) + 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 + local ok, theme = pcall(require, 'lualine.themes.' .. theme_name) + if ok then return theme end + elseif type(theme_name) == 'table' then + -- use the provided theme as-is + return config.options.theme + end + 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() + highlight.create_highlight_groups(theme) + vim.api.nvim_exec([[ + augroup lualine + autocmd ColorScheme * lua require'lualine.utils.utils'.reload_highlights() + augroup END + ]], false) + async_loader:close() + end)) async_loader:send() end @@ -280,23 +170,23 @@ local function set_statusline() if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then vim.o.statusline = '%!v:lua.require\'lualine\'.statusline()' vim.api.nvim_exec([[ - augroup lualine - autocmd! - autocmd WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline() - autocmd WinEnter,BufEnter * set statusline< - augroup END + augroup lualine + autocmd! + autocmd WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline() + autocmd WinEnter,BufEnter * set statusline< + augroup END ]], false) end 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 diff --git a/lua/lualine/themes/modus_vivendi.lua b/lua/lualine/themes/modus_vivendi.lua index cefe7ed..b592ecb 100644 --- a/lua/lualine/themes/modus_vivendi.lua +++ b/lua/lualine/themes/modus_vivendi.lua @@ -17,41 +17,41 @@ local colors = { -- LuaFormatter on modus_vivendi.normal = { - a = {bg = colors.blue, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.lightgray, fg = colors.blue}, - c = {bg = colors.gray, fg = colors.white} + a = {bg = colors.blue, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.lightgray, fg = colors.blue}, + c = {bg = colors.gray, fg = colors.white} } modus_vivendi.insert = { - a = {bg = colors.cyan, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.lightgray, fg = colors.cyan}, - c = {bg = colors.gray, fg = colors.white} + a = {bg = colors.cyan, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.lightgray, fg = colors.cyan}, + c = {bg = colors.gray, fg = colors.white} } modus_vivendi.visual = { - a = {bg = colors.magenta, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.lightgray, fg = colors.magenta}, - c = {bg = colors.gray, fg = colors.white} + a = {bg = colors.magenta, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.lightgray, fg = colors.magenta}, + c = {bg = colors.gray, fg = colors.white} } modus_vivendi.replace = { - a = {bg = colors.red, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.lightgray, fg = colors.red}, - c = {bg = colors.gray, fg = colors.white} + a = {bg = colors.red, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.lightgray, fg = colors.red}, + c = {bg = colors.gray, fg = colors.white} } modus_vivendi.command = { - a = {bg = colors.green, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.lightgray, fg = colors.green}, - c = {bg = colors.gray, fg = colors.white} + a = {bg = colors.green, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.lightgray, fg = colors.green}, + c = {bg = colors.gray, fg = colors.white} } modus_vivendi.terminal = modus_vivendi.normal modus_vivendi.inactive = { - a = {bg = colors.darkgray, fg = colors.lightgray, gui = 'bold'}, - b = {bg = colors.darkgray, fg = colors.lightgray}, - c = {bg = colors.darkgray, fg = colors.lightgray} + a = {bg = colors.darkgray, fg = colors.lightgray, gui = 'bold'}, + b = {bg = colors.darkgray, fg = colors.lightgray}, + c = {bg = colors.darkgray, fg = colors.lightgray} } return modus_vivendi diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua new file mode 100644 index 0000000..69b4ebb --- /dev/null +++ b/lua/lualine/utils/loader.lua @@ -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} diff --git a/lua/lualine/utils/mode.lua b/lua/lualine/utils/mode.lua index e7f6c62..8a6dd23 100644 --- a/lua/lualine/utils/mode.lua +++ b/lua/lualine/utils/mode.lua @@ -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', diff --git a/lua/lualine/utils/section.lua b/lua/lualine/utils/section.lua index ce86034..f8a12f8 100644 --- a/lua/lualine/utils/section.lua +++ b/lua/lualine/utils/section.lua @@ -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)) @@ -33,7 +34,7 @@ function M.draw_section(section, highlight_name) -- Remove component separator when color option is used to color background if (type(section[component_no].options.color) == 'table' and section[component_no].options.color.bg) or - type(section[component_no].options.color) == 'string' then + type(section[component_no].options.color) == 'string' then next_component_colored = true status[component_no] = section[component_no]:strip_separator() end diff --git a/tests/helpers.lua b/lua/tests/helpers.lua similarity index 89% rename from tests/helpers.lua rename to lua/tests/helpers.lua index e9f978b..78d0b33 100644 --- a/tests/helpers.lua +++ b/lua/tests/helpers.lua @@ -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 diff --git a/tests/minimal_init.lua b/lua/tests/minimal_init.lua similarity index 100% rename from tests/minimal_init.lua rename to lua/tests/minimal_init.lua diff --git a/tests/spec/component_spec.lua b/lua/tests/spec/component_spec.lua similarity index 91% rename from tests/spec/component_spec.lua rename to lua/tests/spec/component_spec.lua index ac9b174..e7e80af 100644 --- a/tests/spec/component_spec.lua +++ b/lua/tests/spec/component_spec.lua @@ -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) diff --git a/lua/tests/spec/config_spec.lua b/lua/tests/spec/config_spec.lua new file mode 100644 index 0000000..507fdb5 --- /dev/null +++ b/lua/tests/spec/config_spec.lua @@ -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) diff --git a/tests/spec/utils_spec.lua b/lua/tests/spec/utils_spec.lua similarity index 85% rename from tests/spec/utils_spec.lua rename to lua/tests/spec/utils_spec.lua index a559bc2..d207be6 100644 --- a/tests/spec/utils_spec.lua +++ b/lua/tests/spec/utils_spec.lua @@ -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,25 +87,22 @@ 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( - opts_colored2) + 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( - opts_colored3) + section[2] = require('lualine.components.special.function_component'):new( + opts_colored3) local highlight_name2 = '%#lualine_c_' .. section[2].options.component_name .. '_normal#' -- Doesn't remove separator on color without bg