This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-08
Channels
- # babashka (9)
- # beginners (43)
- # biff (4)
- # calva (11)
- # cider (6)
- # clerk (1)
- # clj-kondo (4)
- # cljs-dev (6)
- # clojure (82)
- # clojure-berlin (1)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (182)
- # clojure-quebec (1)
- # clojure-uk (19)
- # clojurescript (6)
- # datahike (1)
- # emacs (30)
- # fulcro (5)
- # honeysql (6)
- # hyperfiddle (12)
- # lambdaisland (8)
- # malli (11)
- # off-topic (36)
- # pathom (26)
- # pedestal (1)
- # portal (25)
- # practicalli (1)
- # rdf (29)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # sci (37)
- # shadow-cljs (15)
- # vim (10)
- # xtdb (13)
@itai The thing to realize is that ddiff/pretty-print
does actually printing, whereas you seem to be expecting that it returns a string. That's a bit more involved, something like this:
(ns repl-sessions.poke
(:require
[lambdaisland.deep-diff2.puget.printer :as ddiff-printer]
[lambdaisland.deep-diff2.printer-impl :as ddiff-printer-impl]
[lambdaisland.deep-diff2 :as ddiff]
[clojure.test :refer :all]))
(defn ddiff->str [expected actual]
(ddiff-printer/render-str
(ddiff/printer)
(ddiff/minimize (ddiff/diff expected actual))))
now you can do
(let [expected {:a 1 :b 2 :c 3}
actual {:a 1 :b 2 :c 4}]
(is (submap? expected actual)
(ddiff->str expected actual)))
or (this is getting close to dark arts), you can override how clojure.test handles the 'submap?
predicate
(defmethod clojure.test/assert-expr 'submap? [msg form]
(let [[_ expected actual] form]
`(let [exp# ~expected
act# ~actual]
(if (submap? exp# act#)
(do-report {:type :pass, :message ~msg,
:expected '~form, :actual (cons 'submap? exp# act#)})
(do-report {:type :fail, :message (ddiff->str exp# act#)
:expected '~form, :actual (list '~'not (list '~'submap? exp# act#))})))))