( t: Deno.TestContext, filename: string, )
| 901 | |
| 902 | // Load and run tests from a JSON file |
| 903 | async function runConformanceTests( |
| 904 | t: Deno.TestContext, |
| 905 | filename: string, |
| 906 | ): Promise<void> { |
| 907 | const testData = await import(`./testdata/structured_fields/${filename}`, { |
| 908 | with: { type: "json" }, |
| 909 | }); |
| 910 | const tests: ConformanceTestCase[] = testData.default; |
| 911 | |
| 912 | for (const test of tests) { |
| 913 | // Skip tests marked can_fail (implementation-dependent) |
| 914 | if (test.can_fail) continue; |
| 915 | |
| 916 | const rawInput = test.raw.join(", "); |
| 917 | const headerType = test.header_type ?? "item"; |
| 918 | |
| 919 | await t.step(test.name, () => { |
| 920 | if (test.must_fail) { |
| 921 | // Test should fail parsing |
| 922 | assertThrows( |
| 923 | () => { |
| 924 | switch (headerType) { |
| 925 | case "item": |
| 926 | parseItem(rawInput); |
| 927 | break; |
| 928 | case "list": |
| 929 | parseList(rawInput); |
| 930 | break; |
| 931 | case "dictionary": |
| 932 | parseDictionary(rawInput); |
| 933 | break; |
| 934 | } |
| 935 | }, |
| 936 | Error, |
| 937 | ); |
| 938 | } else { |
| 939 | // Test should succeed |
| 940 | switch (headerType) { |
| 941 | case "item": { |
| 942 | const parsed = parseItem(rawInput); |
| 943 | const expected = convertExpectedItem(test.expected); |
| 944 | assertEquals( |
| 945 | itemsEqual(parsed, expected), |
| 946 | true, |
| 947 | `Mismatch for "${test.name}": got ${ |
| 948 | JSON.stringify(parsed) |
| 949 | }, expected ${JSON.stringify(expected)}`, |
| 950 | ); |
| 951 | // Test canonical serialization if provided |
| 952 | if (test.canonical) { |
| 953 | const serialized = serializeItem(parsed); |
| 954 | assertEquals(serialized, test.canonical[0]); |
| 955 | } |
| 956 | break; |
| 957 | } |
| 958 | case "list": { |
| 959 | const parsed = parseList(rawInput); |
| 960 | const expected: List = test.expected.map( |
no test coverage detected