set -euo pipefail
tests=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
root=$(dirname "$tests")
out="$tests/operators_expected.txt"
data="$tests/cql2testdata.ndjson"
cargo build
cql2="$root/target/debug/cql2"
scratch=$(mktemp)
trap 'rm -f "$scratch"' EXIT
failures=0
while IFS= read -r line; do
q="${line%%#*}"
q="${q#"${q%%[![:space:]]*}"}"
q="${q%"${q##*[![:space:]]}"}"
case "$q" in
'' | //*) continue ;;
esac
if ! matches=$("$cql2" "$q" --filter "$data" | jq -r '.intfield' | paste -sd ' ' -); then
printf 'FAILED: %s\n' "$q" >&2
failures=$((failures + 1))
continue
fi
printf '%s\n%s\n' "$q" "$matches" >> "$scratch"
done < "$tests/operators_tests.txt"
if [ "$failures" -ne 0 ]; then
printf '%s queries failed; %s left unchanged\n' "$failures" "$out" >&2
exit 1
fi
cp "$scratch" "$out"
printf 'wrote %s queries to %s\n' "$(($(wc -l < "$out") / 2))" "$out"