#!/bin/sh
# Check that the JavaScript engine edbrowse is linked against actually works.
# JavaScript is off in the config edbrowse generates on first start, so the
# test turns it on explicitly with js+.
set -e

export HOME="$AUTOPKGTEST_TMP"
cp "$(dirname "$0")/javascript.html" "$AUTOPKGTEST_TMP/javascript.html"

# First start only writes the default config and exits.
printf 'q\n' | edbrowse >/dev/null 2>&1 || true

out=$(printf 'js+\nb\n1,$p\nq\n' | edbrowse "$AUTOPKGTEST_TMP/javascript.html" 2>&1)
printf '%s\n' "$out"

printf '%s\n' "$out" | grep -q 'edbrowse-js-ok-42' || {
	echo "ERROR: DOM assignment did not reach the rendered buffer" >&2
	exit 1
}
printf '%s\n' "$out" | grep -q 'edbrowse-writeln-ok' || {
	echo "ERROR: document.writeln did not reach the rendered buffer" >&2
	exit 1
}
