From d0adb775f550a68681715e46339b013ba6c8b595 Mon Sep 17 00:00:00 2001 From: mimiMonads Date: Sat, 1 Jun 2024 13:28:48 +0100 Subject: [PATCH 1/2] adding new version and setting up update for `injectHtml` --- package.json | 2 +- src/composer/mainComposer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8cb8f90..a573e0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vixeny", - "version": "0.1.0", + "version": "0.1.20", "description": "A functional router for Bun and Deno", "main": "main.ts", "directories": { diff --git a/src/composer/mainComposer.ts b/src/composer/mainComposer.ts index 6b8f93b..2b5c586 100644 --- a/src/composer/mainComposer.ts +++ b/src/composer/mainComposer.ts @@ -20,7 +20,7 @@ export default ( x.path, o && o.enableLiveReloading //@ts-ignore - ? async (r: Request) => await injectHtml(x.r(r)) + ? async (r: Request) => await injectHtml()(x.r(r)) : x.r, false, ] as unknown as RouteTypes From 5ee28536b1f63898aa89542df5fd655dddf7ea1a Mon Sep 17 00:00:00 2001 From: mimiMonads Date: Sat, 1 Jun 2024 13:55:49 +0100 Subject: [PATCH 2/2] adding parametrs test --- test/components/parameters/finder.test.ts | 60 ++++ test/components/parameters/map.test.ts | 171 +++++++++++ test/components/parameters/multi.test.ts | 67 +++++ test/components/parameters/one.test.ts | 316 ++++++++++++++++++++ test/components/parameters/slicer.test.ts | 342 ++++++++++++++++++++++ test/components/parameters/unique.test.ts | 320 ++++++++++++++++++++ 6 files changed, 1276 insertions(+) create mode 100644 test/components/parameters/finder.test.ts create mode 100644 test/components/parameters/map.test.ts create mode 100644 test/components/parameters/multi.test.ts create mode 100644 test/components/parameters/one.test.ts create mode 100644 test/components/parameters/slicer.test.ts create mode 100644 test/components/parameters/unique.test.ts diff --git a/test/components/parameters/finder.test.ts b/test/components/parameters/finder.test.ts new file mode 100644 index 0000000..c6351cd --- /dev/null +++ b/test/components/parameters/finder.test.ts @@ -0,0 +1,60 @@ +import finder from "../../../src/components/parameters/finder.ts"; +import assert from "node:assert"; +import test from "node:test"; +import map from "../../../src/components/parameters/map.ts"; +import type { Petition } from "../../../src/morphism.ts"; + +test( + "only one parameter at the end and query", + (_) => + assert.deepStrictEqual( + (new Function( + ` return ${ + finder( + map()({ f: (_) => "hello", path: "/test/:id/:hi" } as Petition), + ) + }`, + ))()("456/hi"), + { + hi: "hi", + id: "456", + }, + ), +); + +test( + "only one parameter at the end and query", + (_) => + assert.deepStrictEqual( + (new Function( + ` return ${ + finder( + map()({ f: (_) => "hello", path: "/:test/:id/:hi" } as Petition), + ) + }`, + ))()("test/456/hi"), + { + hi: "hi", + id: "456", + test: "test", + }, + ), +); + +test( + "only one parameter at the end and query", + (_) => + assert.deepStrictEqual( + (new Function( + ` return ${ + finder( + map()({ f: (_) => "hello", path: "/:test/:id/hi" } as Petition), + ) + }`, + ))()("test/456"), + { + id: "456", + test: "test", + }, + ), +); diff --git a/test/components/parameters/map.test.ts b/test/components/parameters/map.test.ts new file mode 100644 index 0000000..e779fd6 --- /dev/null +++ b/test/components/parameters/map.test.ts @@ -0,0 +1,171 @@ +import map from "../../../src/components/parameters/map.ts"; +import assert from "node:assert"; +import test from "node:test"; +import type { Petition } from "../../../src/morphism.ts"; + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/test/:id", f: (_) => "hello" } as Petition), + { + elements: [ + ":id", + ], + endsInSlash: false, + firstParam: 5, + lastParam: 0, + bind: undefined, + list: [ + "test", + ":id", + ], + map: [ + false, + true, + ], + startsWith: ":", + }, + ), +); + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/test/:id/", f: (_) => "hello" } as Petition), + { + elements: [ + ":id", + ], + endsInSlash: true, + firstParam: 5, + lastParam: 1, + bind: undefined, + list: [ + "test", + ":id", + ], + map: [ + false, + true, + ], + startsWith: ":", + }, + ), +); + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/test/:id/hi", f: (_) => "hello" } as Petition), + { + elements: [ + ":id", + ], + endsInSlash: false, + firstParam: 5, + lastParam: 3, + bind: undefined, + list: [ + "test", + ":id", + "hi", + ], + map: [ + false, + true, + false, + ], + startsWith: ":", + }, + ), +); + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition), + { + elements: [ + ":id", + ], + endsInSlash: true, + firstParam: 5, + lastParam: 4, + bind: undefined, + list: [ + "test", + ":id", + "hi", + ], + map: [ + false, + true, + false, + ], + startsWith: ":", + }, + ), +); + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/test/:id/:test", f: (_) => "hello" } as Petition), + { + elements: [ + ":id", + ":test", + ], + endsInSlash: false, + firstParam: 5, + lastParam: 0, + bind: undefined, + list: [ + "test", + ":id", + ":test", + ], + map: [ + false, + true, + true, + ], + startsWith: ":", + }, + ), +); + +test( + "only one parameter at the end", + (_) => + assert.deepStrictEqual( + map({})({ path: "/:test/:id/:hi", f: (_) => "hello" } as Petition), + { + elements: [ + ":test", + ":id", + ":hi", + ], + endsInSlash: false, + firstParam: 0, + lastParam: 0, + bind: undefined, + list: [ + ":test", + ":id", + ":hi", + ], + map: [ + true, + true, + true, + ], + startsWith: ":", + }, + ), +); diff --git a/test/components/parameters/multi.test.ts b/test/components/parameters/multi.test.ts new file mode 100644 index 0000000..ca20163 --- /dev/null +++ b/test/components/parameters/multi.test.ts @@ -0,0 +1,67 @@ +import multi from "../../../src/components/parameters/multi.ts"; +import map from "../../../src/components/parameters/map.ts"; +import assert from "node:assert"; +import test from "node:test"; +import type { Petition } from "../../../src/morphism.ts"; + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + multi( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/:hello", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/world"), + { + hello: "world", + id: "hello", + }, + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + multi( + map({ hasName: "http://localhost:8080/" })({ + path: "/:test/:id/:hello", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/world"), + { + hello: "world", + id: "hello", + test: "test", + }, + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + multi( + map({ hasName: "http://localhost:8080/" })({ + path: "/:test/:id/hello", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/world"), + { + id: "hello", + test: "test", + }, + ), +); diff --git a/test/components/parameters/one.test.ts b/test/components/parameters/one.test.ts new file mode 100644 index 0000000..0f49c29 --- /dev/null +++ b/test/components/parameters/one.test.ts @@ -0,0 +1,316 @@ +import one from "../../../src/components/parameters/one.ts"; +import map from "../../../src/components/parameters/map.ts"; +import assert from "node:assert"; +import test from "node:test"; +import type { Petition } from "../../../src/morphism.ts"; + +// "/test/:id" +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello").id, + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello?a=1").id, + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello").id, + f("http://localhost:8080/test/hello").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello?a=1").id, + f("http://localhost:8080/test/hello?a=1").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/").id, + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/?a=1").id, + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/").id, + f("http://localhost:8080/test/hello/").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/?a=1").id, + f("http://localhost:8080/test/hello/?a=1").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/hi" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi").id, + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi?a=1").id, + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi").id, + f("http://localhost:8080/test/hello/hi").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi?a=1").id, + f("http://localhost:8080/test/hello/hi?a=1").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/hi/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/").id, + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/?a=1").id, + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/").id, + f("http://localhost:8080/test/hello/hi/").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/?a=1").id, + f("http://localhost:8080/test/hello/hi/?a=1").id, + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); diff --git a/test/components/parameters/slicer.test.ts b/test/components/parameters/slicer.test.ts new file mode 100644 index 0000000..227497f --- /dev/null +++ b/test/components/parameters/slicer.test.ts @@ -0,0 +1,342 @@ +import slicer from "../../../src/components/parameters/slicer.ts"; +import map from "../../../src/components/parameters/map.ts"; +import assert from "node:assert"; +import test from "node:test"; +import type { Petition } from "../../../src/morphism.ts"; + +// "/test/:id" +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello"), + "hello", + ), +); + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/"), + f("http://localhost:8080/test/hello/"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + slicer(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/?a=1"), + f("http://localhost:8080/test/hello/?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + slicer(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/hi" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi"), + f("http://localhost:8080/test/hello/hi"), + ], + ["hello", "hello"], + ) + )( + new Function(` return ${ + slicer( + map()({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`)(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi?a=1"), + f("http://localhost:8080/test/hello/hi?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function(` return ${ + slicer( + map()({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`)(), + ), +); + +// "/test/:id/hi/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/"), + f("http://localhost:8080/test/hello/hi/"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + slicer( + map()({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/?a=1"), + f("http://localhost:8080/test/hello/hi/?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + slicer( + map()({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )(), + ), +); + +// "/:test/:id/hi/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/:test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/hello/world/hi/"), + "hello/world", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + slicer( + map({ hasName: "http://localhost:8080/" })({ + path: "/:test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/hello/world/hi/?a=1"), + "hello/world", + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/hello/world/hi/"), + f("http://localhost:8080/hello/world/hi/"), + ], + ["hello/world", "hello/world"], + ) + )( + new Function( + ` return ${ + slicer( + map()({ + path: "/:test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/hello/world/hi/"), + f("http://localhost:8080/hello/world/hi/?a=1"), + ], + ["hello/world", "hello/world"], + ) + )( + new Function( + ` return ${ + slicer( + map()({ + path: "/:test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )(), + ), +); diff --git a/test/components/parameters/unique.test.ts b/test/components/parameters/unique.test.ts new file mode 100644 index 0000000..1279a50 --- /dev/null +++ b/test/components/parameters/unique.test.ts @@ -0,0 +1,320 @@ +import one from "../../../src/components/parameters/unique.ts"; +import map from "../../../src/components/parameters/map.ts"; +import assert from "node:assert"; +import test from "node:test"; +import type { Petition } from "../../../src/morphism.ts"; + +// "/test/:id" +console.log( + one(map()({ path: "/test/:id", f: (_) => "hello" } as Petition)), +); + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello"), + f("http://localhost:8080/test/hello"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello?a=1"), + f("http://localhost:8080/test/hello?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/"), + f("http://localhost:8080/test/hello/"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/?a=1"), + f("http://localhost:8080/test/hello/?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/hi" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi"), + f("http://localhost:8080/test/hello/hi"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi?a=1"), + f("http://localhost:8080/test/hello/hi?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); + +// "/test/:id/hi/" + +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/"), + "hello", + ), +); +test( + "param", + (_) => + assert.deepStrictEqual( + new Function( + ` return ${ + one( + map({ hasName: "http://localhost:8080/" })({ + path: "/test/:id/hi/", + f: (_) => "hello", + } as Petition), + ) + }`, + )()("http://localhost:8080/test/hello/hi/?a=1"), + "hello", + ), +); + +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/"), + f("http://localhost:8080/test/hello/hi/"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +); +test( + "param", + (_) => + ( + (f) => + assert.deepStrictEqual( + [ + f("http://localhost:8080/test/hello/hi/?a=1"), + f("http://localhost:8080/test/hello/hi/?a=1"), + ], + ["hello", "hello"], + ) + )( + new Function( + ` return ${ + one(map()({ path: "/test/:id/hi/", f: (_) => "hello" } as Petition)) + }`, + )(), + ), +);