···11+import { describe, it, expect } from 'vitest';
22+import { readFileSync } from 'node:fs';
33+import { join, dirname } from 'node:path';
44+import { fileURLToPath } from 'node:url';
55+import { match, enumerate, parse, isVector, type PathInfo } from '../src/index.js';
66+77+const __dirname = dirname(fileURLToPath(import.meta.url));
88+const fixturesDir = join(__dirname, '..', '..', 'interop-tests');
99+1010+function loadFixture(name: string) {
1111+ return JSON.parse(readFileSync(join(fixturesDir, name), 'utf-8'));
1212+}
1313+1414+// -- Match tests --
1515+1616+const matchFixture = loadFixture('match.json');
1717+1818+describe('match', () => {
1919+ for (const t of matchFixture.tests) {
2020+ it(t.description, () => {
2121+ const result = match(t.record, t.path);
2222+ expect(result).toEqual(t.expected);
2323+ });
2424+ }
2525+});
2626+2727+// -- Enumerate tests --
2828+2929+const enumFixture = loadFixture('enumerate.json');
3030+3131+describe('enumerate', () => {
3232+ for (const t of enumFixture.tests) {
3333+ it(t.description, () => {
3434+ const result = enumerate(t.record);
3535+3636+ // Compare as sets of {path, type}
3737+ const resultSet = new Set(result.map((p: PathInfo) => `${p.path}:${p.type}`));
3838+ const expectedSet = new Set(
3939+ t.expected.map((p: { path: string; type: string }) => `${p.path}:${p.type}`)
4040+ );
4141+4242+ expect(resultSet).toEqual(expectedSet);
4343+ });
4444+ }
4545+});
4646+4747+// -- Parse type classification tests --
4848+4949+const parseFixture = loadFixture('parse.json');
5050+5151+describe('type classification', () => {
5252+ for (const t of parseFixture.type_tests) {
5353+ it(t.description, () => {
5454+ const result = isVector(t.path) ? 'vector' : 'scalar';
5555+ expect(result).toBe(t.type);
5656+ });
5757+ }
5858+});
5959+6060+// -- Parse validity tests --
6161+6262+describe('invalid paths', () => {
6363+ for (const t of parseFixture.invalid_tests) {
6464+ it(t.description, () => {
6565+ expect(() => parse(t.path)).toThrow();
6666+ });
6767+ }
6868+});
+2
spec.md
···233233234234- lexicon awareness notes
235235 - backlinks example: match links on non-link fields if they happen to parse
236236+237237+- bring back the expected order of matches: depth-first-search order (probably as a "should")