From: Eduardo San Martin Morote Date: Thu, 12 Dec 2019 09:01:46 +0000 (+0100) Subject: test: more test for optional and repeatable params X-Git-Tag: v4.0.0-alpha.0~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc84c62cd3c5afcbbbe3744b7a2a251eae1b45a8;p=thirdparty%2Fvuejs%2Frouter.git test: more test for optional and repeatable params --- diff --git a/__tests__/matcher/path-parser.spec.ts b/__tests__/matcher/path-parser.spec.ts index 711e8f15..28f7c8c4 100644 --- a/__tests__/matcher/path-parser.spec.ts +++ b/__tests__/matcher/path-parser.spec.ts @@ -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 })