Skip to content

Commit

Permalink
test: add test using catppuccin as colorscheme
Browse files Browse the repository at this point in the history
  • Loading branch information
mawkler committed Jan 24, 2024
1 parent 796de27 commit 9bab73e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ test:
nvim \
--headless \
-u tests/init.lua \
-c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/init.lua' }"
-c "PlenaryBustedDirectory tests/ { init = 'tests/init.lua' }"

test-watch:
find tests -name '*.lua' | entr nvim \
find tests -name '*.lua' | entr -c nvim \
--headless \
-u tests/init.lua \
-c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/init.lua' }"
-c "PlenaryBustedDirectory tests/ { init = 'tests/init.lua' }"
5 changes: 3 additions & 2 deletions tests/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local status, error = pcall(function()
pcall(function()
local root = vim.fn.fnamemodify('.repro', ':p')
for _, name in ipairs { 'config', 'data', 'state', 'cache' } do
vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
Expand All @@ -11,13 +11,14 @@ local status, error = pcall(function()
end
vim.opt.runtimepath:prepend(lazy_path)

vim.o.showmode = false
vim.o.termguicolors = true
vim.o.cursorline = true
vim.o.number = true

local plugins = {
{ 'mawkler/modicator.nvim', opts = {} },
{ 'nvim-lua/plenary.nvim' },
{ 'catppuccin/nvim', name = 'catppuccin', },
}

require('lazy').setup(plugins, { root = root .. '/plugins' })
Expand Down
13 changes: 4 additions & 9 deletions tests/mode_switching_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ local highlight_exists = utils.highlight_exists
local get_highlights = utils.get_highlights
local hl_name_from_mode = modicator.hl_name_from_mode

local function setup_modicator()
vim.o.termguicolors = true
vim.o.cursorline = true
vim.o.number = true
require('modicator').setup()
end

--- @param keys string
--- @param mode string?
local function feedkeys(keys, mode)
if mode == nil then mode = 'n' end

-- TODO: `feedkeys()` seems to print out the typed keys in plenary's output
-- window. Not sure how to fix that.
return vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(keys, true, true, true),
mode,
Expand Down Expand Up @@ -69,15 +64,15 @@ local function test_mode_switching(expected_mode, key_press)
assert.are.equal(current_visual_hl_fg, expected_visual_hl_fg)
end

describe('creates highlights', function()
describe('creates default highlights', function()
it('has no modicator highlights before setup', function()
for _, highlight in pairs(get_highlights()) do
assert.is_not_true(highlight_exists(highlight))
end
end)

it('creates highlights on setup', function()
setup_modicator()
require('modicator').setup()

for _, highlight in pairs(get_highlights()) do
assert.is_true(highlight_exists(highlight))
Expand Down
33 changes: 33 additions & 0 deletions tests/mode_switching_with_colorscheme_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local utils = require('modicator.utils')

vim.cmd.colorscheme('catppuccin')

describe('creates highlights with colorscheme', function()
it('creates highlights on setup', function()
require('modicator').setup()

for _, highlight in pairs(utils.get_highlights()) do
assert.is_true(utils.highlight_exists(highlight))
end
end)

it('sets mode highlights for colorscheme', function()
local catppuccin_mode_fg_hls = {
CommandMode = 15912397,
InsertMode = 9024762,
NormalMode = 11845374,
ReplaceMode = 16376495,
SelectMode = 15961000,
TerminalMode = 9034987,
TerminalNormalMode = 11845374,
VisualMode = 10937249,
}

local mode_hl_fgs = {}
for _, hl_name in pairs(utils.get_highlights()) do
mode_hl_fgs[hl_name] = utils.get_highlight(hl_name).fg
end

assert.are.same(catppuccin_mode_fg_hls, mode_hl_fgs)
end)
end)

0 comments on commit 9bab73e

Please sign in to comment.