refactor(tests): use table for configs

This commit is contained in:
Null Chilly 2023-06-28 11:30:46 +07:00
parent 8d02781a63
commit 12894370fa
5 changed files with 185 additions and 62 deletions

View file

@ -1,20 +0,0 @@
describe("compile", function()
before_each(function()
for name, _ in pairs(package.loaded) do
if name:match "^catppuccin" and name ~= "catppuccin" then package.loaded[name] = nil end
end
end)
it("without setup", function()
assert.equals(pcall(function() require("catppuccin").compile() end), true)
end)
it("user 1", function()
require("catppuccin").setup {
custom_highlight = function(C)
return {
SpellBad = { cterm = { underdashed = true } },
}
end,
}
assert.equals(pcall(function() require("catppuccin").compile() end), true)
end)
end)

41
tests/hash_spec.lua Normal file
View file

@ -0,0 +1,41 @@
describe("hash", function()
local hash = require("catppuccin.lib.hashing").hash
it("typo", function() assert.are_not.equals(hash { custom_highlight = {} }, hash { ustom_highlight = {} }) end)
it(
"when table order is shuffled",
function()
assert.equals(
hash {
custom_highlight = {
Search = { fg = "#F5C2E7", bg = "#45475A", style = { "bold" } },
IncSearch = { fg = "#45475A", bg = "#F5C2E7" },
},
},
hash {
custom_highlight = {
Search = { style = { "bold" }, bg = "#45475A", fg = "#F5C2E7" },
IncSearch = { bg = "#F5C2E7", fg = "#45475A" },
},
}
)
end
)
it(
"when toggle true/false",
function()
assert.are_not.equals({
integrations = {
navic = true,
noice = true,
fidget = true,
},
}, {
integrations = {
navic = true,
noice = false,
fidget = false,
},
})
end
)
end)

View file

@ -1,5 +0,0 @@
describe("set colorscheme", function()
it("without calling setup", function()
assert.equals(pcall(function() vim.cmd.colorscheme "catppuccin" end), true)
end)
end)

View file

@ -1,41 +1,148 @@
describe("setup hash", function()
local hash = require("catppuccin.lib.hashing").hash
it("typo", function() assert.are_not.equals(hash { custom_highlight = {} }, hash { ustom_highlight = {} }) end)
it(
"when table order is shuffled",
function()
assert.equals(
hash {
custom_highlight = {
Search = { fg = "#F5C2E7", bg = "#45475A", style = { "bold" } },
IncSearch = { fg = "#45475A", bg = "#F5C2E7" },
},
local configs = {
without_setup = {},
transparent_background = {
transparent = true,
},
cterm = {
custom_highlight = function(C)
return {
SpellBad = { cterm = { underdashed = true } },
}
end,
},
-- User configs
nullchilly = {
{
term_colors = true,
transparent_background = false,
styles = {
comments = {},
conditionals = {},
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
},
color_overrides = {
mocha = {
base = "#000000",
mantle = "#000000",
crust = "#000000",
},
hash {
custom_highlight = {
Search = { style = { "bold" }, bg = "#45475A", fg = "#F5C2E7" },
IncSearch = { bg = "#F5C2E7", fg = "#45475A" },
},
},
integrations = {
dropbar = {
enabled = true,
color_mode = true,
},
},
},
},
nekowinston = {
transparent_background = not vim.g.neovide,
dim_inactive = {
enable = true,
shade = "dark",
percentage = 0.15,
},
styles = {
comments = { "italic" },
conditionals = { "italic" },
},
term_colors = true,
integrations = {
treesitter = true,
native_lsp = {
enabled = true,
virtual_text = {
errors = { "italic" },
hints = { "italic" },
warnings = { "italic" },
information = { "italic" },
},
underlines = {
errors = { "undercurl" },
hints = { "undercurl" },
warnings = { "undercurl" },
information = { "undercurl" },
},
},
cmp = true,
lsp_trouble = true,
nvimtree = true,
which_key = true,
indent_blankline = {
enabled = true,
colored_indent_levels = true,
},
navic = {
enabled = true,
custom_bg = "NONE",
},
gitsigns = true,
lightspeed = true,
markdown = true,
neogit = true,
symbols_outline = true,
ts_rainbow = true,
vimwiki = true,
notify = true,
},
highlight_overrides = {
all = function(colors)
return {
-- borders
FloatBorder = { fg = colors.overlay0 },
LspInfoBorder = { link = "FloatBorder" },
NvimTreeWinSeparator = { link = "FloatBorder" },
WhichKeyBorder = { link = "FloatBorder" },
-- telescope
TelescopeBorder = { link = "FloatBorder" },
TelescopeTitle = { fg = colors.text },
TelescopeSelection = { link = "Selection" },
TelescopeSelectionCaret = { link = "Selection" },
-- pmenu
PmenuSel = { link = "Selection" },
-- bufferline
BufferLineTabSeparator = { link = "FloatBorder" },
BufferLineSeparator = { link = "FloatBorder" },
BufferLineOffsetSeparator = { link = "FloatBorder" },
--
FidgetTitle = { fg = colors.subtext1 },
FidgetTask = { fg = colors.subtext0 },
NotifyBackground = { bg = colors.base },
NotifyINFOBorder = { link = "NotifyInfoTitle" },
NotifyINFOIcon = { link = "NotifyINFOTitle" },
NotifyINFOTitle = { fg = colors.pink },
}
end,
},
},
}
describe("setup", function()
before_each(function()
for name, _ in pairs(package.loaded) do
if name:match "^catppuccin" and name ~= "catppuccin" then package.loaded[name] = nil end
end
end)
for name, config in pairs(configs) do
it(name, function()
require("catppuccin").setup(config)
assert.equals(
pcall(function()
require("catppuccin").compile()
vim.cmd.colorscheme "catppuccin"
end),
true
)
end
)
it(
"when toggle true/false",
function()
assert.are_not.equals({
integrations = {
navic = true,
noice = true,
fidget = true,
},
}, {
integrations = {
navic = true,
noice = false,
fidget = false,
},
})
end
)
end)
end
end)