-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(overrides): add tests for group overrides
- Loading branch information
Showing
3 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |