Skip to content

Commit

Permalink
Merge pull request #13 from mimiMonads/0.1.20
Browse files Browse the repository at this point in the history
0.1.20
  • Loading branch information
mimiMonads authored Jun 2, 2024
2 parents 6c89e31 + 5ee2853 commit afcacd2
Show file tree
Hide file tree
Showing 8 changed files with 1,278 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/composer/mainComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions test/components/parameters/finder.test.ts
Original file line number Diff line number Diff line change
@@ -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",
},
),
);
171 changes: 171 additions & 0 deletions test/components/parameters/map.test.ts
Original file line number Diff line number Diff line change
@@ -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: ":",
},
),
);
67 changes: 67 additions & 0 deletions test/components/parameters/multi.test.ts
Original file line number Diff line number Diff line change
@@ -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",
},
),
);
Loading

0 comments on commit afcacd2

Please sign in to comment.