fix strings in key map portability

This commit is contained in:
Yann Esposito (Yogsototh) 2018-02-06 11:02:33 +01:00
parent 8a33982450
commit 08f3f69909
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
2 changed files with 6 additions and 9 deletions

View file

@ -2,16 +2,13 @@
(:require (:require
[clojure.string :as str])) [clojure.string :as str]))
(defn write-key (def write-key name)
[x]
(cond
(string? x) (str "\"" x "\"")
:else (name x)))
(defn read-key (defn read-key
"don't keywordize keys with / or ."
[x] [x]
(if-let [y (re-seq #"^\"(.*)\"$" x)] (if (re-matches #".*[/.].*" x)
(-> y first second) x
(keyword x))) (keyword x)))

View file

@ -5,8 +5,8 @@
(fact "write-key should work fine." (fact "write-key should work fine."
(write-key :foo) => "foo" (write-key :foo) => "foo"
(write-key "foo") => "\"foo\"") (write-key "foo") => "foo")
(fact "read-key should work fine." (fact "read-key should work fine."
(read-key "foo") => :foo (read-key "foo") => :foo
(read-key "\"foo\"") => "foo") (read-key "foo/bar") => "foo/bar")