Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raw map key when it cannot be keywordized #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
`clj-yaml` is available as a Maven artifact from [Clojars](http://clojars.org/clj-yaml):

:dependencies
[["clj-yaml" "0.4.0"]
[["clj-yaml" "0.4.1"]
...]

## Development
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject clj-yaml "0.4.0"
(defproject clj-yaml "0.4.1"
:description "YAML encoding and decoding for Clojure using SnakeYAML"
:url "http://github.com/lancepantz/clj-yaml"
:dependencies
Expand Down
4 changes: 3 additions & 1 deletion src/clj_yaml/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
(decode [data]))

(defn decode-key [k]
(if *keywordize* (keyword k) k))
(if *keywordize*
(or (keyword k) k) ; (keyword k) is nil for numbers and other values
k))

(extend-protocol YAMLCodec

Expand Down
10 changes: 9 additions & 1 deletion test/clj_yaml/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ the-bin: !!binary 0101")
(let [parsed (parse-string "foo: bar")]
(is (= "bar" (parsed :foo)))))

(deftest parse-hash-with-numeric-key
(let [parsed (parse-string "123: 456")]
(is (= 456 (parsed 123)))))

(deftest parse-hash-with-complex-key
(let [parsed (parse-string "[1, 2]: 3")]
(is (= 3 (parsed [1, 2])))))

(deftest parse-nested-hash
(let [parsed (parse-string nested-hash-yaml)]
(is (= "a" ((parsed :root) :childa)))
Expand Down Expand Up @@ -118,4 +126,4 @@ the-bin: !!binary 0101")
(is (= "- age: 33\n name: jon\n- age: 44\n name: boo\n"
(generate-string data :dumper-options {:flow-style :block})))
(is (= "[{age: 33, name: jon}, {age: 44, name: boo}]\n"
(generate-string data :dumper-options {:flow-style :flow})))))
(generate-string data :dumper-options {:flow-style :flow})))))