Skip to content

Commit

Permalink
test(overrides): add tests for group overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
tmillr committed Jul 14, 2024
1 parent 23484d2 commit af30c71
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
3 changes: 1 addition & 2 deletions test/github-theme/config/darken_spec.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
local assert = require('luassert')
local t_util = require('github-theme._test.util')
local C = require('github-theme.lib.color')
local api = vim.api

if not api.nvim_get_hl then
if vim.fn.has('nvim-0.9.0') == 0 or vim.fn.has('nvim-0.9.0') == false then
return
end

Expand Down
121 changes: 121 additions & 0 deletions test/github-theme/config/overrides_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
local assert = require('luassert')
local t_util = require('github-theme._test.util')

if vim.fn.has('nvim-0.9.0') == 0 or vim.fn.has('nvim-0.9.0') == false then
return
end

describe('config > groups', function()
before_each(function()
-- These next 2 lines shouldn't be necessary since we're modifying
-- `package.loaded` below, but they still are for some reason? It might be
-- plenary's fault, not sure, but one of the (less important) tests fails
-- without these. Maybe something we should look into in the future.
require('github-theme.override').reset()
require('github-theme.config').reset()

for name, _ in pairs(_G.package.loaded) do
if name:find('^github-theme') then
_G.package.loaded[name] = nil
end
end
end)

it('should allow clearing a group via empty table (1)', function()
require('github-theme').setup({ groups = { all = { Normal = {} } } })
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same({}, t_util.get_hl('Normal'))
end)

it('should allow clearing a group via empty table (2)', function()
require('github-theme').setup({
groups = {
github_dark_dimmed = { Normal = {} },
all = { Normal = { fg = '#123456', bg = '#654321' } },
},
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same({}, t_util.get_hl('Normal'))
end)

it('clearing group combines properly with more-specific overrides', function()
require('github-theme').setup({
groups = {
all = { Normal = {} },
github_dark_dimmed = { Normal = { fg = '#123456', bg = '#654321' } },
},
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same(
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) },
t_util.get_hl('Normal')
)
end)

it('should allow overriding a group', function()
require('github-theme').setup({
groups = { all = { Normal = { fg = '#123456', bg = '#654321' } } },
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same(
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) },
t_util.get_hl('Normal')
)
end)

it('overriding group combines properly with more-specific overrides (1)', function()
require('github-theme').setup({
groups = {
all = { Normal = { link = 'NormalNC' } },
github_dark_dimmed = { Normal = { fg = '#123456', bg = '#654321' } },
},
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.is_nil(t_util.get_hl('Normal', true).link)
end)

it('overriding group combines properly with more-specific overrides (2)', function()
require('github-theme').setup({
groups = {
all = { Normal = { fg = '#123456', bg = '#654321' } },
github_dark_dimmed = { Normal = { link = 'NormalNC' } },
},
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same({ link = 'NormalNC' }, t_util.get_hl('Normal', true))
end)

it('should allow linking a group', function()
require('github-theme').setup({
groups = { all = { Normal = { link = 'NormalNC' } } },
})
vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same({ link = 'NormalNC' }, t_util.get_hl('Normal', true))
end)

it('should not be affected by a previous override using `link`', function()
vim.print(require('github-theme.override'))
require('github-theme').setup({
groups = {
all = { Normal = { link = 'NormalNC' } },
},
})

require('github-theme').setup({
groups = {
all = { Normal = { fg = '#123456', bg = '#654321' } },
},
})

vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same(
{ fg = '#123456', bg = '#654321' },
require('github-theme.override').groups.all.Normal
)
assert.is_nil(t_util.get_hl('Normal', true).link)
assert.same(
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) },
t_util.get_hl('Normal')
)
end)
end)
6 changes: 5 additions & 1 deletion test/minimal_init.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
lua vim.loader.disable()
lua <<
if vim.fn.has('nvim-0.9.0') == 1 or vim.fn.has('nvim-0.9.0') == true then
vim.loader.disable()
end
.
set rtp+=.
set rtp+=./test/plenary
runtime! plugin/plenary.vim

0 comments on commit af30c71

Please sign in to comment.