Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed parameter keys from strings to keywords

  • Loading branch information...
commit 7567c31615f8730483f07e174d41af8d0b5edad2 1 parent cb1d016
@weavejester weavejester authored
Showing with 29 additions and 30 deletions.
  1. +3 −4 src/clout/core.clj
  2. +26 −26 test/clout/test/core.clj
View
7 src/clout/core.clj
@@ -139,9 +139,8 @@
(let [splat #"\*"
word #":([\p{L}_][\p{L}_0-9-]*)"
literal #"(:[^\p{L}_*]|[^:*])+"
- word-group #(.group % 1)
- word-regex #(regexs (keyword (word-group %))
- "[^/.,;?]+")]
+ word-group #(keyword (.group % 1))
+ word-regex #(regexs (word-group %) "[^/.,;?]+")]
(CompiledRoute.
(re-pattern
(apply str
@@ -151,7 +150,7 @@
literal #(re-escape (.group %)))))
(remove nil?
(lex path
- splat "*"
+ splat :*
word word-group
literal nil))
(absolute-url? path)))))
View
52 test/clout/test/core.clj
@@ -14,56 +14,56 @@
(deftest keyword-paths
(are [path uri params] (= (route-matches path uri) params)
- "/:x" "/foo" {"x" "foo"}
- "/foo/:x" "/foo/bar" {"x" "bar"}
- "/a/b/:c" "/a/b/c" {"c" "c"}
- "/:a/b/:c" "/a/b/c" {"a" "a", "c" "c"}))
+ "/:x" "/foo" {:x "foo"}
+ "/foo/:x" "/foo/bar" {:x "bar"}
+ "/a/b/:c" "/a/b/c" {:c "c"}
+ "/:a/b/:c" "/a/b/c" {:a "a", :c "c"}))
(deftest keywords-match-extensions
(are [path uri params] (= (route-matches path uri) params)
- "/foo.:ext" "/foo.txt" {"ext" "txt"}
- "/:x.:y" "/foo.txt" {"x" "foo", "y" "txt"}))
+ "/foo.:ext" "/foo.txt" {:ext "txt"}
+ "/:x.:y" "/foo.txt" {:x "foo", :y "txt"}))
(deftest hyphen-keywords
(are [path uri params] (= (route-matches path uri) params)
- "/:foo-bar" "/baz" {"foo-bar" "baz"}
- "/:foo-" "/baz" {"foo-" "baz"}))
+ "/:foo-bar" "/baz" {:foo-bar "baz"}
+ "/:foo-" "/baz" {:foo- "baz"}))
(deftest underscore-keywords
(are [path uri params] (= (route-matches path uri) params)
- "/:foo_bar" "/baz" {"foo_bar" "baz"}
- "/:_foo" "/baz" {"_foo" "baz"}))
+ "/:foo_bar" "/baz" {:foo_bar "baz"}
+ "/:_foo" "/baz" {:_foo "baz"}))
(deftest urlencoded-keywords
(are [path uri params] (= (route-matches path uri) params)
- "/:x" "/foo%20bar" {"x" "foo bar"}
- "/:x" "/foo+bar" {"x" "foo bar"}))
+ "/:x" "/foo%20bar" {:x "foo bar"}
+ "/:x" "/foo+bar" {:x "foo bar"}))
(deftest same-keyword-many-times
(are [path uri params] (= (route-matches path uri) params)
- "/:x/:x/:x" "/a/b/c" {"x" ["a" "b" "c"]}
- "/:x/b/:x" "/a/b/c" {"x" ["a" "c"]}))
+ "/:x/:x/:x" "/a/b/c" {:x ["a" "b" "c"]}
+ "/:x/b/:x" "/a/b/c" {:x ["a" "c"]}))
(deftest non-ascii-keywords
(are [path uri params] (= (route-matches path uri) params)
- "/:äñßOÔ" "/abc" {"äñßOÔ" "abc"}
- "/:ÁäñßOÔ" "/abc" {"ÁäñßOÔ" "abc"}
- "/:ä/:ش" "/foo/bar" {"ä" "foo" "ش" "bar"}
- "/:ä/:ä" "/foo/bar" {"ä" ["foo" "bar"]}
- "/:Ä-ü" "/baz" {"Ä-ü" "baz"}
- "/:Ä_ü" "/baz" {"Ä_ü" "baz"}))
+ "/:äñßOÔ" "/abc" {:äñßOÔ "abc"}
+ "/:ÁäñßOÔ" "/abc" {:ÁäñßOÔ "abc"}
+ "/:ä/:ش" "/foo/bar" { "foo" "bar"}
+ "/:ä/:ä" "/foo/bar" { ["foo" "bar"]}
+ "/:Ä-ü" "/baz" {:Ä-ü "baz"}
+ "/:Ä_ü" "/baz" {:Ä_ü "baz"}))
(deftest wildcard-paths
(are [path uri params] (= (route-matches path uri) params)
- "/*" "/foo" {"*" "foo"}
- "/*" "/foo.txt" {"*" "foo.txt"}
- "/*" "/foo/bar" {"*" "foo/bar"}
- "/foo/*" "/foo/bar/baz" {"*" "bar/baz"}
- "/a/*/d" "/a/b/c/d" {"*" "b/c"}))
+ "/*" "/foo" {:* "foo"}
+ "/*" "/foo.txt" {:* "foo.txt"}
+ "/*" "/foo/bar" {:* "foo/bar"}
+ "/foo/*" "/foo/bar/baz" {:* "bar/baz"}
+ "/a/*/d" "/a/b/c/d" {:* "b/c"}))
(deftest compiled-routes
(is (= (route-matches (route-compile "/foo/:id") "/foo/bar")
- {"id" "bar"})))
+ {:id "bar"})))
(deftest url-paths
(is (route-matches "http://localhost" "http://localhost")))
Please sign in to comment.
Something went wrong with that request. Please try again.