Skip to content

Commit f5823e2

Browse files
committed
Add smoke tests for top level API
1 parent 0bd3a5e commit f5823e2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

repl_sessions/str_rep.clj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(ns str-rep
2+
(:require [clojure.string :as str]))
3+
4+
(defn left-pad [s len pad]
5+
(concat (repeat (- len (count s)) pad) s))
6+
7+
(defn int->hex [i]
8+
(str/upper-case
9+
(Integer/toHexString i)))
10+
11+
(defn unicode-rep [char]
12+
(apply str "\\u" (left-pad (int->hex (long char)) 4 \0)))
13+
14+
(defn char-rep [char]
15+
(cond
16+
(= \backspace char)
17+
"\\b"
18+
(= \tab char)
19+
"\\t"
20+
(= \newline char)
21+
"\\n"
22+
(= \formfeed char)
23+
"\\f"
24+
(= \return char)
25+
"\\r"
26+
(< (long char) 32)
27+
(unicode-rep char)
28+
:else
29+
(str char)))
30+
31+
(defn str-rep [s]
32+
(str "\""
33+
(apply str (map char-rep s))
34+
"\""))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns lambdaisland.deep-diff2-test
2+
"Smoke tests of the top level API."
3+
(:require [lambdaisland.deep-diff2 :as ddiff]
4+
[lambdaisland.deep-diff2.diff-impl :as diff-impl]
5+
[clojure.test :refer [is are deftest testing]]
6+
[clojure.string :as str]))
7+
8+
(deftest diff-test
9+
(is (= [{:foo (diff-impl/->Mismatch 1 2)}]
10+
(ddiff/diff [{:foo 1}] [{:foo 2}]))))
11+
12+
(deftest printer-test
13+
(is (instance? lambdaisland.deep_diff2.puget.printer.PrettyPrinter
14+
(ddiff/printer))))
15+
16+
(deftest pretty-print-test
17+
(is (= "\u001B[1;31m[\u001B[0m\u001B[1;31m{\u001B[0m\u001B[1;33m:foo\u001B[0m \u001B[31m-1\u001B[0m \u001B[32m+2\u001B[0m\u001B[1;31m}\u001B[0m\u001B[1;31m]\u001B[0m\n"
18+
(with-out-str
19+
(ddiff/pretty-print (ddiff/diff [{:foo 1}] [{:foo 2}]))))))

0 commit comments

Comments
 (0)