Skip to content

Commit

Permalink
Add matchPattern tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Sep 25, 2015
1 parent 6228524 commit 029646f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/__tests__/PatternUtils-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*eslint-env mocha */
import expect from 'expect'
import { matchPattern } from '../PatternUtils'

describe('matchPattern', function () {

function assertMatch(pattern, pathname, remainingPathname, paramNames, paramValues) {
expect(matchPattern(pattern, pathname)).toEqual({
remainingPathname,
paramNames,
paramValues
})
}

it('works without params', function () {
assertMatch('/', '/path', 'path', [], [])
})

it('works with named params', function () {
assertMatch('/:id', '/path', '', [ 'id' ], [ 'path' ])
assertMatch('/:id.:ext', '/path.jpg', '', [ 'id', 'ext' ], [ 'path', 'jpg' ])
})

it('works with splat params', function () {
assertMatch('/files/*.*', '/files/path.jpg', '', [ 'splat', 'splat' ], [ 'path', 'jpg' ])
})

it('ignores trailing slashes', function () {
assertMatch('/:id', '/path/', '', [ 'id' ], [ 'path' ])
})

})

0 comments on commit 029646f

Please sign in to comment.