| 1 |
-- Copyright (c) 2020-2021 shadmansaleh |
| 2 |
-- MIT license, see LICENSE for more details. |
| 3 |
|
| 4 |
local eq = assert.are.same |
| 5 |
|
| 6 |
describe('config parsing', function() |
| 7 |
local config_module = require('lualine.config') |
| 8 |
|
| 9 |
describe('options', function() |
| 10 |
describe('icons_enabled', function() |
| 11 |
it('default', function() |
| 12 |
local config = config_module.apply_configuration {} |
| 13 |
eq(config.options.icons_enabled, true) |
| 14 |
end) |
| 15 |
it('custom', function() |
| 16 |
local config = { options = { icons_enabled = false } } |
| 17 |
config = config_module.apply_configuration(config) |
| 18 |
eq(config.options.icons_enabled, false) |
| 19 |
end) |
| 20 |
end) |
| 21 |
|
| 22 |
describe('theme', function() |
| 23 |
it('default', function() |
| 24 |
local config = config_module.apply_configuration {} |
| 25 |
eq(config.options.theme, 'auto') |
| 26 |
end) |
| 27 |
it('custom', function() |
| 28 |
local config = { options = { theme = 'nord' } } |
| 29 |
config = config_module.apply_configuration(config) |
| 30 |
eq(config.options.theme, 'nord') |
| 31 |
config = { options = { theme = {} } } |
| 32 |
config = config_module.apply_configuration(config) |
| 33 |
eq(config.options.theme, {}) |
| 34 |
end) |
| 35 |
end) |
| 36 |
|
| 37 |
describe('separators', function() |
| 38 |
it('default', function() |
| 39 |
local config = config_module.apply_configuration {} |
| 40 |
eq(config.options.component_separators, { left = '', right = '' }) |
| 41 |
eq(config.options.section_separators, { left = '', right = '' }) |
| 42 |
end) |
| 43 |
it('double separators', function() |
| 44 |
local config = { |
| 45 |
options = { |
| 46 |
component_separators = { left = 'a', right = 'b' }, |
| 47 |
section_separators = { left = 'c', right = 'd' }, |
| 48 |
}, |
| 49 |
} |
| 50 |
config = config_module.apply_configuration(config) |
| 51 |
eq(config.options.component_separators, { left = 'a', right = 'b' }) |
| 52 |
eq(config.options.section_separators, { left = 'c', right = 'd' }) |
| 53 |
end) |
| 54 |
|
| 55 |
describe('single separator', function() |
| 56 |
it('string', function() |
| 57 |
local config = { |
| 58 |
options = { component_separators = 'a', section_separators = 'b' }, |
| 59 |
} |
| 60 |
config = config_module.apply_configuration(config) |
| 61 |
eq(config.options.component_separators, { left = 'a', right = 'a' }) |
| 62 |
eq(config.options.section_separators, { left = 'b', right = 'b' }) |
| 63 |
end) |
| 64 |
it('table', function() |
| 65 |
local config = { |
| 66 |
options = { |
| 67 |
component_separators = { left = 'a', right = 'b' }, |
| 68 |
section_separators = { left = 'b', right = 'a' }, |
| 69 |
}, |
| 70 |
} |
| 71 |
config = config_module.apply_configuration(config) |
| 72 |
eq(config.options.component_separators, { left = 'a', right = 'b' }) |
| 73 |
eq(config.options.section_separators, { left = 'b', right = 'a' }) |
| 74 |
end) |
| 75 |
end) |
| 76 |
it('no separators', function() |
| 77 |
local config = { |
| 78 |
options = { component_separators = {}, section_separators = {} }, |
| 79 |
} |
| 80 |
config = config_module.apply_configuration(config) |
| 81 |
eq(config.options.component_separators, {}) |
| 82 |
eq(config.options.section_separators, {}) |
| 83 |
end) |
| 84 |
end) |
| 85 |
|
| 86 |
describe('disabled filetypes', function() |
| 87 |
it('default', function() |
| 88 |
local config = config_module.apply_configuration {} |
| 89 |
eq(config.options.disabled_filetypes, { statusline = {}, winbar = {} }) |
| 90 |
end) |
| 91 |
it('custom', function() |
| 92 |
local config = { options = { disabled_filetypes = { 'lua' } } } |
| 93 |
config = config_module.apply_configuration(config) |
| 94 |
eq(config.options.disabled_filetypes, { statusline = { 'lua' }, winbar = { 'lua' } }) |
| 95 |
end) |
| 96 |
end) |
| 97 |
|
| 98 |
describe('non default global option', function() |
| 99 |
it('default', function() |
| 100 |
local config = { options = {} } |
| 101 |
config = config_module.apply_configuration(config) |
| 102 |
eq(config.options.non_default_global_option, nil) |
| 103 |
end) |
| 104 |
it('custom', function() |
| 105 |
local config = { options = { non_default_global_option = 1 } } |
| 106 |
config = config_module.apply_configuration(config) |
| 107 |
eq(config.options.non_default_global_option, 1) |
| 108 |
end) |
| 109 |
end) |
| 110 |
end) |
| 111 |
|
| 112 |
describe('sections', function() |
| 113 |
it('default', function() |
| 114 |
local config = {} |
| 115 |
config = config_module.apply_configuration(config) |
| 116 |
local lualine_default_sections = { |
| 117 |
lualine_a = { 'mode' }, |
| 118 |
lualine_b = { 'branch', 'diff', 'diagnostics' }, |
| 119 |
lualine_c = { 'filename' }, |
| 120 |
lualine_x = { 'encoding', 'fileformat', 'filetype' }, |
| 121 |
lualine_y = { 'progress' }, |
| 122 |
lualine_z = { 'location' }, |
| 123 |
} |
| 124 |
eq(config.sections, lualine_default_sections) |
| 125 |
end) |
| 126 |
it('custom', function() |
| 127 |
local custom_sections = { |
| 128 |
lualine_a = { { 'mode', lower = true } }, |
| 129 |
lualine_b = { 'branch', { 'branch', lower = true } }, |
| 130 |
lualine_c = nil, |
| 131 |
lualine_x = {}, |
| 132 |
} |
| 133 |
local expected_sections = { |
| 134 |
lualine_a = { { 'mode', lower = true } }, |
| 135 |
lualine_b = { 'branch', { 'branch', lower = true } }, |
| 136 |
lualine_c = { 'filename' }, |
| 137 |
lualine_x = {}, |
| 138 |
lualine_y = { 'progress' }, |
| 139 |
lualine_z = { 'location' }, |
| 140 |
} |
| 141 |
local config = { sections = custom_sections } |
| 142 |
config = config_module.apply_configuration(config) |
| 143 |
eq(config.sections, expected_sections) |
| 144 |
end) |
| 145 |
end) |
| 146 |
|
| 147 |
describe('inactive_sections', function() end) |
| 148 |
|
| 149 |
describe('tabline', function() |
| 150 |
it('default', function() |
| 151 |
local config = {} |
| 152 |
config = config_module.apply_configuration(config) |
| 153 |
eq(config.tabline, {}) |
| 154 |
end) |
| 155 |
it('custom', function() |
| 156 |
local custom_sections = { |
| 157 |
lualine_a = { { 'mode', lower = true } }, |
| 158 |
lualine_b = { 'branch', { 'branch', lower = true } }, |
| 159 |
lualine_c = nil, |
| 160 |
lualine_x = {}, |
| 161 |
} |
| 162 |
local expected_sections = { |
| 163 |
lualine_a = { { 'mode', lower = true } }, |
| 164 |
lualine_b = { 'branch', { 'branch', lower = true } }, |
| 165 |
lualine_x = {}, |
| 166 |
} |
| 167 |
local config = { tabline = custom_sections } |
| 168 |
config = config_module.apply_configuration(config) |
| 169 |
eq(config.tabline, expected_sections) |
| 170 |
end) |
| 171 |
end) |
| 172 |
|
| 173 |
describe('extensions', function() |
| 174 |
it('default', function() |
| 175 |
local config = { options = {} } |
| 176 |
config = config_module.apply_configuration(config) |
| 177 |
eq(config.extensions, {}) |
| 178 |
end) |
| 179 |
it('custom', function() |
| 180 |
local config = { extensions = { 'fugitive' } } |
| 181 |
config = config_module.apply_configuration(config) |
| 182 |
eq(config.extensions, { 'fugitive' }) |
| 183 |
end) |
| 184 |
end) |
| 185 |
end) |