Skip to content

Commit 503aa5b

Browse files
authored
Experimental elision feature fix: Preserve metadata on sets to make it work with feature (#225)
* preserve metadata on sets to ensure ellision works w/ them * add TODO to show that I don't understand the ellision feature For example, with `(match? [#{2}] [#{1 2}])` it currently gives `[#{(unexpected 1)} ...]` This feels misleading to me because there aren't more elements in the vector that are being elided. It should be more like `[#{(unexpected 1) ...}]` or at worst something like `[#{(unexpected 1) ...} ...]`
1 parent 3b96648 commit 503aa5b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/cljc/matcher_combinators/core.cljc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@
246246

247247
(defn- type-preserving-mismatch [base-list values]
248248
(let [lst (into base-list values)]
249-
(if (vector? base-list)
249+
(if (or (vector? base-list)
250+
(set? base-list))
250251
lst
251252
(reverse lst))))
252253

@@ -397,9 +398,11 @@
397398
{::result/type :match
398399
::result/value elements
399400
::result/weight 0}
400-
(match (->EqualsSeq (concat (:matched result)
401-
(:unmatched result)))
402-
(:elements result)))))
401+
(update (match (->EqualsSeq (concat (:matched result)
402+
(:unmatched result)))
403+
(:elements result))
404+
::result/value
405+
#(with-mismatch-meta % :mismatch-sequence)))))
403406

404407
(defn- match-any-order [expected actual subset?]
405408
(if-not (sequential? actual)
@@ -445,7 +448,8 @@
445448
"set"))]
446449
issue
447450
(update (match-any-order (vec expected) (vec actual) false)
448-
::result/value set)))
451+
::result/value
452+
#(with-meta (set %) (meta %)))))
449453
(-base-name [_] (if accept-seq? 'set-equals 'equals)))
450454

451455
(defrecord Prefix [expected]

test/clj/matcher_combinators/config_test.clj

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
(printer/as-string (list 'unexpected (printer/->ColorTag :red 1)))))))
2727

2828
(deftest abbreviated-matched-output-test
29+
(config/disable-abbreviation!)
2930
(is (= (str "[1\n 2\n {:a 2,\n :b [4 (mismatch (expected " (colorize/yellow 5) ") (actual " (colorize/red 6) "))],\n :c [2 [3 4]]}]\n")
3031
(printer/as-string
3132
(:matcher-combinators.result/value
@@ -43,4 +44,22 @@
4344
(printer/as-string
4445
(:matcher-combinators.result/value
4546
(c/match [1 2 {:a 2 :b [4 5] :c [2 [3 4]]}]
46-
[1 2 {:a 2 :b [4 6] :c [2 [3 4]]}]))))))
47+
[1 2 {:a 2 :b [4 6] :c [2 [3 4]]}])))))
48+
(config/disable-abbreviation!))
49+
50+
(deftest abbreviated-set-output-test
51+
(config/disable-abbreviation!)
52+
(is (= (str "[#{(unexpected " (colorize/red 1) ") 2}]\n")
53+
(printer/as-string
54+
(:matcher-combinators.result/value
55+
(c/match [#{2}] [#{1 2}])))))
56+
57+
(config/enable-abbreviation!)
58+
;; TODO PLM: `[#{(unexpected 1)} ...]` feels not completely correct.
59+
;; shouldn't it be `[#{(unexpected 1) ...}]` or `[#{(unexpected 1)} ...]`
60+
;; instead?
61+
(is (= (str "[#{(unexpected " (colorize/red 1) ")} ...]\n")
62+
(printer/as-string
63+
(:matcher-combinators.result/value
64+
(c/match [#{2}] [#{1 2}])))))
65+
(config/disable-abbreviation!))

0 commit comments

Comments
 (0)