#!/bin/sh
# Functional test: generate HTML output from AsciiDoc source and verify output
# Note: asciidoc 10.x no longer ships the manpage backend; tests HTML generation instead
set -eu
TMPDIR=$(mktemp -d)
trap 'rm -rf $TMPDIR' EXIT

cat > "$TMPDIR/example.adoc" << 'ADOCEOF'
= Test Document
Test Author
v1.0.0

== Introduction

This is a test document for validating asciidoc functionality.

=== Section

Content here.
ADOCEOF

# Test 1: internal doctest (validates all internal functions)
python3 -m asciidoc.asciidoc --doctest
echo "OK: asciidoc internal doctest passed"

# Test 2: generate HTML output and verify it contains expected content
asciidoc -b html5 -o "$TMPDIR/example.html" "$TMPDIR/example.adoc"
grep -q 'Test Document' "$TMPDIR/example.html" || { echo "FAIL: HTML output missing expected title"; exit 1; }
grep -q 'Introduction' "$TMPDIR/example.html" || { echo "FAIL: HTML output missing section"; exit 1; }
echo "OK: asciidoc HTML generation works"
