Skip to content

Commit fa7d006

Browse files
committed
Prepare for the release of the CLJC deep-diff2
Move namespaces to use a "2" suffix, we have breaking changes and we don't want to break existing consumers. We will bundle both namespaces with and without the suffix in the released artifact. Move the printer and diff namespaces to printer-impl and diff-impl, for two reasons. This way we can keep the same top level API at least (lambdaisland.deep-diff2/printer, lambdaisland.deep-diff2/diff), since in ClojureScript names of functions and namespaces are not allowed to overlap. The second reason is that the -impl suffix signals that these are internal and basically have to be treated as private. This allows us to make the functions in there to be public, which makes it possible to unit test them. Before we used alter-meta! to make them public at the start of the test, but this only works in Clojure. Inline Puget, we've made extensive changes to make this work, which we don't expect to go upstream, so we should not release these under puget.* namespaces. Make Puget dispatch based on value rather than type for both Clojure and ClojureScript. Clean up and further unify the print handlers for platform-specific types. Contains a fix to the round-trip generative test, since ##NaN (on js/cljs) can not be compared for equality it leads to false negatives.
1 parent 6ddbc50 commit fa7d006

File tree

12 files changed

+1292
-262
lines changed

12 files changed

+1292
-262
lines changed

deps.edn

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{:paths ["resources" "src" "test"]
2-
:deps {org.clojure/clojure {:mvn/version "1.10.0"}
3-
;;mvxcvi/puget {:mvn/version "1.1.2"}
4-
github-lambdaisland/puget {:git/url "https://github.com/lambdaisland/puget"
5-
:sha "ea860be1f0c6a5e406c45a414802c41e902d010c"}
6-
fipp {:mvn/version "0.6.17"}
7-
org.clojure/core.rrb-vector {:mvn/version "0.0.14"}
8-
;;tech.droit/clj-diff {:mvn/version "1.0.1"}
2+
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
3+
fipp {:mvn/version "0.6.22"}
4+
org.clojure/core.rrb-vector {:mvn/version "0.1.1"}
95
org.clojars.rymndhng/clj-diff {:mvn/version "1.1.1-SNAPSHOT"}
10-
mvxcvi/arrangement {:mvn/version "1.2.0"}
11-
com.andrewmcveigh/cljs-time {:mvn/version "0.5.2"}}
6+
mvxcvi/arrangement {:mvn/version "1.2.0"}}
127

138
:aliases {:cljs
149
{:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}}

src/lambdaisland/deep_diff/printer.cljc

Lines changed: 0 additions & 220 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
(ns lambdaisland.deep-diff
2-
(:require [lambdaisland.deep-diff.diff :as diff]
3-
[lambdaisland.deep-diff.printer :as printer]))
1+
(ns lambdaisland.deep-diff2
2+
(:require [lambdaisland.deep-diff2.diff-impl :as diff-impl]
3+
[lambdaisland.deep-diff2.printer-impl :as printer-impl]))
44

5-
(defn call-diff
5+
(defn diff
66
"Compare two values recursively.
77
88
The result is a data structure similar to the ones passed in, but with
@@ -19,16 +19,16 @@
1919
[expected actual]
2020
(diff/diff expected actual))
2121

22-
(defn build-printer
22+
(defn printer
2323
"Construct a Puget printer instance suitable for printing diffs.
2424
2525
Extra options are passed on to Puget. Extra type handlers can be provides as
2626
`:extra-handlers` (a map from symbol to function), or by
2727
using [[lambdaisland.deep-diff.printer/register-print-handler!]]"
2828
([]
29-
(build-printer {}))
29+
(printer {}))
3030
([opts]
31-
(printer/puget-printer opts)))
31+
(printer-impl/puget-printer opts)))
3232

3333
(defn pretty-print
3434
"Pretty print a diff.
@@ -39,5 +39,5 @@
3939
(pretty-print diff (build-printer)))
4040
([diff printer]
4141
(-> diff
42-
(printer/format-doc printer)
43-
(printer/print-doc printer))))
42+
(printer-impl/format-doc printer)
43+
(printer-impl/print-doc printer))))

src/lambdaisland/deep_diff/diff.cljc renamed to src/lambdaisland/deep_diff2/diff_impl.cljc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns lambdaisland.deep-diff.diff
1+
(ns lambdaisland.deep-diff2.diff-impl
22
(:require [clojure.data :as data]
33
[clj-diff.core :as seq-diff]))
44

@@ -134,8 +134,12 @@
134134
(-diff-similar x y)))
135135

136136
(defn diffable? [exp]
137-
(or (implements? Diff exp)
138-
(satisfies? Diff exp)))
137+
(satisfies? Diff exp))
138+
139+
;; ClojureScript has this, Clojure doesn't
140+
#?(:clj
141+
(defn array? [x]
142+
(and x (.isArray (class x)))))
139143

140144
(defn diff [exp act]
141145
(cond

0 commit comments

Comments
 (0)