import { describe, expect, it } from "vitest"; import { parseMw, parseAllMw, parseMoney, parsePartialDate, inferStatus, normalizeStatus, countryFromText, parseAreaSqm } from "./normalize.js"; describe("parseMw", () => { it("parses plain figures and units", () => { expect(parseMw("36 MW")).toBe(36); expect(parseMw("36MW")).toBe(36); expect(parseMw("120 megawatts")).toBe(120); expect(parseMw("1.2 GW")).toBe(1200); expect(parseMw("36,000 kW")).toBe(36); expect(parseMw("40+MW")).toBe(40); }); it("treats a single dot followed by three digits as a decimal (DataBank 0.779MW regression)", () => { expect(parseMw("0.779MW Critical IT Load")).toBe(0.779); expect(parseMw("1.250 MW")).toBe(1.25); expect(parseMw("2.500MW")).toBe(2.5); }); it("still reads European thousands with two or more groups", () => { expect(parseMw("1.500.000 kW")).toBe(1500); }); it("reads a comma decimal", () => { expect(parseMw("1,2 GW")).toBe(1200); }); it("returns null without a unit", () => { expect(parseMw("300 million")).toBeNull(); expect(parseMw(null)).toBeNull(); }); }); describe("parseAllMw", () => { it("dedupes and sorts descending, drops absurd figures", () => { expect(parseAllMw("a 36 MW hall in a 300MW campus, 36 MW again, 500,000 MW nonsense")).toEqual([300, 36]); }); }); describe("parseMoney", () => { it("parses currencies and multipliers", () => { expect(parseMoney("$1.2 billion")).toEqual({ amount: 1_200_000_000, currency: "USD" }); expect(parseMoney("€800m")).toEqual({ amount: 800_000_000, currency: "EUR" }); expect(parseMoney("£2bn")).toEqual({ amount: 2_000_000_000, currency: "GBP" }); expect(parseMoney("US$450 million")).toEqual({ amount: 450_000_000, currency: "USD" }); }); }); describe("parsePartialDate", () => { it("handles partial dates", () => { expect(parsePartialDate("Q2 2027")).toBe("2027-Q2"); expect(parsePartialDate("June 2027")).toBe("2027-06"); expect(parsePartialDate("2027")).toBe("2027"); expect(parsePartialDate("15 June 2027")).toBe("2027-06-15"); }); }); describe("status", () => { it("infers and normalizes statuses", () => { expect(inferStatus("breaks ground on new campus")).toBe("under_construction"); expect(inferStatus("planning application submitted")).toBe("permitting"); expect(normalizeStatus("Under Construction")).toBe("under_construction"); expect(normalizeStatus("coming soon")).toBe("announced"); }); }); describe("misc", () => { it("country from text and areas", () => { expect(countryFromText("a campus in the Netherlands")).toBe("NL"); expect(parseAreaSqm("8,170 Square Feet")).toBe(759.0); }); });