Skip to content

Commit

Permalink
Added a utility function that helps the tests on multiline strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
green-coder committed Apr 4, 2019
1 parent cdd9347 commit 87895f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/hopen/util.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
(ns hopen.util)
(ns hopen.util
(:require [clojure.string :as str]))

(defn triml
"Trims the white spaces at the beginning of each line in the text, including the delimiter."
([text] (triml text "|"))
([text delimiter]
(transduce (comp (map (fn [line]
(let [trimmed (str/triml line)]
(if (str/starts-with? trimmed delimiter)
(subs trimmed (count delimiter))
line))))
(interpose "\n"))
str
(str/split-lines text))))

(defn binding-partition
"A transducer which is partitioning a multi-variables binding sequence."
Expand Down
7 changes: 6 additions & 1 deletion test/hopen/util_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
(:require #?(:clj [clojure.test :refer [deftest testing is are]]
:cljs [cljs.test :refer [deftest testing is are]
:include-macros true])
[hopen.util :refer [parse-bindings collect collect-in]]))
[hopen.util :refer [triml parse-bindings collect collect-in]]))

(deftest triml-test
(is (= (triml "hello,
| world!")
"hello,\n world!")))

(deftest parse-bindings-test
(testing "Example-spec the function's input and output"
Expand Down

0 comments on commit 87895f9

Please sign in to comment.