Skip to content

Commit

Permalink
adding parametrs test
Browse files Browse the repository at this point in the history
  • Loading branch information
mimiMonads committed Jun 1, 2024
1 parent d0adb77 commit 5ee2853
Show file tree
Hide file tree
Showing 6 changed files with 1,276 additions and 0 deletions.
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 5ee2853

Please sign in to comment.