2026-05-30 19:24:20 -03:00
|
|
|
-- 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))
|
2026-05-30 21:53:56 -03:00
|
|
|
if payload.diagnostic then
|
|
|
|
|
emit('diagnostic.link_severity=' .. tostring(payload.diagnostic.link_severity))
|
|
|
|
|
end
|
2026-05-30 19:24:20 -03:00
|
|
|
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',
|
2026-05-30 21:53:56 -03:00
|
|
|
diagnostic = { link_severity = 'error' },
|
2026-05-30 19:24:20 -03:00
|
|
|
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!')
|