Refactor ()

* Update system info

* Update qlfile

* Organize code

* Add test

* Implement uri-mapper and package-mapper

* Change type of package from string to keyword

* Implement router
This commit is contained in:
Akira Tempaku 2024-12-20 13:32:20 +09:00
parent 7ab7284e88
commit b1dee071ff
8 changed files with 126 additions and 77 deletions

View file

34
tests/router.lisp Normal file
View file

@ -0,0 +1,34 @@
(defpackage #:ningle-fbr-test/router
(:use #:cl
#:rove)
(:import-from #:ningle-fbr/router
#:pathname->path
#:path->uri
#:path->package))
(in-package #:ningle-fbr-test/router)
(deftest router-test
(testing "pathname->path"
(ok (string= (pathname->path #P"/home/app/src/routes/foo.lisp"
#P"/home/app/src/routes/")
"/foo"))))
(deftest uri-test
(testing "normal path"
(ok (string= (path->uri "/foo") "/foo"))
(ok (string= (path->uri "/foo/bar") "/foo/bar")))
(testing "index path"
(ok (string= (path->uri "/index") "/"))
(ok (string= (path->uri "/nested/index") "/nested")))
(testing "dynamic path"
(ok (string= (path->uri "/user/[id]") "/user/:id"))
(ok (string= (path->uri "/location/[country]/[city]") "/location/:country/:city" ))))
(deftest package-test
(testing "normal case"
(ok (eq (path->package "/foo" :app "routes")
:app/routes/foo))
(ok (eq (path->package "/foo" :app "somedir/routes")
:app/somedir/routes/foo))))