1
1
describe ( "UrlMatcher" , function ( ) {
2
2
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 ( ) {
4
35
expect ( new UrlMatcher ( '/hello/world' ) . exec ( '/hello/world' ) ) . toEqual ( { } ) ;
5
36
} ) ;
6
37
@@ -14,7 +45,7 @@ describe("UrlMatcher", function () {
14
45
expect ( matcher . exec ( '/hello/world/suffix' ) ) . toBeNull ( ) ;
15
46
} ) ;
16
47
17
- it ( "shoudl parse parameter placeholders" , function ( ) {
48
+ it ( "should parse parameter placeholders" , function ( ) {
18
49
var matcher = new UrlMatcher ( '/users/:id/details/{type}/{repeat:[0-9]+}?from&to' ) ;
19
50
var params = matcher . parameters ( ) ;
20
51
expect ( params . length ) . toBe ( 5 ) ;
@@ -267,4 +298,27 @@ describe("urlMatcherFactory", function () {
267
298
} ) ;
268
299
} ) ;
269
300
} ) ;
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
+ } ) ;
270
324
} ) ;
0 commit comments