Skip to content

Commit

Permalink
removed unused function, added tests for util.format (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkspranger committed Jan 26, 2022
1 parent b00528a commit e503ca0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/yetibot/core/util/format.clj
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@
(let [ds (if (set? d) (seq d) d)]
[(format-flattened ds) ds])))

(defn format-data-as-string [d]
(let [[s _] (format-data-structure d)]
s))

(defn to-coll-if-contains-newlines
"Convert a String to a List if the string contains newlines. Bit of a hack but
it lets us get out of explicitly supporting streams in every command that we
Expand Down
36 changes: 35 additions & 1 deletion test/yetibot/core/test/util/format.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,34 @@
(fact
"the flattened representation should not contain collections"
(let [[_ flattened] (fmt/format-data-structure nested-list)]
flattened =not=> (contains coll?))))
flattened =not=> (contains coll?)))

(fact
"it will stringify the contents of the collection and return a tuple that
contains said stringification as the 1st element and the actual collection as
the second value
NOTE: when the 1st element of a non-map collection is a map, it drops that 1st
element and performs the creation of the tuple on the rest of the collection
values"
(fmt/format-data-structure {:hello :world})
=> ["hello: :world" {:hello :world}]

(fmt/format-data-structure {:hello :world :how :ru})
=> ["hello: :world\nhow: :ru" {:hello :world :how :ru}]

(fmt/format-data-structure [:hello :world :how :ru])
=> [":hello\n:world\n:how\n:ru" [:hello :world :how :ru]]

(fmt/format-data-structure {{:hello :world} :howru :ihope :well})
=> ["{:hello :world}: :howru\nihope: :well" {:ihope :well {:hello :world} :howru}]

(fmt/format-data-structure #{1 {:hello :world}})
=> ["1\n{:hello :world}" '(1 {:hello :world})]

;; this is what the NOTE is about .. on purpose ??
(fmt/format-data-structure [{:hello :world} {:how :ru}])
=> ["how: :ru" {:how :ru}]))

(facts
"about format-n"
Expand Down Expand Up @@ -124,3 +151,10 @@
"returns arg when no new lines are present"
(fmt/to-coll-if-contains-newlines "123") => "123"
(fmt/to-coll-if-contains-newlines 123) => 123))

(facts
"about format-exception-log"
(fact
"it will .."
(fmt/format-exception-log (Exception. "hello world"))
=> #"(?is)Exception.+hello world.+format\.clj"))

0 comments on commit e503ca0

Please sign in to comment.