34 lines
743 B
JavaScript
34 lines
743 B
JavaScript
|
import assert from 'assert'
|
||
|
import { compilePaths } from "./router_v2.mjs"
|
||
|
import * as consts from './const.js'
|
||
|
|
||
|
let paths = [
|
||
|
{ path: '/aa/aa', },
|
||
|
{ path: '/aa/:blabla', },
|
||
|
{ path: '/::rest', },
|
||
|
]
|
||
|
|
||
|
// paths = consts.allManyRoutes.map(x => ({ path: x }))
|
||
|
|
||
|
let tests = [
|
||
|
['/', paths[5]],
|
||
|
['/aa', paths[5]],
|
||
|
['/aa/aa', paths[0]],
|
||
|
['/aa/_', paths[1]],
|
||
|
['/aa/_/aa', paths[2]],
|
||
|
['/aa/_/ab', paths[3]],
|
||
|
['/aa/_/bb', paths[4]],
|
||
|
]
|
||
|
|
||
|
tests = paths.map(p => ([p.path.replace(/:[^/]+/g, '_'), p]))
|
||
|
|
||
|
let func = compilePaths(paths)
|
||
|
for (let [_, fun] of func) {
|
||
|
console.log(`--- ${fun.name} ---`)
|
||
|
for (let test of tests) {
|
||
|
let check = fun(test[0])
|
||
|
console.log(test[0], check)
|
||
|
assert.strictEqual(check.path, test[1])
|
||
|
}
|
||
|
}
|