From af30c71513081716ac0ed913e807d757c4f66c93 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Sun, 14 Jul 2024 15:51:46 -0700 Subject: [PATCH] test(overrides): add tests for group overrides --- test/github-theme/config/darken_spec.lua | 3 +- test/github-theme/config/overrides_spec.lua | 121 ++++++++++++++++++++ test/minimal_init.vim | 6 +- 3 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 test/github-theme/config/overrides_spec.lua diff --git a/test/github-theme/config/darken_spec.lua b/test/github-theme/config/darken_spec.lua index 063a328..c0502c1 100644 --- a/test/github-theme/config/darken_spec.lua +++ b/test/github-theme/config/darken_spec.lua @@ -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 diff --git a/test/github-theme/config/overrides_spec.lua b/test/github-theme/config/overrides_spec.lua new file mode 100644 index 0000000..344e0f1 --- /dev/null +++ b/test/github-theme/config/overrides_spec.lua @@ -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) diff --git a/test/minimal_init.vim b/test/minimal_init.vim index ec2c966..6aa2d4e 100644 --- a/test/minimal_init.vim +++ b/test/minimal_init.vim @@ -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