2026-05-12 12:41:46 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
2026-05-30 18:35:40 +00:00
|
|
|
# development/tests/test-keymaps-vim.sh — Vim counterpart of test-keymaps.sh.
|
2026-05-12 12:41:46 +00:00
|
|
|
#
|
|
|
|
|
# Pure-VimL portion only. The LSP-roundtrip keymaps (`<C-Space>`,
|
|
|
|
|
# `=`, `-`, …) talk to the server via vim-lsp's timer-driven async
|
|
|
|
|
# layer, which doesn't fire reliably inside `vim -e -s`. Those have
|
2026-05-30 18:35:40 +00:00
|
|
|
# Neovim coverage in development/tests/test-keymaps.lua, exercising the same
|
2026-05-12 12:41:46 +00:00
|
|
|
# Lua command layer + server binary.
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
2026-05-30 18:35:40 +00:00
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
2026-05-12 12:41:46 +00:00
|
|
|
TMP="$(mktemp -d -t nuwiki-keymap-vim-test-XXXXXX)"
|
|
|
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
|
|
|
|
|
|
log() { printf '\033[1;34m[keymap-vim]\033[0m %s\n' "$*"; }
|
|
|
|
|
|
|
|
|
|
if ! command -v vim >/dev/null 2>&1; then
|
|
|
|
|
log 'vim not installed — skipping'
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Don't need the LSP binary for the pure-VimL cases, but make sure
|
|
|
|
|
# the autoload file `expand('<sfile>')` resolves correctly when the
|
|
|
|
|
# script-load-time plugin_root capture runs.
|
|
|
|
|
|
|
|
|
|
mkdir -p "$TMP/wiki"
|
|
|
|
|
SEED="$TMP/wiki/index.wiki"
|
|
|
|
|
echo "= seed =" > "$SEED"
|
|
|
|
|
|
|
|
|
|
VIMRC="$TMP/vimrc"
|
|
|
|
|
cat > "$VIMRC" <<EOF
|
|
|
|
|
set nocompatible
|
|
|
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
2026-05-30 18:35:40 +00:00
|
|
|
" Enable the opt-in mouse mappings before the ftplugin loads so the
|
|
|
|
|
" harness can assert the full documented mapping surface (doc §6 mouse).
|
|
|
|
|
let g:nuwiki_mouse_mappings = 1
|
2026-05-12 12:41:46 +00:00
|
|
|
filetype plugin indent on
|
|
|
|
|
syntax enable
|
|
|
|
|
" ftdetect/nuwiki.vim already maps *.wiki → vimwiki via \`set filetype\`.
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
RESULTS="$TMP/results.txt"
|
|
|
|
|
|
|
|
|
|
log "running harness…"
|
2026-05-12 13:17:10 +00:00
|
|
|
# `</dev/null` so Vim's ex-mode doesn't hang waiting on stdin;
|
|
|
|
|
# `timeout` so a misbehaving script can't stall CI for 30 minutes.
|
2026-05-12 12:41:46 +00:00
|
|
|
NUWIKI_KEYMAP_RESULTS="$RESULTS" \
|
2026-05-30 18:35:40 +00:00
|
|
|
timeout 30 vim -e -s -u "$VIMRC" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim.vim" \
|
2026-05-12 13:17:10 +00:00
|
|
|
</dev/null >"$TMP/vim.log" 2>&1 || true
|
2026-05-12 12:41:46 +00:00
|
|
|
|
|
|
|
|
if [[ ! -f "$RESULTS" ]]; then
|
|
|
|
|
echo 'keymap test harness produced no output' >&2
|
|
|
|
|
echo '--- vim log ---' >&2
|
|
|
|
|
cat "$TMP/vim.log" >&2 || true
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat "$RESULTS"
|
|
|
|
|
|
2026-05-30 23:40:29 -03:00
|
|
|
if ! grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS"; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ===== Per-subgroup opt-out run =====
|
|
|
|
|
# Fresh Vim instance with a subset of g:nuwiki_no_<group>_mappings set
|
|
|
|
|
# *before* the ftplugin loads, so we can assert the disabled groups drop
|
|
|
|
|
# their bindings while the rest survive.
|
|
|
|
|
|
|
|
|
|
VIMRC_OPTOUT="$TMP/vimrc-optout"
|
|
|
|
|
cat > "$VIMRC_OPTOUT" <<EOF
|
|
|
|
|
set nocompatible
|
|
|
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
|
|
|
let g:nuwiki_no_wiki_prefix_mappings = 1
|
|
|
|
|
let g:nuwiki_no_links_mappings = 1
|
|
|
|
|
let g:nuwiki_no_headers_mappings = 1
|
|
|
|
|
let g:nuwiki_no_text_objects_mappings = 1
|
|
|
|
|
filetype plugin indent on
|
|
|
|
|
syntax enable
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
RESULTS_OPTOUT="$TMP/results-optout.txt"
|
|
|
|
|
|
|
|
|
|
log "running opt-out harness…"
|
|
|
|
|
NUWIKI_KEYMAP_RESULTS="$RESULTS_OPTOUT" \
|
|
|
|
|
timeout 30 vim -e -s -u "$VIMRC_OPTOUT" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim-optout.vim" \
|
|
|
|
|
</dev/null >"$TMP/vim-optout.log" 2>&1 || true
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$RESULTS_OPTOUT" ]]; then
|
|
|
|
|
echo 'keymap opt-out harness produced no output' >&2
|
|
|
|
|
echo '--- vim log ---' >&2
|
|
|
|
|
cat "$TMP/vim-optout.log" >&2 || true
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat "$RESULTS_OPTOUT"
|
|
|
|
|
|
2026-05-31 19:18:06 +00:00
|
|
|
if ! grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ===== Custom map_prefix run =====
|
|
|
|
|
# Fresh Vim instance with g:nuwiki_map_prefix set *before* the ftplugin
|
|
|
|
|
# loads, so we can assert the whole wiki command family relocates under the
|
|
|
|
|
# custom prefix and nothing remains under the default <Leader>w*.
|
|
|
|
|
|
|
|
|
|
VIMRC_PREFIX="$TMP/vimrc-prefix"
|
|
|
|
|
cat > "$VIMRC_PREFIX" <<EOF
|
|
|
|
|
set nocompatible
|
|
|
|
|
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
|
|
|
|
let g:nuwiki_map_prefix = '<Leader>n'
|
|
|
|
|
filetype plugin indent on
|
|
|
|
|
syntax enable
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
RESULTS_PREFIX="$TMP/results-prefix.txt"
|
|
|
|
|
|
|
|
|
|
log "running custom-prefix harness…"
|
|
|
|
|
NUWIKI_KEYMAP_RESULTS="$RESULTS_PREFIX" \
|
|
|
|
|
timeout 30 vim -e -s -u "$VIMRC_PREFIX" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim-prefix.vim" \
|
|
|
|
|
</dev/null >"$TMP/vim-prefix.log" 2>&1 || true
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$RESULTS_PREFIX" ]]; then
|
|
|
|
|
echo 'keymap custom-prefix harness produced no output' >&2
|
|
|
|
|
echo '--- vim log ---' >&2
|
|
|
|
|
cat "$TMP/vim-prefix.log" >&2 || true
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat "$RESULTS_PREFIX"
|
|
|
|
|
|
|
|
|
|
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_PREFIX"; then
|
2026-05-12 12:41:46 +00:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
exit 1
|