#!/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
	case $name in
	*/input)
		case=${name%/input}
		testmark_body doc "$name" >"$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
		;;
	esac
done
testmark_write doc
((fails == 0))
