Skip to content

Commit

Permalink
[Fix #1] Restore default text-wrapping behavior of prior release (#2)
Browse files Browse the repository at this point in the history
See comments in diff and #1.
  • Loading branch information
Avi Flax authored and slipset committed Jan 7, 2019
1 parent 6f3ff44 commit ba91f0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/clojure/clj_yaml/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
:block DumperOptions$FlowStyle/BLOCK
:flow DumperOptions$FlowStyle/FLOW})

(defn ^DumperOptions default-dumper-options
"clj-yaml 0.5.6 used SnakeYAML 1.13 which by default did *not* split long
lines. clj-yaml 0.6.0 upgraded to SnakeYAML 1.23 which by default *did* split
long lines. This ensures that generate-string uses the older behavior by
default, for the sake of stability, i.e. backwards compatibility."
[]
(doto (DumperOptions.)
(.setSplitLines false)))

(defn ^DumperOptions make-dumper-options
[& {:keys [flow-style]}]
(doto (DumperOptions.)
(doto (default-dumper-options)
(.setDefaultFlowStyle (flow-styles flow-style))))

(defn ^Yaml make-yaml
Expand All @@ -27,7 +36,7 @@
;; TODO: unsafe marked constructor
dumper (if dumper-options
(make-dumper-options :flow-style (:flow-style dumper-options))
(DumperOptions.))]
(default-dumper-options))]
(Yaml. constructor (Representer.) dumper)))

(defrecord Marked
Expand Down
13 changes: 13 additions & 0 deletions test/clj_yaml/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ the-bin: !!binary 0101")
(is (= 1 (-> parsed unmark first :end :line)))
(is (= 5 (-> parsed unmark first :end :column)))))

(deftest text-wrapping
(let [data
{:description
"Big-picture diagram showing how our top-level systems and stakeholders interact"}]
(testing "long lines of text should not be wrapped"
;; clj-yaml 0.5.6 used SnakeYAML 1.13 which by default did *not* split long lines.
;; clj-yaml 0.6.0 upgraded to SnakeYAML 1.23 which by default *did* split long lines.
;; This test ensures that generate-string uses the older behavior by default, for the sake
;; of stability, i.e. backwards compatibility.
(is
(= "{description: Big-picture diagram showing how our top-level systems and stakeholders interact}\n"
(generate-string data))))))

(deftest dump-opts
(let [data [{:age 33 :name "jon"} {:age 44 :name "boo"}]]
(is (= "- age: 33\n name: jon\n- age: 44\n name: boo\n"
Expand Down

0 comments on commit ba91f0f

Please sign in to comment.