Skip to content

Commit

Permalink
test(overrides): add test for spec overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
tmillr committed Aug 5, 2024
1 parent 0dd4317 commit e5d683f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
### Issues Fix

- Made `Color()` constructor idempotent (previously, passing a `Color` inst silently caused a bug)
- Fixed unable to override/customize spec (#359)

## [v1.1.0] - 23 July 2024

Expand Down
34 changes: 31 additions & 3 deletions test/github-theme/config/overrides_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ describe('config > groups', function()
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' } },
all = { Normal = {} },
},
})

vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same(
{ fg = tonumber('123456', 16), bg = tonumber('654321', 16) },
Expand All @@ -45,6 +47,7 @@ describe('config > groups', 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) },
Expand All @@ -55,21 +58,23 @@ describe('config > groups', function()
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' } },
all = { Normal = { link = 'NormalNC' } },
},
})

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' } },
all = { Normal = { fg = '#123456', bg = '#654321' } },
},
})

vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same({ link = 'NormalNC' }, t_util.get_hl('Normal', true))
end)
Expand All @@ -78,6 +83,7 @@ describe('config > groups', 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)
Expand Down Expand Up @@ -106,3 +112,25 @@ describe('config > groups', function()
)
end)
end)

describe('config > specs', function()
before_each(function()
require('github-theme.util.reload')(true)
end)

it('should allow overriding the spec', function()
require('github-theme').setup({
specs = {
github_dark_dimmed = { bg1 = '#654321' },
github_dark = { bg1 = '#652322' },
all = { bg1 = '#123456' },
},
})

local spec = require('github-theme.spec').load('github_dark_dimmed')
assert.equals('#654321', spec.bg1)

vim.cmd.colorscheme({ args = { 'github_dark_dimmed' } })
assert.same(tonumber('654321', 16), t_util.get_hl('Normal').bg)
end)
end)

0 comments on commit e5d683f

Please sign in to comment.