mirror of
https://github.com/timmypidashev/darkbox.nvim.git
synced 2026-04-14 03:33:51 +00:00
Add tests
This commit is contained in:
11
Makefile
Normal file
11
Makefile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
TESTS_INIT=tests/init.lua
|
||||||
|
TESTS_DIR=tests/
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
|
||||||
|
test:
|
||||||
|
@nvim \
|
||||||
|
--headless \
|
||||||
|
--noplugin \
|
||||||
|
-u ${TESTS_INIT} \
|
||||||
|
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"
|
||||||
161
tests/darkbox/darkbox_spec.lua
Normal file
161
tests/darkbox/darkbox_spec.lua
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
require("plenary.reload").reload_module("darkbox", true)
|
||||||
|
local darkbox = require("darkbox")
|
||||||
|
local default = darkbox.config
|
||||||
|
|
||||||
|
local function clear_term_colors()
|
||||||
|
for item = 0, 15 do
|
||||||
|
vim.g["terminal_color_" .. item] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe("tests", function()
|
||||||
|
it("works with default values", function()
|
||||||
|
darkbox.setup()
|
||||||
|
assert.are.same(darkbox.config, default)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("works with config overrides", function()
|
||||||
|
local expected = {
|
||||||
|
terminal_colors = true,
|
||||||
|
undercurl = false,
|
||||||
|
underline = false,
|
||||||
|
bold = true,
|
||||||
|
italic = {
|
||||||
|
strings = true,
|
||||||
|
emphasis = true,
|
||||||
|
comments = true,
|
||||||
|
operators = false,
|
||||||
|
folds = true,
|
||||||
|
},
|
||||||
|
strikethrough = true,
|
||||||
|
inverse = true,
|
||||||
|
invert_selection = false,
|
||||||
|
invert_signs = false,
|
||||||
|
invert_tabline = false,
|
||||||
|
invert_intend_guides = false,
|
||||||
|
contrast = "",
|
||||||
|
palette_overrides = {},
|
||||||
|
overrides = {},
|
||||||
|
dim_inactive = false,
|
||||||
|
transparent_mode = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
darkbox.setup({ undercurl = false, underline = false })
|
||||||
|
assert.are.same(darkbox.config, expected)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should override a hightlight color", function()
|
||||||
|
local config = {
|
||||||
|
overrides = {
|
||||||
|
Search = { fg = "#ff9900", bg = "#000000" },
|
||||||
|
ColorColumn = { bg = "#ff9900" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
darkbox.setup(config)
|
||||||
|
darkbox.load()
|
||||||
|
|
||||||
|
local search_group_id = vim.api.nvim_get_hl_id_by_name("Search")
|
||||||
|
local search_values = {
|
||||||
|
background = vim.fn.synIDattr(search_group_id, "bg", "gui"),
|
||||||
|
foreground = vim.fn.synIDattr(search_group_id, "fg", "gui"),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.are.same(search_values, { background = "#000000", foreground = "#ff9900" })
|
||||||
|
|
||||||
|
local color_column_group_id = vim.api.nvim_get_hl_id_by_name("ColorColumn")
|
||||||
|
local color_column_values = {
|
||||||
|
background = vim.fn.synIDattr(color_column_group_id, "bg", "gui"),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.are.same(color_column_values, { background = "#ff9900" })
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should create new hightlights colors if they dont exist", function()
|
||||||
|
local config = {
|
||||||
|
overrides = {
|
||||||
|
Search = { fg = "#ff9900", bg = "#000000" },
|
||||||
|
New = { bg = "#ff9900" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
darkbox.setup(config)
|
||||||
|
darkbox.load()
|
||||||
|
|
||||||
|
local search_group_id = vim.api.nvim_get_hl_id_by_name("Search")
|
||||||
|
local search_values = {
|
||||||
|
background = vim.fn.synIDattr(search_group_id, "bg", "gui"),
|
||||||
|
foreground = vim.fn.synIDattr(search_group_id, "fg", "gui"),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.are.same(search_values, { background = "#000000", foreground = "#ff9900" })
|
||||||
|
|
||||||
|
local new_group_id = vim.api.nvim_get_hl_id_by_name("New")
|
||||||
|
local new_group_values = {
|
||||||
|
background = vim.fn.synIDattr(new_group_id, "bg", "gui"),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.are.same(new_group_values, { background = "#ff9900" })
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should override links", function()
|
||||||
|
local config = {
|
||||||
|
overrides = {
|
||||||
|
TelescopePreviewBorder = { fg = "#990000", bg = nil },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
darkbox.setup(config)
|
||||||
|
darkbox.load()
|
||||||
|
|
||||||
|
local group_id = vim.api.nvim_get_hl_id_by_name("TelescopePreviewBorder")
|
||||||
|
local values = {
|
||||||
|
fg = vim.fn.synIDattr(group_id, "fg", "gui"),
|
||||||
|
}
|
||||||
|
|
||||||
|
local expected = {
|
||||||
|
fg = "#990000",
|
||||||
|
}
|
||||||
|
assert.are.same(expected, values)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should override palette", function()
|
||||||
|
local config = {
|
||||||
|
palette_overrides = {
|
||||||
|
gray = "#ff9900",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
darkbox.setup(config)
|
||||||
|
darkbox.load()
|
||||||
|
|
||||||
|
local group_id = vim.api.nvim_get_hl_id_by_name("Comment")
|
||||||
|
local values = {
|
||||||
|
fg = vim.fn.synIDattr(group_id, "fg", "gui"),
|
||||||
|
}
|
||||||
|
assert.are.same(values, { fg = "#ff9900" })
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("does not set terminal colors when terminal_colors is false", function()
|
||||||
|
clear_term_colors()
|
||||||
|
darkbox.setup({ terminal_colors = false })
|
||||||
|
darkbox.load()
|
||||||
|
assert.is_nil(vim.g.terminal_color_0)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("sets terminal colors when terminal_colors is true", function()
|
||||||
|
clear_term_colors()
|
||||||
|
darkbox.setup({ terminal_colors = true })
|
||||||
|
darkbox.load()
|
||||||
|
|
||||||
|
-- dark bg
|
||||||
|
local colors = require("gruvbox").palette
|
||||||
|
vim.opt.background = "dark"
|
||||||
|
assert.are.same(vim.g.terminal_color_0, colors.dark0)
|
||||||
|
|
||||||
|
-- light bg
|
||||||
|
clear_term_colors()
|
||||||
|
darkbox.load()
|
||||||
|
vim.opt.background = "light"
|
||||||
|
assert.are.same(vim.g.terminal_color_0, colors.light0)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
11
tests/init.lua
Normal file
11
tests/init.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim"
|
||||||
|
local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0
|
||||||
|
if is_not_a_directory then
|
||||||
|
vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir })
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.opt.rtp:append(".")
|
||||||
|
vim.opt.rtp:append(plenary_dir)
|
||||||
|
|
||||||
|
vim.cmd("runtime plugin/plenary.vim")
|
||||||
|
require("plenary.busted")
|
||||||
Reference in New Issue
Block a user