Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): tiny testing #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 53 additions & 51 deletions lua/litee/lib/highlights/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,72 @@ M.hls = {
ExpandedGuideHL = "LTExpandedGuide",
CollapsedGuideHL = "LTCollapsedGuide",
SelectFiletreeHL = "LTSelectFiletree",
NormalSB = "LTNormalSB"
-- NormalSB = "LTNormalSB"
}
M.dark = {
LTBoolean = 'hi LTBoolean guifg=#0087af guibg=None',
LTConstant = 'hi LTConstant guifg=#0087af guibg=None',
LTConstructor = 'hi LTConstructor guifg=#4DC5C6 guibg=None',
LTField = 'hi LTField guifg=#0087af guibg=None',
LTFunction = 'hi LTFunction guifg=#988ACF guibg=None',
LTMethod = 'hi LTMethod guifg=#0087af guibg=None',
LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None',
LTNumber = 'hi LTNumber guifg=#9b885c guibg=None',
LTOperator = 'hi LTOperator guifg=#988ACF guibg=None',
LTParameter = 'hi LTParameter guifg=#988ACF guibg=None',
LTParameterReference = 'hi LTParameterReference guifg=#4DC5C6 guibg=None',
LTString = 'hi LTString guifg=#af5f5f guibg=None',
LTSymbol = 'hi LTSymbol guifg=#87afd7 gui=underline',
LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#988ACF gui=italic',
LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold',
LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold',
LTType = 'hi LTType guifg=#9b885c guibg=None',
LTURI = 'hi LTURI guifg=#988ACF guibg=None',
LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None',
LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None',
LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None',
LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None',
-- LTGitPullRequest = 'hi LTGitPullRequest guifg=white guibg=None',
}
M.light = {
LTBoolean = 'hi LTBoolean guifg=#005f87 guibg=None',
LTConstant = 'hi LTConstant guifg=#005f87 guibg=None',
LTConstructor = 'hi LTConstructor guifg=#9b885c guibg=None',
LTField = 'hi LTField guifg=#005f87 guibg=None',
LTFunction = 'hi LTFunction guifg=#806CCF guibg=None',
LTMethod = 'hi LTMethod guifg=#005f87 guibg=None',
LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None',
LTNumber = 'hi LTNumber guifg=#9b885c guibg=None',
LTOperator = 'hi LTOperator guifg=#806CCF guibg=None',
LTParameter = 'hi LTParameter guifg=#806CCF guibg=None',
LTParameterReference = 'hi LTParameterReference guifg=#268889 guibg=None',
LTString = 'hi LTString guifg=#af5f5f guibg=None',
LTSymbol = 'hi LTSymbol guifg=#806CCF gui=underline',
LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#005f87 gui=italic',
LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold',
LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold',
LTType = 'hi LTType guifg=#268889 guibg=None',
LTURI = 'hi LTURI guifg=#806CCF guibg=None',
LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None',
LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None',
LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None',
LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None'
}

-- setup_default_highlights configures a list of default
-- highlights for the litee.nvim library.
function M.setup_default_highlights()
local dark = {
LTBoolean = 'hi LTBoolean guifg=#0087af guibg=None',
LTConstant = 'hi LTConstant guifg=#0087af guibg=None',
LTConstructor = 'hi LTConstructor guifg=#4DC5C6 guibg=None',
LTField = 'hi LTField guifg=#0087af guibg=None',
LTFunction = 'hi LTFunction guifg=#988ACF guibg=None',
LTMethod = 'hi LTMethod guifg=#0087af guibg=None',
LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None',
LTNumber = 'hi LTNumber guifg=#9b885c guibg=None',
LTOperator = 'hi LTOperator guifg=#988ACF guibg=None',
LTParameter = 'hi LTParameter guifg=#988ACF guibg=None',
LTParameterReference = 'hi LTParameterReference guifg=#4DC5C6 guibg=None',
LTString = 'hi LTString guifg=#af5f5f guibg=None',
LTSymbol = 'hi LTSymbol guifg=#87afd7 gui=underline',
LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#988ACF gui=italic',
LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold',
LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold',
LTType = 'hi LTType guifg=#9b885c guibg=None',
LTURI = 'hi LTURI guifg=#988ACF guibg=None',
LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None',
LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None',
LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None',
LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None'
}
local light = {
LTBoolean = 'hi LTBoolean guifg=#005f87 guibg=None',
LTConstant = 'hi LTConstant guifg=#005f87 guibg=None',
LTConstructor = 'hi LTConstructor guifg=#9b885c guibg=None',
LTField = 'hi LTField guifg=#005f87 guibg=None',
LTFunction = 'hi LTFunction guifg=#806CCF guibg=None',
LTMethod = 'hi LTMethod guifg=#005f87 guibg=None',
LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None',
LTNumber = 'hi LTNumber guifg=#9b885c guibg=None',
LTOperator = 'hi LTOperator guifg=#806CCF guibg=None',
LTParameter = 'hi LTParameter guifg=#806CCF guibg=None',
LTParameterReference = 'hi LTParameterReference guifg=#268889 guibg=None',
LTString = 'hi LTString guifg=#af5f5f guibg=None',
LTSymbol = 'hi LTSymbol guifg=#806CCF gui=underline',
LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#005f87 gui=italic',
LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold',
LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold',
LTType = 'hi LTType guifg=#268889 guibg=None',
LTURI = 'hi LTURI guifg=#806CCF guibg=None',
LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None',
LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None',
LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None',
LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None'
}

local bg = vim.api.nvim_get_option("background")
if bg == "dark" then
for hl_name, hl in pairs(dark) do
for hl_name, hl in pairs(M.dark) do
if vim.fn.hlexists(hl_name) == 0 then
vim.cmd(hl)
end
end
end
if bg == "light" then
for hl_name, hl in pairs(light) do
for hl_name, hl in pairs(M.light) do
if vim.fn.hlexists(hl_name) == 0 then
vim.cmd(hl)
end
Expand Down
43 changes: 43 additions & 0 deletions tests/check_highlights.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local litee = "lua/litee/lib/"
local highlights = dofile(litee .. "highlights/init.lua")
local hls, dark, light = highlights.hls, highlights.dark, highlights.light
local M, dark_fields, light_fields = {}, {}, {}
for key, _ in pairs(dark) do
dark_fields[key] = true
end
for key, _ in pairs(light) do
light_fields[key] = true
end

function M.hls_dark(desc)
for _, hl in pairs(hls) do
assert(dark_fields[hl], "dark_feild lacks " .. hl)
end
if desc then
return "The highlights in hls are all defined."
end
end

function M.dark_light_fields(desc)
for key, _ in pairs(dark_fields) do
assert(light_fields[key], "light_feild lacks " .. key)
end
for key, _ in pairs(light_fields) do
assert(dark_fields[key], "dark_feild lacks " .. key)
end
if desc then
return "Fields are the same in light & dark highlights."
end
end

function M.icon_hls(desc)
local icons = dofile(litee .. "icons/init.lua")
for _, hl in pairs(icons.icon_hls) do
assert(dark_fields[hl], hl .. "is not defined.")
end
if desc then
return "All highlights in icon_hls are defined."
end
end

return M
30 changes: 30 additions & 0 deletions tests/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Testing
-- * Run test in the project root, `DESC` is optional:
-- * nvim -u NONE --headless -c ":luafile tests/init.lua" +quit
-- * DESC=1 nvim -u NONE --headless -c ":luafile tests/init.lua" +quit
-- * Add test:
-- 1. append the file path to the path table
-- 2. the testing file returns a table containing testing functions
-- 3. testing functions takes an optional `desc` argument which tells the purpose of testing
-- * Sample testing function:
-- function M.name(desc)
-- -- testing code here
-- if desc then
-- return "description"
-- end
-- end

local function test(path, desc)
for name, fn in pairs(dofile(path)) do
print(string.format("%-30s :: %-30s -- PASS -- ", path, name), fn(desc))
end
end

local desc = os.getenv("DESC")
local path = {
"tests/check_highlights.lua",
}

for _, p in ipairs(path) do
test(p, desc)
end