test(router): cover pruning across a static branch and a param sibling

The walk takes the static branch first, so for `GET /a/:rest*` and
`GET /:x/b` it reaches the catch-all on `/a/b` before the exact param
route that outranks it. The corpus has no such pair, and a pruning
bound off by one went unnoticed there. Checked against the oracle in
both declaration orders.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-11 21:00:27 -05:00
1 parent d76afd7f25
commit 55a4e282ad
1 file changed
+16
+16
View File
@@ -92,6 +92,22 @@ describe('radix index: local and remote trees', () => {
});
});
describe('radix index: ranking across branches', () => {
it('lets an exact param route beat a catch-all the walk reached first through a static branch', () => {
// The static branch is walked first and yields the catch-all (rank 1); the param sibling still
// holds the rank-0 exact route, so pruning must not cut it, even by one.
for (const order of [
['/a/:rest*', '/:x/b'],
['/:x/b', '/a/:rest*'],
]) {
const routes = order.map((pattern) => route('GET', pattern));
const expected = oracle.matchRoute(routes, 'GET', '/a/b');
expect(expected?.def.pattern).toBe('/:x/b');
expect(live.matchRoute(routes, 'GET', '/a/b')).toEqual(expected);
}
});
});
describe('radix index: lifetime', () => {
it('rebuilds when the array it was built from changes length', () => {
const routes = [route('GET', '/a')];