Skip to content

Commit

Permalink
Merge pull request #10 from ngrx/test/match-pattern
Browse files Browse the repository at this point in the history
test(MatchPattern): Added unit tests for match pattern
  • Loading branch information
brandonroberts committed Mar 30, 2016
2 parents 69d083a + 857e181 commit 91fdfab
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/match-pattern.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { matchPattern } from '../lib/match-pattern'

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 named params that contain spaces', function() {
assertMatch('/:id', '/path+more', '', [ 'id' ], [ 'path+more' ]);
assertMatch('/:id', '/path%20more', '', [ 'id' ], [ 'path more' ]);
});

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' ]);
});

it('works with greedy splat (**)', function() {
assertMatch('/**/g', '/greedy/is/good/g', '', [ 'splat' ], [ 'greedy/is/good' ]);
});

it('works with greedy and non-greedy splat', function() {
assertMatch('/**/*.jpg', '/files/path/to/file.jpg', '', [ 'splat', 'splat' ], [ 'files/path/to', 'file' ]);
});
});

0 comments on commit 91fdfab

Please sign in to comment.