// node scripts/test-resolve-path.mjs — the path box resolves like a shell: relative to here, // . and .. applied, trailing slashes dropped, never anything but an absolute path. import { readFileSync } from 'node:fs' const src = readFileSync(new URL('../src/Files.tsx', import.meta.url), 'utf8') const m = src.match(/export function resolvePath[\s\S]*?\n}\n/) if (!m) { console.error('resolvePath not found'); process.exit(1) } const resolvePath = new Function(m[0].replace('export function', 'return function').replace(/: string\[\]/g, '').replace(/: string/g, '') + ' ')() const cases = [ ['/tank/media', '/x', '/tank/media'], ['/tank/media/', '/x', '/tank/media'], ['', '/here', '/here'], [' ', '/here', '/here'], ['sub', '/here', '/here/sub'], ['./sub/', '/here', '/here/sub'], ['..', '/a/b', '/a'], ['../..', '/a/b', '/'], ['../../..', '/a', '/'], ['/', '/a', '/'], ['a//b', '/', '/a/b'], ['/tank/./x/../y', '/', '/tank/y'], ['sp ace #1', '/d', '/d/sp ace #1'], ] let bad = 0 for (const [input, here, want] of cases) { const got = resolvePath(input, here); if (got !== want) { bad++; console.error(`resolvePath(${JSON.stringify(input)}, ${here}) = ${got}, want ${want}`) } } if (bad) process.exit(1) console.log(`resolve path: ok (${cases.length} cases)`)