Merge pull request #939 from timmc/back-to-one-problem

Remove some unnecessary regular expressions from the templates util ns.
This commit is contained in:
Phil Hagelberg 2013-01-19 15:07:58 -08:00
commit f60ae5f3ae
2 changed files with 24 additions and 8 deletions

View file

@ -30,7 +30,7 @@
(defn sanitize
"Replace hyphens with underscores."
[s]
(string/replace s #"-" "_"))
(string/replace s "-" "_"))
(defn multi-segment
"Make a namespace multi-segmented by adding another segment if necessary.
@ -44,14 +44,11 @@ The additional segment defaults to \"core\"."
(defn name-to-path
"Constructs directory structure from fully qualified artifact name:
myproject creates src/myproject/* directory
mygroup.myproject creates src/mygroup/myproject/* directory
\"foo-bar.baz\" becomes \"foo_bar/baz\"
and so on. Uses platform-specific file separators."
[s]
(-> s sanitize (string/replace #"\." (if (= :windows (eval/get-os))
"\\\\"
java.io.File/separator))))
(-> s sanitize (string/replace "." java.io.File/separator)))
(defn sanitize-ns
"Returns project namespace name from (possibly group-qualified) project name:
@ -61,8 +58,8 @@ The additional segment defaults to \"core\"."
mygroup/my_proj => mygroup.my-proj"
[s]
(-> s
(string/replace #"/" ".")
(string/replace #"_" "-")))
(string/replace "/" ".")
(string/replace "_" "-")))
(defn year
"Get the current year. Useful for setting copyright years and such."

View file

@ -0,0 +1,19 @@
(ns leiningen.test.new.templates
(:use clojure.test
leiningen.new.templates))
(deftest project-names
(is (= (project-name "org.example/foo.bar") "foo.bar"))
(is (= (project-name "example") "example"))
(is (= (sanitize-ns "org.example/foo-bar") "org.example.foo-bar"))
(is (= (sanitize-ns "foo-bar") "foo-bar"))
(is (= (sanitize-ns "foo_bar") "foo-bar")))
(deftest namespaces
(is (= (multi-segment "foo") "foo.core"))
(is (= (multi-segment "foo" "api") "foo.api"))
(is (= (multi-segment "multi.segment" "last") "multi.segment")))
(deftest paths
(is (= (name-to-path "foo-bar.baz") "foo_bar/baz")))