#!/bin/bash
## Checks todos.sh against every case in todos.md.
## Run with TESTMARK_REGEN=1 to update todos.md to match what todos.sh does now; then review the change with `git diff`.
set -euo pipefail
cd "$(dirname "$0")"
source ../lib/testmark.bash

work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

testmark_parse doc todos.md
mapfile -t names < <(testmark_names doc)
fails=0
for name in "${names[@]}"; do
	[[ $name == */input ]] || continue
	case=${name%/input}
	testmark_body doc "$case/input" >"$work/notes.txt"
	if testmark_check doc "$case/output" < <(./todos.sh "$work/notes.txt" | sed "s|$work|WORK|g"); then
		echo "PASS  $case"
	else
		echo "FAIL  $case"
		fails=$((fails + 1))
	fi
done
testmark_write doc
((fails == 0))
