-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0adb77
commit 5ee2853
Showing
6 changed files
with
1,276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ":", | ||
}, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
), | ||
); |
Oops, something went wrong.