// mas-v0.2-spec/conformance/statute-aware.json, consumed unchanged (CONFORMANCE.md section 5). import { test } from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { Statute, interpret, equivalent, forDestination, CannotExpress } from "../src/statute.mjs"; const BUNDLE = new URL("../../../mas-v0.2-spec/", import.meta.url); const fx = JSON.parse(readFileSync(new URL("conformance/statute-aware.json", BUNDLE))); const statutes = Object.fromEntries(Object.entries(fx.statutes).map(([k, d]) => [k, new Statute(d)])); for (const c of fx.interpretation) { test(`${c.id} interpret ${c.local_part}`, () => { const r = interpret(c.local_part, statutes[c.statute]); assert.deepEqual([r.canonical, r.stand_ins], [c.canonical, c.stand_ins]); }); } for (const c of fx.equivalence) { test(`${c.id} ${c.a} ~ ${c.b}`, () => { assert.equal(equivalent(c.a, c.b, statutes[c.statute]), c.equivalent); }); } for (const c of fx.destination) { test(`${c.id} ${c.local_part} for [${c.needs}]`, () => { const run = () => forDestination(c.local_part, statutes[c.statute], c.needs, { allowLossy: c.allow_lossy ?? false }); if (c.expect === null) assert.throws(run, CannotExpress, c.reason); else assert.equal(run(), c.expect); }); }