Files
nvim-config/tests/mail_spec.lua

48 lines
1.8 KiB
Lua

-- Test: lua/mail.lua NEOMUTT=1 activation
-- Run from repo root: NEOMUTT=1 nvim --headless -u NONE -i NONE --noplugin -l tests/mail_spec.lua
-- Exit 0 = all assertions passed; non-zero = failure.
-- Does NOT require nvim-mail to be installed (pcall-guarded in mail.lua).
vim.g.mapleader = " "
-- Resolve repo root from this file's path and expose lua/ to require()
local src = debug.getinfo(1, "S").source:sub(2) -- strip leading '@'
local repo = vim.fn.fnamemodify(src, ":h:h") -- tests/../ = repo root
package.path = repo .. "/lua/?.lua;" .. package.path
-- 1. Module loads when NEOMUTT=1 is present in the environment
local ok, err = pcall(require, "mail")
assert(ok, "require('mail') failed: " .. tostring(err))
print("[pass] mail module loaded")
-- 2. Create a scratch buffer, make it current, set filetype to fire the autocmd
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(buf)
vim.cmd("set filetype=mail")
-- 3. Buffer-local option checks (set via vim.opt_local in the FileType callback)
local tw = vim.bo.textwidth
assert(tw == 72, ("textwidth: expected 72, got %d"):format(tw))
print("[pass] textwidth = 72")
local fo = vim.bo.formatoptions
assert(fo:find("q", 1, true), ("formatoptions %q missing 'q'"):format(fo))
print("[pass] formatoptions contains 'q'")
-- 4. Window-local option checks (wrap and spell are 'wo', not 'bo')
assert(vim.wo.wrap, "wrap should be true")
print("[pass] wrap = true")
assert(vim.wo.spell, "spell should be true")
print("[pass] spell = true")
-- 5. Representative keymap registered at global scope by mail.lua
local found_mt = false
for _, m in ipairs(vim.api.nvim_get_keymap("n")) do
if m.desc == "Mail: To:" then found_mt = true; break end
end
assert(found_mt, "<leader>mt (Mail: To:) keymap not registered")
print("[pass] <leader>mt keymap registered")
print("\nALL TESTS PASSED")