# Erlang-on-SX conformance config — sourced by lib/guest/conformance.sh.
#
# Erlang's suites load into one session and each exposes a pass counter and a
# *count* (total) counter — not a fail counter. dict mode fits cleanly: each
# runner is a dict literal computing :failed as count - pass. (counters mode
# would misread the count counter as a fail counter.)

LANG_NAME=erlang
MODE=dict

PRELOADS=(
  lib/erlang/tokenizer.sx
  lib/erlang/parser.sx
  lib/erlang/parser-core.sx
  lib/erlang/parser-expr.sx
  lib/erlang/parser-module.sx
  lib/erlang/transpile.sx
  lib/erlang/runtime.sx
  lib/erlang/vm/dispatcher.sx
)

# name:file:(runner) — runner is a dict literal {:passed :failed :total}.
SUITES=(
  "tokenize:lib/erlang/tests/tokenize.sx:{:passed er-test-pass :failed (- er-test-count er-test-pass) :total er-test-count}"
  "parse:lib/erlang/tests/parse.sx:{:passed er-parse-test-pass :failed (- er-parse-test-count er-parse-test-pass) :total er-parse-test-count}"
  "eval:lib/erlang/tests/eval.sx:{:passed er-eval-test-pass :failed (- er-eval-test-count er-eval-test-pass) :total er-eval-test-count}"
  "runtime:lib/erlang/tests/runtime.sx:{:passed er-rt-test-pass :failed (- er-rt-test-count er-rt-test-pass) :total er-rt-test-count}"
  "ring:lib/erlang/tests/programs/ring.sx:{:passed er-ring-test-pass :failed (- er-ring-test-count er-ring-test-pass) :total er-ring-test-count}"
  "ping-pong:lib/erlang/tests/programs/ping_pong.sx:{:passed er-pp-test-pass :failed (- er-pp-test-count er-pp-test-pass) :total er-pp-test-count}"
  "bank:lib/erlang/tests/programs/bank.sx:{:passed er-bank-test-pass :failed (- er-bank-test-count er-bank-test-pass) :total er-bank-test-count}"
  "echo:lib/erlang/tests/programs/echo.sx:{:passed er-echo-test-pass :failed (- er-echo-test-count er-echo-test-pass) :total er-echo-test-count}"
  "fib:lib/erlang/tests/programs/fib_server.sx:{:passed er-fib-test-pass :failed (- er-fib-test-count er-fib-test-pass) :total er-fib-test-count}"
  "ffi:lib/erlang/tests/ffi.sx:{:passed er-ffi-test-pass :failed (- er-ffi-test-count er-ffi-test-pass) :total er-ffi-test-count}"
  "vm:lib/erlang/tests/vm.sx:{:passed er-vm-test-pass :failed (- er-vm-test-count er-vm-test-pass) :total er-vm-test-count}"
)

# Preserve the historical scoreboard schema so consumers of
# lib/erlang/scoreboard.json keep working.
emit_scoreboard_json() {
  local n=${#GC_NAMES[@]} i status
  printf '{\n'
  printf '  "language": "erlang",\n'
  printf '  "total_pass": %d,\n' "$GC_TOTAL_PASS"
  printf '  "total": %d,\n' "$GC_TOTAL"
  printf '  "suites": ['
  for ((i=0; i<n; i++)); do
    [ "$i" -gt 0 ] && printf ','
    status="ok"; [ "${GC_FAIL[$i]}" -gt 0 ] && status="fail"
    printf '\n    {"name":"%s","pass":%d,"total":%d,"status":"%s"}' \
      "${GC_NAMES[$i]}" "${GC_PASS[$i]}" "${GC_TOTAL_S[$i]}" "$status"
  done
  printf '\n  ]\n'
  printf '}\n'
}

emit_scoreboard_md() {
  local n=${#GC_NAMES[@]} i marker
  printf '# Erlang-on-SX Scoreboard\n\n'
  printf '**Total: %d / %d tests passing**\n\n' "$GC_TOTAL_PASS" "$GC_TOTAL"
  printf '|  | Suite | Pass | Total |\n'
  printf '|---|---|---|---|\n'
  for ((i=0; i<n; i++)); do
    marker="✅"; [ "${GC_FAIL[$i]}" -gt 0 ] && marker="❌"
    printf '| %s | %s | %d | %d |\n' \
      "$marker" "${GC_NAMES[$i]}" "${GC_PASS[$i]}" "${GC_TOTAL_S[$i]}"
  done
  printf '\nGenerated by `lib/erlang/conformance.sh`.\n'
}
