55 lines
2.0 KiB
Lua
55 lines
2.0 KiB
Lua
|
|
-- development/tests/test-global-shorthand.lua — Neovim client global
|
||
|
|
-- shorthand: a per-wiki setting given once at the top level (setup() or
|
||
|
|
-- g:nuwiki_<key>) is folded into every wiki as a default, and a per-wiki
|
||
|
|
-- value overrides it. Mirror of the Vim test-vimwiki-compat checks.
|
||
|
|
--
|
||
|
|
-- Writes PASS/FAIL lines to $NUWIKI_GS_OUT; the wrapper fails on any FAIL.
|
||
|
|
|
||
|
|
local config = require('nuwiki.config')
|
||
|
|
local lsp = require('nuwiki.lsp')
|
||
|
|
|
||
|
|
local out = {}
|
||
|
|
local function check(desc, cond)
|
||
|
|
table.insert(out, (cond and 'PASS ' or 'FAIL ') .. desc)
|
||
|
|
end
|
||
|
|
|
||
|
|
-- ----- setup() top-level scalar folds into every wiki; per-wiki wins -----
|
||
|
|
config.apply({
|
||
|
|
toc_header_level = 2,
|
||
|
|
html_header_numbering = 2,
|
||
|
|
wikis = {
|
||
|
|
{ root = '/tmp/one', name = 'One' },
|
||
|
|
{ root = '/tmp/two', name = 'Two', toc_header_level = 3 },
|
||
|
|
},
|
||
|
|
})
|
||
|
|
local io1 = lsp.init_options()
|
||
|
|
check('w0 inherits global level', io1.wikis[1].toc_header_level == 2)
|
||
|
|
check('w0 inherits numbering', io1.wikis[1].html_header_numbering == 2)
|
||
|
|
check('w1 per-wiki override wins', io1.wikis[2].toc_header_level == 3)
|
||
|
|
check('w1 still inherits numbering', io1.wikis[2].html_header_numbering == 2)
|
||
|
|
|
||
|
|
-- The user's setup table must not be mutated by the fold.
|
||
|
|
check('no mutation of user wikis', config.user.wikis[1].toc_header_level == nil)
|
||
|
|
|
||
|
|
-- ----- built-in defaults are NOT folded (only explicit user values) -----
|
||
|
|
config.apply({
|
||
|
|
wikis = { { root = '/tmp/x', name = 'X' } },
|
||
|
|
})
|
||
|
|
local io2 = lsp.init_options()
|
||
|
|
check('default toc_header not folded', io2.wikis[1].toc_header == nil)
|
||
|
|
check('default level not folded', io2.wikis[1].toc_header_level == nil)
|
||
|
|
|
||
|
|
-- ----- g:nuwiki_<key> acts as a global too -----
|
||
|
|
config.apply({
|
||
|
|
wikis = { { root = '/tmp/y', name = 'Y' } },
|
||
|
|
})
|
||
|
|
vim.g.nuwiki_toc_header_level = 5
|
||
|
|
local io3 = lsp.init_options()
|
||
|
|
check('g:nuwiki_ global folds', io3.wikis[1].toc_header_level == 5)
|
||
|
|
vim.g.nuwiki_toc_header_level = nil
|
||
|
|
|
||
|
|
local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w'))
|
||
|
|
f:write(table.concat(out, '\n') .. '\n')
|
||
|
|
f:close()
|
||
|
|
vim.cmd('qa!')
|