fix strings in key map portability
This commit is contained in:
parent
8a33982450
commit
08f3f69909
2 changed files with 6 additions and 9 deletions
|
@ -2,16 +2,13 @@
|
|||
(:require
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn write-key
|
||||
[x]
|
||||
(cond
|
||||
(string? x) (str "\"" x "\"")
|
||||
:else (name x)))
|
||||
(def write-key name)
|
||||
|
||||
(defn read-key
|
||||
"don't keywordize keys with / or ."
|
||||
[x]
|
||||
(if-let [y (re-seq #"^\"(.*)\"$" x)]
|
||||
(-> y first second)
|
||||
(if (re-matches #".*[/.].*" x)
|
||||
x
|
||||
(keyword x)))
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
(fact "write-key should work fine."
|
||||
(write-key :foo) => "foo"
|
||||
(write-key "foo") => "\"foo\"")
|
||||
(write-key "foo") => "foo")
|
||||
|
||||
(fact "read-key should work fine."
|
||||
(read-key "foo") => :foo
|
||||
(read-key "\"foo\"") => "foo")
|
||||
(read-key "foo/bar") => "foo/bar")
|
||||
|
|
Loading…
Reference in a new issue