]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: more test for optional and repeatable params
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 12 Dec 2019 09:01:46 +0000 (10:01 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 18 Dec 2019 09:26:15 +0000 (10:26 +0100)
__tests__/matcher/path-parser.spec.ts

index 711e8f15d5e059c6b7bcdbc852826b540f08b081..28f7c8c468e6d18bb5d512bbaa5aeeba32c83e28 100644 (file)
@@ -484,12 +484,30 @@ describe('Path parser', () => {
     })
 
     it('param optional', () => {
-      matchParams('/:a?', '/', {
-        a: '',
-      })
-      matchParams('/:a*', '/', {
-        a: '',
-      })
+      matchParams('/:a?', '/one', { a: 'one' })
+      matchParams('/:a*', '/one', { a: ['one'] })
+    })
+
+    it('empty param optional', () => {
+      matchParams('/:a?', '/', { a: '' })
+      matchParams('/:a*', '/', { a: '' })
+    })
+
+    it('static then param optional', () => {
+      matchParams('/one/:a?', '/one/two', { a: 'two' })
+      matchParams('/one/:a?', '/one/', { a: '' })
+      // can only match one time
+      matchParams('/one/:a?', '/one/two/three', null)
+      matchParams('/one/:a*', '/one/two', { a: ['two'] })
+    })
+
+    it('param optional followed by static', () => {
+      matchParams('/:a?/one', '/two/one', { a: 'two' })
+      // the second one is never matched
+      matchParams('/:a?/one', '/one', null)
+      // can only match one time
+      matchParams('/:a?/one', '/two/three/one', null)
+      matchParams('/:a*/one', '/two/one', { a: ['two'] })
     })
 
     it('param repeatable', () => {
@@ -501,6 +519,21 @@ describe('Path parser', () => {
       })
     })
 
+    it('param repeatable with static', () => {
+      matchParams('/one/:a+', '/one/two', {
+        a: ['two'],
+      })
+      matchParams('/one/:a+', '/one/two/three', {
+        a: ['two', 'three'],
+      })
+      matchParams('/one/:a*', '/one/two', {
+        a: ['two'],
+      })
+      matchParams('/one/:a*', '/one/two/three', {
+        a: ['two', 'three'],
+      })
+    })
+
     // end of parsing urls
   })