Files
nuwiki/development/tests/test-config.lua
gffranco e3f28d7dfc
CI / cargo fmt --check (push) Successful in 23s
CI / cargo clippy (push) Successful in 31s
CI / cargo test (push) Successful in 31s
CI / editor keymaps (push) Successful in 1m28s
test(config): cover link_severity in parity harnesses and docs
Both editor harnesses now emit diagnostic.link_severity and exercise a
non-default override ('error') in the sample scenario, diffed against the
shared golden. Drop the README "not wired" caveat now that the value flows
through, and document the g:nuwiki_link_severity global.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 21:53:56 -03:00

79 lines
2.4 KiB
Lua

-- development/tests/test-config.lua — dump the Neovim client's
-- `initialization_options` payload for two scenarios (default config and a
-- representative multi-wiki sample) as deterministic `key=value` lines.
--
-- The runner (test-config.sh) diffs the output against
-- development/tests/config-expected.txt. The Vim harness
-- (test-config-vim.vim) emits byte-identical lines against the SAME golden,
-- so "nvim == golden" and "vim == golden" together prove the two clients
-- send the same server-bound config — i.e. Vim/Neovim config parity.
--
-- Only the server-relevant keys are emitted (wiki_root, file_extension,
-- syntax, log_level, wikis[*]). `mappings`/`folding` are client-side
-- concerns the server ignores, so they're intentionally excluded.
local out = assert(os.getenv('NUWIKI_CONFIG_OUT'), 'NUWIKI_CONFIG_OUT unset')
local config = require('nuwiki.config')
local lsp = require('nuwiki.lsp')
local lines = {}
local function emit(s)
lines[#lines + 1] = s
end
local function dump(payload)
emit('wiki_root=' .. tostring(payload.wiki_root))
emit('file_extension=' .. tostring(payload.file_extension))
emit('syntax=' .. tostring(payload.syntax))
emit('log_level=' .. tostring(payload.log_level))
if payload.diagnostic then
emit('diagnostic.link_severity=' .. tostring(payload.diagnostic.link_severity))
end
if payload.wikis then
for i, w in ipairs(payload.wikis) do
local keys = {}
for k in pairs(w) do
keys[#keys + 1] = k
end
table.sort(keys)
for _, k in ipairs(keys) do
emit(string.format('wikis[%d].%s=%s', i - 1, k, tostring(w[k])))
end
end
end
end
-- Scenario 1: defaults (no user config, no VimL globals).
vim.g.nuwiki_wikis = nil
config.apply({})
emit('[default]')
dump(lsp.init_options())
-- Scenario 2: representative config exercising scalar keys + a wikis list.
config.apply({
wiki_root = '/tmp/base',
file_extension = '.md',
syntax = 'vimwiki',
log_level = 'debug',
diagnostic = { link_severity = 'error' },
wikis = {
{
name = 'personal',
root = '/tmp/personal',
file_extension = '.wiki',
index = 'home',
diary_rel_path = 'journal',
},
{ name = 'work', root = '/tmp/work' },
},
})
emit('[sample]')
dump(lsp.init_options())
local f = assert(io.open(out, 'w'))
f:write(table.concat(lines, '\n') .. '\n')
f:close()
vim.cmd('qa!')