import test from "node:test";
import assert from "node:assert/strict";
import { clamp, createEmitter } from "../src/index.js";

test("clamp keeps value within bounds", () => {
  assert.equal(clamp(5, 0, 10), 5);
  assert.equal(clamp(-1, 0, 10), 0);
  assert.equal(clamp(99, 0, 10), 10);
});

test("createEmitter registers and emits", () => {
  const emitter = createEmitter();
  /** @type {Array<string>} */
  const events = [];

  const off = emitter.on((payload) => events.push(payload));
  emitter.emit("confirm");
  off();
  emitter.emit("cancel");

  assert.deepEqual(events, ["confirm"]);
});
