#!/bin/sh
# debian/tests/functional
set -e

WORKDIR="$AUTOPKGTEST_TMP"

cat > "$WORKDIR/test-input.tex" <<'EOF'
\documentclass{article}
\begin{document}
\section{Introduction}
This is a \textbf{bold} statement and some \emph{emphasized} text.
Here is a \cite{somekey} reference and a \ref{somefig} link.
\end{document}
EOF

untex "$WORKDIR/test-input.tex" > "$WORKDIR/test-output.txt"

if grep -q '\\' "$WORKDIR/test-output.txt"; then
    echo "FAIL, Output still contains LaTeX commands."
    cat "$WORKDIR/test-output.txt"
    exit 1
fi

if ! grep -q 'bold' "$WORKDIR/test-output.txt"; then
    echo "FAIL, 'bold' removed."
    exit 1
fi
if ! grep -q 'emphasized' "$WORKDIR/test-output.txt"; then
    echo "FAIL, 'emphasized' removed."
    exit 1
fi

echo "PASS"
