]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test(parser): add back the compare tests
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 18 Dec 2019 09:01:40 +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-ranking.spec.ts

index 0e0cf5e3d46ccbbfc32fc21ef3c228525d5fc08e..d1beab9d996280f1e55cbd245dc049dcf795ca33 100644 (file)
@@ -7,20 +7,43 @@ import {
 type PathParserOptions = Parameters<typeof tokensToParser>[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[] = [