'/a/:b/c',
'/a/:b',
'/a',
+ '/:a/:b',
+ '/:w',
+ '/:w+',
// '/:a/-:b',
// '/:a/:b',
// '/a-:b',
})
})
+ it('sensitive should go before non sensitive', () => {
+ checkPathOrder([
+ ['/Home', { sensitive: true }],
+ ['/home', {}],
+ ])
+ checkPathOrder([
+ ['/:w', { sensitive: true }],
+ ['/:w', {}],
+ ])
+ })
+
+ it('strict should go before non strict', () => {
+ checkPathOrder([
+ ['/home', { strict: true }],
+ ['/home', {}],
+ ])
+ })
+
it('orders repeteable and optional', () => {
- checkPathOrder(['/:w', '/:w+'])
+ possibleOptions.forEach(options => {
+ checkPathOrder(['/:w', ['/:w?', options]])
+ checkPathOrder(['/:w?', ['/:w+', options]])
+ checkPathOrder(['/:w?', ['/:w*', options]])
+ })
})
it('orders static before params', () => {
- checkPathOrder(['/a', '/:id'])
+ possibleOptions.forEach(options => {
+ checkPathOrder(['/a', ['/:id', options]])
+ })
})
it('empty path before slash', () => {
- checkPathOrder(['', '/'])
+ possibleOptions.forEach(options => {
+ checkPathOrder(['', ['/', options]])
+ })
})
it('works with long paths', () => {
'/a/b',
])
- // does this really make sense?
- // checkPathOrder([['/a/', { strict: true }], '/a/'])
- // checkPathOrder([['/a', { strict: true }], '/a'])
+ checkPathOrder([['/a/', { strict: true }], '/a/'])
+ checkPathOrder([['/a', { strict: true }], '/a'])
})
it('puts the wildcard at the end', () => {
: PathScore.Segment
: PathScore.Root
+ if (options.sensitive) segmentScore += PathScore.BonusCaseSensitive
+
for (let tokenIndex = 0; tokenIndex < segment.length; tokenIndex++) {
const token = segment[tokenIndex]
if (token.type === TokenType.Static) {
score.push(segmentScore)
}
+ // only apply the strict bonus to the last score
+ if (options.strict) score[score.length - 1] += PathScore.BonusStrict
+
// TODO: warn double trailing slash
if (!options.strict) pattern += '/?'