import { describe, it, expect } from 'vitest'; import { readFileSync } from 'node:fs'; import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { match, enumerate, parse, isVector, type PathInfo } from '../src/index.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); const fixturesDir = join(__dirname, '..', '..', 'interop-tests'); function loadFixture(name: string) { return JSON.parse(readFileSync(join(fixturesDir, name), 'utf-8')); } // -- Match tests -- const matchFixture = loadFixture('match.json'); describe('match', () => { for (const t of matchFixture.tests) { it(t.description, () => { const result = match(t.record, t.path); expect(result).toEqual(t.expected); }); } }); // -- Enumerate tests -- const enumFixture = loadFixture('enumerate.json'); describe('enumerate', () => { for (const t of enumFixture.tests) { it(t.description, () => { const result = enumerate(t.record); // Compare as sets of {path, type} const resultSet = new Set(result.map((p: PathInfo) => `${p.path}:${p.type}`)); const expectedSet = new Set( t.expected.map((p: { path: string; type: string }) => `${p.path}:${p.type}`) ); expect(resultSet).toEqual(expectedSet); }); } }); // -- Parse type classification tests -- const parseFixture = loadFixture('parse.json'); describe('type classification', () => { for (const t of parseFixture.type_tests) { it(t.description, () => { const result = isVector(t.path) ? 'vector' : 'scalar'; expect(result).toBe(t.type); }); } }); // -- Parse validity tests -- describe('invalid paths', () => { for (const t of parseFixture.invalid_tests) { it(t.description, () => { expect(() => parse(t.path)).toThrow(); }); } });