This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-10
Channels
- # admin-announcements (1)
- # aleph (1)
- # asami (9)
- # babashka (30)
- # beginners (83)
- # calva (8)
- # cherry (4)
- # cider (4)
- # clj-kondo (15)
- # cljs-dev (11)
- # cljsrn (8)
- # clojure (85)
- # clojure-europe (87)
- # clojure-losangeles (9)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (3)
- # clojurescript (12)
- # community-development (5)
- # conjure (1)
- # core-typed (3)
- # datomic (21)
- # docker (13)
- # emacs (13)
- # funcool (1)
- # google-cloud (1)
- # graalvm (12)
- # gratitude (14)
- # holy-lambda (6)
- # introduce-yourself (18)
- # lsp (15)
- # malli (6)
- # matcher-combinators (15)
- # nbb (15)
- # off-topic (37)
- # pathom (31)
- # portal (23)
- # rdf (3)
- # releases (2)
- # reveal (2)
- # sci (4)
- # scittle (3)
- # shadow-cljs (14)
- # squint (2)
- # tools-deps (29)
https://github.com/nubank/matcher-combinators/pull/180 a badge for this channel in README.
Impetus for this channel: https://clojurians.slack.com/archives/C03S1KBA2/p1668100660564529
Started using macher-combinator in babashka now as well, for some tests. I needed to compare expected text spanning multiple lines against actual text. I didn't know if mc had something for this, so I just broke everything in lines and then compared a sequence of lines
I think it would be useful if mc had something like: This is the expected multi-line string and the actual output should at least start with that. And when it doesn't match, don't output the large string blob, but point into the string where it starts to diverge
Is matcher-combinators.matchers/regex
insufficient?
Oh - I see the bit about the blob.
This is my diff to move from my own logic to mc: https://github.com/babashka/babashka/commit/ac1b16bfc89e394b7dce555dad329d97a6fa0e8c
So this is basically my matching logic now:
(defmacro multiline-equals [s1 s2]
`(let [lines-s1# (str/split-lines ~s1)
lines-s2# (str/split-lines ~s2)
max-lines# (max (count lines-s1#) (count lines-s2#))
lines-s1# (take max-lines# lines-s1#)
lines-s2# (take max-lines# lines-s2#)]
(is (~'match? (map str/trimr lines-s1#) (map str/trimr lines-s2#)))
#_(run! (fn [i]
(let [l1 (get lines-s1 i)
l2 (get lines-s2 i)]
(if (and l1 l2)
(is (= l1 l2)
(format "Lines did not match.\nLine: %s\nLeft: %s\nRight: %s"
i (pr-str l1) (pr-str l2)))
(is false (format "Out of lines at line: %s.\nLeft: %s\nRight: %s"
i (pr-str l1) (pr-str l2))))))
(range max-lines))))
The commented out thing is what I did beforeThis works already pretty well but it also ties into an issue that @lee mentioned yesterday: If you have two sequences and they start to diverge because there is one element in between, all the elements after are reported as non-matching
e.g.
[1,2,3,4] ~ [1,1,2,3,4]
everything after the first 1 is dismissed as non-matching, while you could argue that it should only report the second 1 in the last element@borkdude I also use the split lines strategy when using kaocha to get nice diff results.
Would be cool to have such a matcher built into matcher-combinators, and it would make sense if it https://github.com/nubank/matcher-combinators/issues/177.