mirror of
https://github.com/metosin/reitit.git
synced 2025-12-23 18:41:11 +00:00
router-type => router-name
This commit is contained in:
parent
ec628bd05e
commit
249a54f9bc
3 changed files with 14 additions and 9 deletions
|
|
@ -87,7 +87,7 @@ Creating a router:
|
||||||
`:mixed-router` is created (both static & wild routes are found):
|
`:mixed-router` is created (both static & wild routes are found):
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
(reitit/router-type router)
|
(reitit/router-name router)
|
||||||
; :mixed-router
|
; :mixed-router
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@
|
||||||
[p m (if compile (compile route opts))])
|
[p m (if compile (compile route opts))])
|
||||||
|
|
||||||
(defprotocol Router
|
(defprotocol Router
|
||||||
(router-type [this])
|
(router-name [this])
|
||||||
(routes [this])
|
(routes [this])
|
||||||
(options [this])
|
(options [this])
|
||||||
(route-names [this])
|
(route-names [this])
|
||||||
|
|
@ -146,7 +146,7 @@
|
||||||
lookup (impl/fast-map lookup)]
|
lookup (impl/fast-map lookup)]
|
||||||
(reify
|
(reify
|
||||||
Router
|
Router
|
||||||
(router-type [_]
|
(router-name [_]
|
||||||
:linear-router)
|
:linear-router)
|
||||||
(routes [_]
|
(routes [_]
|
||||||
routes)
|
routes)
|
||||||
|
|
@ -190,7 +190,7 @@
|
||||||
data (impl/fast-map data)
|
data (impl/fast-map data)
|
||||||
lookup (impl/fast-map lookup)]
|
lookup (impl/fast-map lookup)]
|
||||||
(reify Router
|
(reify Router
|
||||||
(router-type [_]
|
(router-name [_]
|
||||||
:lookup-router)
|
:lookup-router)
|
||||||
(routes [_]
|
(routes [_]
|
||||||
routes)
|
routes)
|
||||||
|
|
@ -220,7 +220,7 @@
|
||||||
lookup-router (lookup-router lookup opts)
|
lookup-router (lookup-router lookup opts)
|
||||||
names (find-names routes opts)]
|
names (find-names routes opts)]
|
||||||
(reify Router
|
(reify Router
|
||||||
(router-type [_]
|
(router-name [_]
|
||||||
:mixed-router)
|
:mixed-router)
|
||||||
(routes [_]
|
(routes [_]
|
||||||
routes)
|
routes)
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
(testing "linear-router"
|
(testing "linear-router"
|
||||||
(let [router (reitit/router ["/api" ["/ipa" ["/:size" ::beer]]])]
|
(let [router (reitit/router ["/api" ["/ipa" ["/:size" ::beer]]])]
|
||||||
(is (= :linear-router (reitit/router-type router)))
|
|
||||||
(is (= [["/api/ipa/:size" {:name ::beer}]]
|
(is (= [["/api/ipa/:size" {:name ::beer}]]
|
||||||
|
(is (= :linear-router (reitit/router-name router)))
|
||||||
(reitit/routes router)))
|
(reitit/routes router)))
|
||||||
(is (= true (map? (reitit/options router))))
|
(is (= true (map? (reitit/options router))))
|
||||||
(is (= (reitit/map->Match
|
(is (= (reitit/map->Match
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
(reitit/match-by-name router ::beer {:size "large"})))
|
(reitit/match-by-name router ::beer {:size "large"})))
|
||||||
(is (= nil (reitit/match-by-name router "ILLEGAL")))
|
(is (= nil (reitit/match-by-name router "ILLEGAL")))
|
||||||
(is (= [::beer] (reitit/route-names router)))
|
(is (= [::beer] (reitit/route-names router)))
|
||||||
|
|
||||||
(testing "name-based routing with missing parameters"
|
(testing "name-based routing with missing parameters"
|
||||||
(is (= (reitit/map->PartialMatch
|
(is (= (reitit/map->PartialMatch
|
||||||
{:template "/api/ipa/:size"
|
{:template "/api/ipa/:size"
|
||||||
|
|
@ -42,8 +43,8 @@
|
||||||
|
|
||||||
(testing "lookup-router"
|
(testing "lookup-router"
|
||||||
(let [router (reitit/router ["/api" ["/ipa" ["/large" ::beer]]])]
|
(let [router (reitit/router ["/api" ["/ipa" ["/large" ::beer]]])]
|
||||||
(is (= :lookup-router (reitit/router-type router)))
|
|
||||||
(is (= [["/api/ipa/large" {:name ::beer}]]
|
(is (= [["/api/ipa/large" {:name ::beer}]]
|
||||||
|
(is (= :lookup-router (reitit/router-name router)))
|
||||||
(reitit/routes router)))
|
(reitit/routes router)))
|
||||||
(is (= true (map? (reitit/options router))))
|
(is (= true (map? (reitit/options router))))
|
||||||
(is (= (reitit/map->Match
|
(is (= (reitit/map->Match
|
||||||
|
|
@ -60,6 +61,7 @@
|
||||||
(reitit/match-by-name router ::beer {:size "large"})))
|
(reitit/match-by-name router ::beer {:size "large"})))
|
||||||
(is (= nil (reitit/match-by-name router "ILLEGAL")))
|
(is (= nil (reitit/match-by-name router "ILLEGAL")))
|
||||||
(is (= [::beer] (reitit/route-names router)))
|
(is (= [::beer] (reitit/route-names router)))
|
||||||
|
|
||||||
(testing "can't be created with wildcard routes"
|
(testing "can't be created with wildcard routes"
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
|
|
@ -69,6 +71,7 @@
|
||||||
["/api/:version/ping"] {})))))))
|
["/api/:version/ping"] {})))))))
|
||||||
|
|
||||||
(testing "route coercion & compilation"
|
(testing "route coercion & compilation"
|
||||||
|
|
||||||
(testing "custom compile"
|
(testing "custom compile"
|
||||||
(let [compile-times (atom 0)
|
(let [compile-times (atom 0)
|
||||||
coerce (fn [[path meta] _]
|
coerce (fn [[path meta] _]
|
||||||
|
|
@ -86,6 +89,7 @@
|
||||||
["/crap"]]]
|
["/crap"]]]
|
||||||
{:coerce coerce
|
{:coerce coerce
|
||||||
:compile compile})]
|
:compile compile})]
|
||||||
|
|
||||||
(testing "routes are coerced"
|
(testing "routes are coerced"
|
||||||
(is (= [["/api/ping" {:name ::ping
|
(is (= [["/api/ping" {:name ::ping
|
||||||
:path "/api/ping",
|
:path "/api/ping",
|
||||||
|
|
@ -100,6 +104,7 @@
|
||||||
(is result)
|
(is result)
|
||||||
(is (= "/api/pong" (result)))
|
(is (= "/api/pong" (result)))
|
||||||
(is (= 2 @compile-times))))))
|
(is (= 2 @compile-times))))))
|
||||||
|
|
||||||
(testing "default compile"
|
(testing "default compile"
|
||||||
(let [router (reitit/router ["/ping" (constantly "ok")])]
|
(let [router (reitit/router ["/ping" (constantly "ok")])]
|
||||||
(let [{:keys [result]} (reitit/match-by-path router "/ping")]
|
(let [{:keys [result]} (reitit/match-by-path router "/ping")]
|
||||||
|
|
@ -109,9 +114,9 @@
|
||||||
(testing "custom router"
|
(testing "custom router"
|
||||||
(let [router (reitit/router ["/ping"] {:router (fn [_ _]
|
(let [router (reitit/router ["/ping"] {:router (fn [_ _]
|
||||||
(reify Router
|
(reify Router
|
||||||
(reitit/router-type [_]
|
(reitit/router-name [_]
|
||||||
::custom)))})]
|
::custom)))})]
|
||||||
(is (= ::custom (reitit/router-type router)))))
|
(is (= ::custom (reitit/router-name router)))))
|
||||||
|
|
||||||
(testing "bide sample"
|
(testing "bide sample"
|
||||||
(let [routes [["/auth/login" :auth/login]
|
(let [routes [["/auth/login" :auth/login]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue