#!/bin/sh

. libtest.sh
. libgit.sh

export LINES=16

git_clone 'repo-one'

test_tig_script() {
	name="$1"; shift

	tig_script "$name" "$@"
	test_tig

	assert_equals "$name.stderr" <<EOF
EOF
}

test_tig_script 'segfault-regression-for-bc4f8e83c590058641c9e1654db300798e9cd106' '
	:view-main
'

view_open_file="view-is-open"
touch -- "$view_open_file"

tigrc <<EOF
bind generic <F1> @sh -c 'echo "view not closed" > "$HOME/$view_open_file"'
EOF

test_tig_script 'view-close-no-quit-should-not-close-tig' '
	:view-close-no-quit
	<F1>
'

assert_equals "$view_open_file" <<EOF
view not closed
EOF

view_closed_file="view-is-closed"
touch -- "$view_closed_file"

tigrc <<EOF
bind generic <F1> @sh -c 'echo "view not closed" > "$HOME/$view_closed_file"'
EOF

test_tig_script 'view-close-should-close-tig' '
	:view-close
	<F1>
'

assert_equals "$view_closed_file" <<EOF
EOF

find . -name "*.stderr" -exec cat -- "{}" \; > stderr
