Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental elision feature fix: Preserve metadata on sets to make it work with feature #225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/cljc/matcher_combinators/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@

(defn- type-preserving-mismatch [base-list values]
(let [lst (into base-list values)]
(if (vector? base-list)
(if (or (vector? base-list)
(set? base-list))
lst
(reverse lst))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this change we were turning a set into a list due to reverse


Expand Down Expand Up @@ -397,9 +398,11 @@
{::result/type :match
::result/value elements
::result/weight 0}
(match (->EqualsSeq (concat (:matched result)
(:unmatched result)))
(:elements result)))))
(update (match (->EqualsSeq (concat (:matched result)
(:unmatched result)))
(:elements result))
::result/value
#(with-mismatch-meta % :mismatch-sequence)))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add :mismatch-sequence metadata, which is used by the elision feature, to the result of any-order/set mismatch results


(defn- match-any-order [expected actual subset?]
(if-not (sequential? actual)
Expand Down Expand Up @@ -445,7 +448,8 @@
"set"))]
issue
(update (match-any-order (vec expected) (vec actual) false)
::result/value set)))
::result/value
#(with-meta (set %) (meta %)))))
(-base-name [_] (if accept-seq? 'set-equals 'equals)))

(defrecord Prefix [expected]
Expand Down
21 changes: 20 additions & 1 deletion test/clj/matcher_combinators/config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
(printer/as-string (list 'unexpected (printer/->ColorTag :red 1)))))))

(deftest abbreviated-matched-output-test
(config/disable-abbreviation!)
(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")
(printer/as-string
(:matcher-combinators.result/value
Expand All @@ -43,4 +44,22 @@
(printer/as-string
(:matcher-combinators.result/value
(c/match [1 2 {:a 2 :b [4 5] :c [2 [3 4]]}]
[1 2 {:a 2 :b [4 6] :c [2 [3 4]]}]))))))
[1 2 {:a 2 :b [4 6] :c [2 [3 4]]}])))))
(config/disable-abbreviation!))

(deftest abbreviated-set-output-test
(config/disable-abbreviation!)
(is (= (str "[#{(unexpected " (colorize/red 1) ") 2}]\n")
(printer/as-string
(:matcher-combinators.result/value
(c/match [#{2}] [#{1 2}])))))

(config/enable-abbreviation!)
;; TODO PLM: `[#{(unexpected 1)} ...]` feels not completely correct.
;; shouldn't it be `[#{(unexpected 1) ...}]` or `[#{(unexpected 1)} ...]`
;; instead?
(is (= (str "[#{(unexpected " (colorize/red 1) ")} ...]\n")
(printer/as-string
(:matcher-combinators.result/value
(c/match [#{2}] [#{1 2}])))))
(config/disable-abbreviation!))
Loading