Files
lab-console-neovim/src/tasks/task03_undo_redo.sh
T

11 lines
812 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
work="$(mktemp -d)"; trap 'rm -rf -- "$work"' EXIT
printf 'alpha\nbeta\ngamma\n' >"$work/history.txt"
EVIDENCE="$work/history-counts.txt" nvim --headless -u NONE -n "$work/history.txt" \
'+lua vim.api.nvim_buf_set_lines(0,-1,-1,false,{"delta"}); local a=vim.api.nvim_buf_line_count(0); vim.cmd("silent undo"); local u=vim.api.nvim_buf_line_count(0); vim.cmd("silent redo"); local r=vim.api.nvim_buf_line_count(0); vim.cmd("silent write"); vim.fn.writefile({a.." "..u.." "..r},vim.env.EVIDENCE)' '+qa'
read -r after_change after_undo after_redo <"$work/history-counts.txt"
[[ "$after_change" -eq 4 && "$after_undo" -eq 3 && "$after_redo" -eq 4 ]]
[[ "$(tail -1 "$work/history.txt")" == delta ]]
printf 'PASS task03 after_change=4 after_undo=3 after_redo=4 saved_delta=1\n'