/*
    test-runner.sesi
    A lightweight test-runner framework for modular Sesi scripts.
    Includes beautiful custom color logs, assertion utilities, and final test suite counters.
*/

let green_tick = "✓ "
let red_cross = "❌ "

export fn assert_equals(actual, expected, testName: string) {
  if actual == expected {
    show green_tick "PASS:" testName
    return true
  } else {
    show red_cross "FAIL:" testName
    show "  -> Expected:" expected
    show "  -> Actual:" actual
    return false
  }
}

export fn assert_not_null(val, testName: string) {
  if val == null {
    show red_cross "FAIL:" testName "(Value is null)"
    return false
  } else {
    show green_tick "PASS:" testName
    return true
  }
}

export fn run_test_suite(suiteName: string, results: array) {
  show "========================================="
  show "   TEST SUITE RUNNER:" suiteName
  show "========================================="
  
  let passed = 0
  let failed = 0
  
  for res in results {
    if res == true {
      passed = passed + 1
    } else {
      failed = failed + 1
    }
  }
  
  show "-----------------------------------------"
  show "📊 Final Summary:"
  show "   Passed:" passed
  show "   Failed:" failed
  
  if failed == 0 {
    show "🎉 ALL TESTS PASSED SUCCESSFULLY!"
  } else {
    show "⚠️ SOME TESTS FAILED. PLEASE AUDIT SPECIFICATIONS."
  }
  show "========================================="
  
  if failed == 0 {
    return true
  }
  return false
}

export fn test_runner() {
  let tool_refs = {}

  fn register_tool(name: string, func, desc: string) {
    define_tool(name, func, desc)
    tool_refs[name] = desc
  }

  register_tool("assert_equals", assert_equals, "Asserts if two values are equal, shows colored PASS/FAIL")
  register_tool("assert_not_null", assert_not_null, "Asserts if a value is not null, shows colored PASS/FAIL")
  register_tool("run_test_suite", run_test_suite, "Runs a test suite and shows a colored summary")
  register_tool("test_runner", test_runner, "Returns a map of all test runner tools")

  let _registry = list_tools()
  show "📦 test-runner tool registry loaded —" str(len(_registry)) "tools available"
  show to_json(tool_refs)
}

test_runner()
