32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
|
|
// mas-v0.2-spec/conformance/addresses.json, consumed unchanged (CONFORMANCE.md section 2).
|
||
|
|
import { test } from "node:test";
|
||
|
|
import assert from "node:assert/strict";
|
||
|
|
import { readFileSync } from "node:fs";
|
||
|
|
import { parseLocalPart, MasSyntaxError } from "../src/parser.mjs";
|
||
|
|
|
||
|
|
const BUNDLE = new URL("../../../mas-v0.2-spec/", import.meta.url);
|
||
|
|
const fixtures = JSON.parse(readFileSync(new URL("conformance/addresses.json", BUNDLE)));
|
||
|
|
|
||
|
|
for (const f of fixtures) {
|
||
|
|
test(`${f.id} ${JSON.stringify(f.local_part)} (${f.profile})`, () => {
|
||
|
|
let got;
|
||
|
|
try {
|
||
|
|
got = parseLocalPart(f.local_part, f.profile);
|
||
|
|
} catch (e) {
|
||
|
|
assert.ok(e instanceof MasSyntaxError, e);
|
||
|
|
assert.equal(f.valid, false, `rejected (${e.code}) but fixture is valid`);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
assert.equal(f.valid, true, `accepted but fixture is invalid (${f.error})`);
|
||
|
|
const { required_profile, generator_allowed, ...parsed } = got;
|
||
|
|
assert.deepEqual(parsed, f.parsed);
|
||
|
|
if ("generator_allowed" in f) assert.equal(generator_allowed, f.generator_allowed);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
test("a P2 parser also passes every P1 fixture (CONFORMANCE.md 2)", () => {
|
||
|
|
for (const f of fixtures.filter((x) => x.profile === "p1" && x.valid)) {
|
||
|
|
assert.deepEqual((({ required_profile, generator_allowed, ...p }) => p)(parseLocalPart(f.local_part, "p2")), f.parsed);
|
||
|
|
}
|
||
|
|
});
|