11describe ( "UrlMatcher" , function ( ) {
22
3- it ( "shoudl match static URLs" , function ( ) {
3+ describe ( "provider" , function ( ) {
4+
5+ var provider ;
6+
7+ beforeEach ( function ( ) {
8+ angular . module ( 'ui.router.router.test' , function ( ) { } ) . config ( function ( $urlMatcherFactoryProvider ) {
9+ provider = $urlMatcherFactoryProvider ;
10+ } ) ;
11+
12+ module ( 'ui.router.router' , 'ui.router.router.test' ) ;
13+
14+ inject ( function ( $injector ) {
15+ $injector . invoke ( provider . $get ) ;
16+ } ) ;
17+ } ) ;
18+
19+ it ( "should factory matchers with correct configuration" , function ( ) {
20+ provider . caseInsensitive ( false ) ;
21+ expect ( provider . compile ( '/hello' ) . exec ( '/HELLO' ) ) . toBeNull ( ) ;
22+
23+ provider . caseInsensitive ( true ) ;
24+ expect ( provider . compile ( '/hello' ) . exec ( '/HELLO' ) ) . toEqual ( { } ) ;
25+
26+ provider . strictMode ( true ) ;
27+ expect ( provider . compile ( '/hello' ) . exec ( '/hello/' ) ) . toBeNull ( ) ;
28+
29+ provider . strictMode ( false ) ;
30+ expect ( provider . compile ( '/hello' ) . exec ( '/hello/' ) ) . toEqual ( { } ) ;
31+ } ) ;
32+ } ) ;
33+
34+ it ( "should match static URLs" , function ( ) {
435 expect ( new UrlMatcher ( '/hello/world' ) . exec ( '/hello/world' ) ) . toEqual ( { } ) ;
536 } ) ;
637
@@ -14,7 +45,7 @@ describe("UrlMatcher", function () {
1445 expect ( matcher . exec ( '/hello/world/suffix' ) ) . toBeNull ( ) ;
1546 } ) ;
1647
17- it ( "shoudl parse parameter placeholders" , function ( ) {
48+ it ( "should parse parameter placeholders" , function ( ) {
1849 var matcher = new UrlMatcher ( '/users/:id/details/{type}/{repeat:[0-9]+}?from&to' ) ;
1950 var params = matcher . parameters ( ) ;
2051 expect ( params . length ) . toBe ( 5 ) ;
@@ -267,4 +298,27 @@ describe("urlMatcherFactory", function () {
267298 } ) ;
268299 } ) ;
269300 } ) ;
301+
302+ describe ( "strict matching" , function ( ) {
303+ it ( "should match with or without trailing slash" , function ( ) {
304+ var m = new UrlMatcher ( '/users' , { strict : false } ) ;
305+ expect ( m . exec ( '/users' ) ) . toEqual ( { } ) ;
306+ expect ( m . exec ( '/users/' ) ) . toEqual ( { } ) ;
307+ } ) ;
308+
309+ it ( "should not match multiple trailing slashes" , function ( ) {
310+ var m = new UrlMatcher ( '/users' , { strict : false } ) ;
311+ expect ( m . exec ( '/users//' ) ) . toBeNull ( ) ;
312+ } ) ;
313+
314+ it ( "should match when defined with parameters" , function ( ) {
315+ var m = new UrlMatcher ( '/users/{name}' , { strict : false , params : {
316+ name : { value : null }
317+ } } ) ;
318+ expect ( m . exec ( '/users/' ) ) . toEqual ( { name : null } ) ;
319+ expect ( m . exec ( '/users/bob' ) ) . toEqual ( { name : "bob" } ) ;
320+ expect ( m . exec ( '/users/bob/' ) ) . toEqual ( { name : "bob" } ) ;
321+ expect ( m . exec ( '/users/bob//' ) ) . toBeNull ( ) ;
322+ } ) ;
323+ } ) ;
270324} ) ;
0 commit comments