From: Eduardo San Martin Morote Date: Wed, 18 Dec 2019 09:01:40 +0000 (+0100) Subject: test(parser): add back the compare tests X-Git-Tag: v4.0.0-alpha.0~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52f49c49cf004da963e293c3adf92a315db068fc;p=thirdparty%2Fvuejs%2Frouter.git test(parser): add back the compare tests --- diff --git a/__tests__/matcher/path-ranking.spec.ts b/__tests__/matcher/path-ranking.spec.ts index 0e0cf5e3..d1beab9d 100644 --- a/__tests__/matcher/path-ranking.spec.ts +++ b/__tests__/matcher/path-ranking.spec.ts @@ -7,20 +7,43 @@ import { type PathParserOptions = Parameters[1] describe('Path ranking', () => { - describe.skip('comparePathParser', () => { - // it('same length', () => { - // expect(comparePathParserScore([[2]], [[3]])).toEqual(1) - // expect(comparePathParserScore([2], [2])).toEqual(0) - // expect(comparePathParserScore([4], [3])).toEqual(-1) - // }) - // it('longer', () => { - // expect(comparePathParserScore([2], [3, 1])).toEqual(1) - // // TODO: we are assuming we never pass end: false - // expect(comparePathParserScore([3], [3, 1])).toEqual(1) - // expect(comparePathParserScore([1, 3], [2])).toEqual(1) - // expect(comparePathParserScore([4], [3])).toEqual(-1) - // expect(comparePathParserScore([], [3])).toEqual(1) - // }) + describe('comparePathParser', () => { + function compare(a: number[][], b: number[][]): number { + return comparePathParserScore( + { + score: a, + re: /a/, + // @ts-ignore + stringify: v => v, + // @ts-ignore + parse: v => v, + keys: [], + }, + { + score: b, + re: /a/, + // @ts-ignore + stringify: v => v, + // @ts-ignore + parse: v => v, + keys: [], + } + ) + } + + it('same length', () => { + expect(compare([[2]], [[3]])).toEqual(1) + expect(compare([[2]], [[2]])).toEqual(0) + expect(compare([[4]], [[3]])).toEqual(-1) + }) + it('longer', () => { + expect(compare([[2]], [[3, 1]])).toEqual(1) + // TODO: we are assuming we never pass end: false + expect(compare([[3]], [[3, 1]])).toEqual(1) + expect(compare([[1, 3]], [[2]])).toEqual(1) + expect(compare([[4]], [[3]])).toEqual(-1) + expect(compare([], [[3]])).toEqual(1) + }) }) const possibleOptions: PathParserOptions[] = [