Skip to content

Commit 029646f

Browse files
committed
Add matchPattern tests
1 parent 6228524 commit 029646f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*eslint-env mocha */
2+
import expect from 'expect'
3+
import { matchPattern } from '../PatternUtils'
4+
5+
describe('matchPattern', function () {
6+
7+
function assertMatch(pattern, pathname, remainingPathname, paramNames, paramValues) {
8+
expect(matchPattern(pattern, pathname)).toEqual({
9+
remainingPathname,
10+
paramNames,
11+
paramValues
12+
})
13+
}
14+
15+
it('works without params', function () {
16+
assertMatch('/', '/path', 'path', [], [])
17+
})
18+
19+
it('works with named params', function () {
20+
assertMatch('/:id', '/path', '', [ 'id' ], [ 'path' ])
21+
assertMatch('/:id.:ext', '/path.jpg', '', [ 'id', 'ext' ], [ 'path', 'jpg' ])
22+
})
23+
24+
it('works with splat params', function () {
25+
assertMatch('/files/*.*', '/files/path.jpg', '', [ 'splat', 'splat' ], [ 'path', 'jpg' ])
26+
})
27+
28+
it('ignores trailing slashes', function () {
29+
assertMatch('/:id', '/path/', '', [ 'id' ], [ 'path' ])
30+
})
31+
32+
})

0 commit comments

Comments
 (0)