From f19f0474280284a9e15b998509126fb43ae3948b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Pospi=CC=81s=CC=8Cil?= Date: Tue, 22 Oct 2019 10:17:10 +0200 Subject: [PATCH] Move trolley to root of the project Add period as part of the route. Clean up test code. --- project.janet | 2 +- test/trolley.janet | 68 +++++++++++++++--------------- src/trolley.janet => trolley.janet | 4 +- 3 files changed, 37 insertions(+), 37 deletions(-) rename src/trolley.janet => trolley.janet (94%) diff --git a/project.janet b/project.janet index f95cd9d..734fedb 100644 --- a/project.janet +++ b/project.janet @@ -8,4 +8,4 @@ :dependencies ["https://github.com/joy-framework/tester"]) (declare-source - :source @["src/trolley.janet"]) + :source @["trolley.janet"]) diff --git a/test/trolley.janet b/test/trolley.janet index b1459a1..87c24c8 100644 --- a/test/trolley.janet +++ b/test/trolley.janet @@ -1,42 +1,42 @@ (import tester :prefix "") -(import ../src/trolley :as trolley) +(import ../trolley :as trolley) +(def config "Routes' config for all tests" + {"/" :root "/home/:id" :home "/real-thing.json" :real-thing}) (deftest "Compile routes" - (def compiled-routes - (trolley/compile-routes {"/" :root "/home/:id" :home})) - - (test "are compiled" compiled-routes) - - (def actions (values compiled-routes)) - (test "has root action" - (some |(= :root $) actions)) - (test "has home action" - (some |(= :home $) actions)) - - (def first-route (first (keys compiled-routes))) - (test "route is peg" - (= :core/peg (type first-route)))) + (let [compiled-routes (trolley/compile-routes config) + actions (values compiled-routes) + routes (keys compiled-routes)] + (test "are compiled" compiled-routes) + (test "has root action" + (some |(= $ :root) actions)) + (test "has home action" + (some |(= $ :home) actions)) + (test "routes are all PEGs" + (all |(= (type $) :core/peg) routes)))) (deftest "Lookup uri" - (def compiled-routes - (trolley/compile-routes {"/" :root "/home/:id" :home})) - - (test "lookup" - (deep= (trolley/lookup compiled-routes "/home/3") - [:home @{:id "3"}])) - (test "lookup root" - (deep= (trolley/lookup compiled-routes "/") - [:root @{}])) - (test "lookup rooty" - (empty? (trolley/lookup compiled-routes "/home/")))) + (let [compiled-routes (trolley/compile-routes config)] + (test "lookup" + (deep= (trolley/lookup compiled-routes "/home/3") + [:home @{:id "3"}])) + (test "lookup root" + (deep= (trolley/lookup compiled-routes "/") + [:root @{}])) + (test "lookup real thing" + (deep= (trolley/lookup compiled-routes "/real-thing.json") + [:real-thing @{}]) ) + (test "lookup rooty" + (empty? (trolley/lookup compiled-routes "/home/"))))) (deftest "Router" - (def router (trolley/router {"/" :root - "/home/:id" :home})) - (test "root" - (deep= (router "/") [:root @{}])) - (test "home" - (deep= (router "/home/3") [:home @{:id "3"}])) - (test "not found" - (empty? (router "home")))) + (let [router (trolley/router config)] + (test "root" + (deep= (router "/") [:root @{}])) + (test "home" + (deep= (router "/home/3") [:home @{:id "3"}])) + (test "real thing json" + (deep= (router "/real-thing.json") [:real-thing @{}])) + (test "not found" + (empty? (router "home"))))) diff --git a/src/trolley.janet b/trolley.janet similarity index 94% rename from src/trolley.janet rename to trolley.janet index 0053dfd..8c51edc 100644 --- a/src/trolley.janet +++ b/trolley.janet @@ -1,7 +1,7 @@ # @todo: make this dyn (def content - "Characters we consider part of the route" - '(+ (range "AZ") (range "az") (range "09") (set "-_"))) + "Characters considered part of the route" + '(+ (range "AZ") (range "az") (range "09") (set "-_."))) (def sep "Separator character" "/") -- 2.45.2