#!/bin/sh

. libtest.sh

export LINES=10

# Disable built-in configuration
export TIGRC_SYSTEM=does-not-exist

file "$HOME/.tigrc.bind.q.for.help.screen" <<EOF
bind generic q quit
EOF

test_case source-file-plain \
	--args='status' \
	--tigrc="
		bind generic : prompt
		source $HOME/.tigrc.bind.q.for.help.screen
		" \
	--script="
		:view-help
		" \
	<<EOF
Quick reference for tig keybindings:
[-] Collapse all sections

[-] generic bindings
View manipulation
  q quit   Close all views and quit
Misc
  : prompt Open the prompt
[help] - line 1 of 28                                                        28%
EOF

test_case source-file-quietly \
	--args='status' \
	--tigrc="
		bind generic : prompt
		source -q $HOME/.tigrc.bind.q.for.help.screen
		" \
	--script="
		:view-help
		" \
	<<EOF
Quick reference for tig keybindings:
[-] Collapse all sections

[-] generic bindings
View manipulation
  q quit   Close all views and quit
Misc
  : prompt Open the prompt
[help] - line 1 of 28                                                        28%
EOF

test_case source-nonexistent-file \
	--args='status' \
	--tigrc="
		bind generic : prompt
		source $HOME/.tigrc.nonexistent.file
		" \
	--script="
		:view-help
		" \
	--assert-stderr="tig warning: ~/.tigrc:3: File does not exist: HOME/.tigrc.nonexistent.file
tig warning: Errors while loading HOME/.tigrc." \
	<<EOF
Quick reference for tig keybindings:
[-] Collapse all sections

[-] generic bindings
Misc
  : prompt Open the prompt
[-] toggle bindings
Toggle keys (enter: o <key>):
[help] - line 1 of 26                                                        30%
EOF

test_case source-nonexistent-file-quietly \
	--args='status' \
	--tigrc="
		bind generic : prompt
		source -q $HOME/.tigrc.nonexistent.file
		" \
	--script="
		:view-help
		" \
	<<EOF
Quick reference for tig keybindings:
[-] Collapse all sections

[-] generic bindings
Misc
  : prompt Open the prompt
[-] toggle bindings
Toggle keys (enter: o <key>):
[help] - line 1 of 26                                                        30%
EOF

test_case source-tilde-path \
	--args='status' \
	--tigrc="
		bind generic : prompt
		source ~/.tigrc.bind.q.for.help.screen
		" \
	--script="
		:view-help
		" \
	<<EOF
Quick reference for tig keybindings:
[-] Collapse all sections

[-] generic bindings
View manipulation
  q quit   Close all views and quit
Misc
  : prompt Open the prompt
[help] - line 1 of 28                                                        28%
EOF

run_test_cases
