a textual notation to locate fields within atproto records (draft spec) microcosm.tngl.io/RecordPath/
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 68 lines 1.7 kB view raw
1import { describe, it, expect } from 'vitest'; 2import { readFileSync } from 'node:fs'; 3import { join, dirname } from 'node:path'; 4import { fileURLToPath } from 'node:url'; 5import { match, enumerate, parse, isVector, type PathInfo } from '../src/index.js'; 6 7const __dirname = dirname(fileURLToPath(import.meta.url)); 8const fixturesDir = join(__dirname, '..', '..', 'interop-tests'); 9 10function loadFixture(name: string) { 11 return JSON.parse(readFileSync(join(fixturesDir, name), 'utf-8')); 12} 13 14// -- Match tests -- 15 16const matchFixture = loadFixture('match.json'); 17 18describe('match', () => { 19 for (const t of matchFixture.tests) { 20 it(t.description, () => { 21 const result = match(t.record, t.path); 22 expect(result).toEqual(t.expected); 23 }); 24 } 25}); 26 27// -- Enumerate tests -- 28 29const enumFixture = loadFixture('enumerate.json'); 30 31describe('enumerate', () => { 32 for (const t of enumFixture.tests) { 33 it(t.description, () => { 34 // Compare as sets of {path, type} 35 const resultSet = new Set( 36 Array.from(enumerate(t.record), ([p]) => `${p.path}:${p.type}`) 37 ); 38 const expectedSet = new Set( 39 t.expected.map((p: { path: string; type: string }) => `${p.path}:${p.type}`) 40 ); 41 42 expect(resultSet).toEqual(expectedSet); 43 }); 44 } 45}); 46 47// -- Parse type classification tests -- 48 49const parseFixture = loadFixture('parse.json'); 50 51describe('type classification', () => { 52 for (const t of parseFixture.type_tests) { 53 it(t.description, () => { 54 const result = isVector(t.path) ? 'vector' : 'scalar'; 55 expect(result).toBe(t.type); 56 }); 57 } 58}); 59 60// -- Parse validity tests -- 61 62describe('invalid paths', () => { 63 for (const t of parseFixture.invalid_tests) { 64 it(t.description, () => { 65 expect(() => parse(t.path)).toThrow(); 66 }); 67 } 68});