import { test, expect } from "bun:test";
import {
  formatNumber,
  formatCurrency,
  formatDate,
  formatRelativeTime,
  plural,
} from "../src/index.ts";

test("formatNumber is locale-aware", () => {
  expect(formatNumber(1234.5, "en-US")).toBe("1,234.5");
  expect(formatNumber(1234.5, "de-DE")).toBe("1.234,5");
});

test("formatCurrency", () => {
  expect(formatCurrency(9.99, "USD", "en-US")).toBe("$9.99");
});

test("formatDate", () => {
  const out = formatDate("2026-01-15T00:00:00Z", "en-US", { dateStyle: "medium", timeZone: "UTC" });
  expect(out).toContain("2026");
  expect(out).toContain("Jan");
});

test("formatRelativeTime", () => {
  expect(formatRelativeTime(-1, "day", "en-US")).toBe("yesterday");
  expect(formatRelativeTime(3, "hour", "en-US")).toBe("in 3 hours");
});

test("plural picks the CLDR form and fills #", () => {
  const forms = { one: "# item", other: "# items" };
  expect(plural(1, forms, "en")).toBe("1 item");
  expect(plural(5, forms, "en")).toBe("5 items");
  expect(plural(0, forms, "en")).toBe("0 items");
});
