Skip to content

Commit f87f3c3

Browse files
wip
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4eefb9d commit f87f3c3

4 files changed

Lines changed: 51 additions & 40 deletions

File tree

cpp/tool/synthetic.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { dirname, resolve } from "node:path";
33
import { fileURLToPath } from "node:url";
44
import {
55
compareWithTolerance,
6+
expectUnsupported,
67
getTestCases,
78
writeActualOutput,
89
} from "synthetic-test-utils";
@@ -11,7 +12,7 @@ import { describe, expect, it } from "vitest";
1112
const __dirname = dirname(fileURLToPath(import.meta.url));
1213
const binary = resolve(__dirname, "../build/tool/mlt-cpp-json");
1314

14-
const SKIPPED_TESTS = [];
15+
const SKIPPED_TESTS: string[] = [];
1516

1617
describe("MLT Decoder - Synthetic tests", () => {
1718
expect.addEqualityTesters([compareWithTolerance]);
@@ -28,10 +29,9 @@ describe("MLT Decoder - Synthetic tests", () => {
2829
});
2930
}
3031

31-
for (const skippedTest of testCases.skipped) {
32-
it.skip(skippedTest, () => {
33-
// Test is skipped since it is not supported yet
34-
});
32+
for (const { name, content, fileName } of testCases.skipped) {
33+
it(`${name} (unsupported)`, () =>
34+
expectUnsupported(() => decodeMLT(fileName), content));
3535
}
3636
});
3737

rust/mlt-wasm/js/synthetic.spec.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { VectorTileLike } from "@maplibre/vt-pbf";
33
import { describe, expect, it } from "vitest";
44
import {
55
compareWithTolerance,
6+
expectUnsupported,
67
getTestCases,
78
writeActualOutput,
89
} from "../../../test/synthetic/synthetic-test-utils";
@@ -13,21 +14,7 @@ import {
1314
type MltLayer,
1415
} from "./vectorTile";
1516

16-
const UNIMPLEMENTED_SYNTHETICS = new Map([
17-
["poly_collinear_fpf", "FastPFor not supported"],
18-
["poly_collinear_fpf_tes", "FastPFor not supported"],
19-
["poly_fpf", "FastPFor not supported"],
20-
["poly_fpf_tes", "FastPFor not supported"],
21-
["poly_hole_fpf", "FastPFor not supported"],
22-
["poly_hole_fpf_tes", "FastPFor not supported"],
23-
["poly_hole_touching_fpf", "FastPFor not supported"],
24-
["poly_hole_touching_fpf_tes", "FastPFor not supported"],
25-
["poly_multi_fpf", "FastPFor not supported"],
26-
["poly_multi_fpf_tes", "FastPFor not supported"],
27-
["poly_self_intersect_fpf", "FastPFor not supported"],
28-
["poly_self_intersect_fpf_tes", "FastPFor not supported"],
29-
["poly_multi_morton_hole_morton", "Pending investigation"],
30-
]);
17+
const UNIMPLEMENTED_SYNTHETICS = new Map<string, string>([]);
3118

3219
describe("MLT WASM Decoder - Synthetic tests", () => {
3320
expect.addEqualityTesters([compareWithTolerance]);
@@ -41,10 +28,9 @@ describe("MLT WASM Decoder - Synthetic tests", () => {
4128
});
4229
}
4330

44-
for (const skippedTest of testCases.skipped) {
45-
it.skip(skippedTest, () => {
46-
// Test is skipped since it is not supported yet
47-
});
31+
for (const { name, content, fileName } of testCases.skipped) {
32+
it(`${name} (unsupported: ${UNIMPLEMENTED_SYNTHETICS.get(name)})`, () =>
33+
expectUnsupported(() => decodeMLT(fileName), content));
4834
}
4935
});
5036

test/synthetic/synthetic-test-utils/index.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { globSync, readFileSync, writeFileSync } from "node:fs";
22
import * as path from "node:path";
33
import { dirname, resolve } from "node:path";
44
import { fileURLToPath } from "node:url";
5+
import { expect } from "vitest";
56

67
const __dirname = dirname(fileURLToPath(import.meta.url));
78
const RELATIVE_FLOAT_TOLERANCE = 0.0001 / 100;
@@ -44,29 +45,57 @@ export function writeActualOutput(
4445
return actualFile;
4546
}
4647

48+
export type TestCase = { name: string; content: object; fileName: string };
49+
4750
export function getTestCases(skipList: string[]): {
48-
active: { name: string; content: object; fileName: string }[];
49-
skipped: string[];
51+
active: TestCase[];
52+
skipped: TestCase[];
5053
} {
5154
const syntheticDir = resolve(__dirname, "..");
5255
const mltFiles = globSync(`**/*.mlt`, {
5356
cwd: syntheticDir,
5457
}).map((mltFile: string) => path.join(syntheticDir, mltFile));
5558

56-
const active: { name: string; content: object; fileName: string }[] = [];
57-
const skipped: string[] = [];
59+
const active: TestCase[] = [];
60+
const skipped: TestCase[] = [];
61+
const matched = new Set<string>();
5862

5963
for (const mltFile of mltFiles) {
6064
const testName = path.relative(syntheticDir, mltFile).replace(/\.mlt$/, "");
65+
const jsonFile = mltFile.replace(/\.mlt$/, ".json");
66+
const expected = JSON.parse(readFileSync(jsonFile, "utf-8"));
67+
const testCase = { name: testName, fileName: mltFile, content: expected };
6168
if (skipList.includes(testName)) {
62-
skipped.push(testName);
69+
matched.add(testName);
70+
skipped.push(testCase);
6371
} else {
64-
const jsonFile = mltFile.replace(/\.mlt$/, ".json");
65-
const expectedRaw = readFileSync(jsonFile, "utf-8");
66-
const expected = JSON.parse(expectedRaw);
67-
active.push({ name: testName, fileName: mltFile, content: expected });
72+
active.push(testCase);
6873
}
6974
}
7075

76+
const unmatched = skipList.filter((name) => !matched.has(name));
77+
if (unmatched.length > 0) {
78+
throw new Error(
79+
`Exclusion list references unknown synthetic test(s): ${unmatched.join(", ")}. ` +
80+
`Use the full path-style name, e.g. "0x01/poly_fpf".`,
81+
);
82+
}
83+
7184
return { active, skipped };
7285
}
86+
87+
export async function expectUnsupported(
88+
decode: () => Promise<unknown>,
89+
content: object,
90+
): Promise<void> {
91+
let actual: unknown;
92+
try {
93+
actual = await decode();
94+
} catch {
95+
return;
96+
}
97+
expect(
98+
actual,
99+
"decoded and matched the expected output — remove it from the exclusion list",
100+
).not.toEqual(content);
101+
}

ts/src/synthetic.spec.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import { readFile } from "node:fs/promises";
22
import { describe, expect, it } from "vitest";
33
import { classifyRings } from "@maplibre/maplibre-gl-style-spec";
44
import { GEOMETRY_TYPE } from "./vector/geometry/geometryType";
5-
import { compareWithTolerance, getTestCases, writeActualOutput } from "../../test/synthetic/synthetic-test-utils";
5+
import { compareWithTolerance, expectUnsupported, getTestCases, writeActualOutput } from "../../test/synthetic/synthetic-test-utils";
66
import decodeTile from "./mltDecoder";
77
import type { Geometry } from "./vector/geometry/geometryVector";
88
import type FeatureTable from "./vector/featureTable";
99

1010
const EARCUT_MAX_RINGS = 500;
1111

1212
const UNIMPLEMENTED_SYNTHETICS: string[] = [
13-
"0x01/multipoint_morton",
14-
"0x01/poly_morton_hole_morton",
1513
"0x01/poly_multi_morton_hole_morton",
1614
"0x01/poly_multi_morton_ring_morton",
1715
"0x01/poly_multi_morton_ring_no_morton",
@@ -28,10 +26,8 @@ describe("MLT Decoder - Synthetic tests", () => {
2826
});
2927
}
3028

31-
for (const skippedTest of testCases.skipped) {
32-
it.skip(skippedTest, () => {
33-
// Test is skipped since it is not supported yet
34-
});
29+
for (const { name, content, fileName } of testCases.skipped) {
30+
it(`${name} (unsupported)`, () => expectUnsupported(() => decodeMLT(fileName), content));
3531
}
3632
});
3733

0 commit comments

Comments
 (0)