Skip to content

Commit 9ef79d1

Browse files
committed
Fixing unit test errors. 2 Errors for diff namespace, 2 errors for printer namespace
1 parent 00342b3 commit 9ef79d1

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target
44
repl
55
bin
66
scratch.clj
7+
/out/
78
/checkouts/
89
/target/
910
/.cljs_node_repl/

src/lambdaisland/deep_diff/diff.cljc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,17 @@
167167
Diff
168168
(-diff-similar [x y] (diff-atom x y))))
169169

170+
#?(:cljs (extend-type js/Object
171+
Diff
172+
(-diff-similar [x y] (diff-atom (js->clj x) (js->clj y)))))
173+
170174
#?(:clj (extend Object
171175
Diff
172176
{:-diff-similar (fn [exp act]
173177
(if (.isArray (.getClass ^Object exp))
174178
(diff-seq exp act)
175179
(diff-atom exp act)))}))
176180

177-
178181
(extend-protocol Diff
179182
#?(:clj java.util.List
180183
:cljs cljs.core/List)
@@ -184,8 +187,14 @@
184187
[cljs.core/PersistentVector
185188
(-diff-similar [exp act] (diff-seq exp act))
186189

190+
cljs.core/EmptyList
191+
(-diff-similar [exp act] (diff-seq exp act))
192+
187193
cljs.core/PersistentHashMap
188-
(-diff-similar [exp act] (diff-map exp act))])
194+
(-diff-similar [exp act] (diff-map exp act))
195+
196+
array
197+
(-diff-similar [exp act] (diff-seq exp act))])
189198

190199
#?(:clj java.util.Set
191200
:cljs cljs.core/PersistentHashSet)
@@ -194,6 +203,7 @@
194203
act-seq (seq act)]
195204
(set (diff-seq exp-seq (concat (filter act exp-seq)
196205
(remove exp act-seq))))))
206+
197207
#?(:clj java.util.Map
198208
:cljs cljs.core/PersistentArrayMap)
199209
(-diff-similar [exp act] (diff-map exp act)))
@@ -204,11 +214,23 @@
204214
(-left-undiff [s] (map left-undiff (remove #(instance? Insertion %) s)))
205215
(-right-undiff [s] (map right-undiff (remove #(instance? Deletion %) s)))
206216

217+
#?(:cljs cljs.core/EmptyList)
218+
#?(:cljs (-left-undiff [s] (map left-undiff (remove #(instance? Insertion %) s))))
219+
#?(:cljs (-right-undiff [s] (map right-undiff (remove #(instance? Deletion %) s))))
220+
221+
#?(:cljs cljs.core/PersistentVector)
222+
#?(:cljs (-left-undiff [s] (map left-undiff (remove #(instance? Insertion %) s))))
223+
#?(:cljs (-right-undiff [s] (map right-undiff (remove #(instance? Deletion %) s))))
224+
207225
#?(:clj java.util.Set
208226
:cljs cljs.core/PersistentHashSet)
209227
(-left-undiff [s] (set (left-undiff (seq s))))
210228
(-right-undiff [s] (set (right-undiff (seq s))))
211229

230+
#?(:cljs cljs.core/KeySeq)
231+
#?(:cljs (-left-undiff [s] (map left-undiff (remove #(instance? Insertion %) s))))
232+
#?(:cljs (-right-undiff [s] (map right-undiff (remove #(instance? Deletion %) s))))
233+
212234
#?(:clj java.util.Map
213235
:cljs cljs.core/PersistentArrayMap)
214236
(-left-undiff [m]
@@ -222,6 +244,18 @@
222244
(map (juxt (comp right-undiff key) (comp right-undiff val))))
223245
m))
224246

247+
#?(:cljs cljs.core/PersistentHashMap)
248+
#?(:cljs (-left-undiff [m]
249+
(into {}
250+
(comp (remove #(instance? Insertion (key %)))
251+
(map (juxt (comp left-undiff key) (comp left-undiff val))))
252+
m)))
253+
#?(:cljs (-right-undiff [m]
254+
(into {}
255+
(comp (remove #(instance? Deletion (key %)))
256+
(map (juxt (comp right-undiff key) (comp right-undiff val))))
257+
m)))
258+
225259
Mismatch
226260
(-left-undiff [m] (get m :-))
227261
(-right-undiff [m] (get m :+))
@@ -238,3 +272,12 @@
238272
(-right-undiff [m] m))
239273

240274
#?(:clj (extend Object Undiff {:-left-undiff identity :-right-undiff identity}))
275+
#?(:cljs (extend-type cljs.core/UUID
276+
Undiff
277+
(-left-undiff [m] m)
278+
(-right-undiff [m] m)))
279+
280+
#?(:cljs (extend-type js/Object
281+
Undiff
282+
(-left-undiff [m] m)
283+
(-right-undiff [m] m)))

test/lambdaisland/deep_diff/diff_test.cljc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@
265265
(diff/diff-seq [:a :b :c] [:a :c :d]))))
266266

267267

268-
269-
270-
271268
(comment
272269
(use 'kaocha.repl)
273270
(run)

test/lambdaisland/deep_diff/printer_test.clj renamed to test/lambdaisland/deep_diff/printer_test.cljc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,40 @@
22
(:require [clojure.test :refer [deftest testing is are]]
33
[lambdaisland.deep-diff.diff :as diff]
44
[lambdaisland.deep-diff.printer :as printer])
5-
(:import (java.sql Timestamp)
6-
(java.util Date
7-
GregorianCalendar
8-
TimeZone)))
5+
#?(:clj
6+
(:import (java.sql Timestamp)
7+
(java.util Date
8+
GregorianCalendar
9+
TimeZone))))
910

1011
(defn- printed
1112
[diff]
1213
(let [printer (printer/puget-printer {})]
1314
(with-out-str (-> diff
1415
(printer/format-doc printer)
1516
(printer/print-doc printer)))))
16-
17-
(defn- calendar
18-
[date]
19-
(doto (GregorianCalendar. (TimeZone/getTimeZone "GMT"))
20-
(.setTime date)))
17+
#?(:clj
18+
(defn- calendar
19+
[date]
20+
(doto (GregorianCalendar. (TimeZone/getTimeZone "GMT"))
21+
(.setTime date))))
2122

2223
(deftest print-doc-test
2324
(testing "date"
2425
(is (= "\u001B[31m-#inst \"2019-04-09T14:57:46.128-00:00\"\u001B[0m \u001B[32m+#inst \"2019-04-10T14:57:46.128-00:00\"\u001B[0m\n"
2526
(printed (diff/diff #inst "2019-04-09T14:57:46.128-00:00"
2627
#inst "2019-04-10T14:57:46.128-00:00")))))
2728

28-
(testing "timestamp"
29-
(is (= "\u001B[31m-#inst \"1970-01-01T00:00:00.000000000-00:00\"\u001B[0m \u001B[32m+#inst \"1970-01-01T00:00:01.000000101-00:00\"\u001B[0m\n"
30-
(printed (diff/diff (Timestamp. 0)
31-
(doto (Timestamp. 1000) (.setNanos 101)))))))
29+
#?(:clj
30+
(testing "timestamp"
31+
(is (= "\u001B[31m-#inst \"1970-01-01T00:00:00.000000000-00:00\"\u001B[0m \u001B[32m+#inst \"1970-01-01T00:00:01.000000101-00:00\"\u001B[0m\n"
32+
(printed (diff/diff (Timestamp. 0)
33+
(doto (Timestamp. 1000) (.setNanos 101))))))))
3234

33-
(testing "calendar"
34-
(is (= "\u001B[31m-#inst \"1970-01-01T00:00:00.000+00:00\"\u001B[0m \u001B[32m+#inst \"1970-01-01T00:00:01.001+00:00\"\u001B[0m\n"
35-
(printed (diff/diff (calendar (Date. 0)) (calendar (Date. 1001)))))))
35+
#?(:clj
36+
(testing "calendar"
37+
(is (= "\u001B[31m-#inst \"1970-01-01T00:00:00.000+00:00\"\u001B[0m \u001B[32m+#inst \"1970-01-01T00:00:01.001+00:00\"\u001B[0m\n"
38+
(printed (diff/diff (calendar (Date. 0)) (calendar (Date. 1001))))))))
3639

3740
(testing "uuid"
3841
(is (= "\u001B[31m-#uuid \"e41b325a-ce9d-4fdd-b51d-280d9c91314d\"\u001B[0m \u001B[32m+#uuid \"0400be9a-619f-4c6a-a735-6245e4955995\"\u001B[0m\n"

0 commit comments

Comments
 (0)