Function: ert--plist-difference-explanation
ert--plist-difference-explanation is a byte-compiled function defined
in ert.el.gz.
Signature
(ert--plist-difference-explanation A B)
Documentation
Return a programmer-readable explanation of why A and B are different plists.
Returns nil if they are equivalent, i.e., have the same value for each key, where absent values are treated as nil. The order of key/value pairs in each list does not matter.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/ert.el.gz
(defun ert--plist-difference-explanation (a b)
"Return a programmer-readable explanation of why A and B are different plists.
Returns nil if they are equivalent, i.e., have the same value for
each key, where absent values are treated as nil. The order of
key/value pairs in each list does not matter."
(cl-assert (evenp (length a)) t)
(cl-assert (evenp (length b)) t)
;; Normalizing the plists would be another way to do this but it
;; requires a total ordering on all lisp objects (since any object
;; is valid as a text property key). Perhaps defining such an
;; ordering is useful in other contexts, too, but it's a lot of
;; work, so let's punt on it for now.
(let* ((keys-a (ert--significant-plist-keys a))
(keys-b (ert--significant-plist-keys b))
(keys-in-a-not-in-b (cl-set-difference keys-a keys-b :test 'eq))
(keys-in-b-not-in-a (cl-set-difference keys-b keys-a :test 'eq)))
(cl-flet ((explain-with-key (key)
(let ((value-a (plist-get a key))
(value-b (plist-get b key)))
(cl-assert (not (equal value-a value-b)) t)
`(different-properties-for-key
,key ,(ert--explain-equal-including-properties value-a
value-b)))))
(cond (keys-in-a-not-in-b
(explain-with-key (car keys-in-a-not-in-b)))
(keys-in-b-not-in-a
(explain-with-key (car keys-in-b-not-in-a)))
(t
(cl-loop for key in keys-a
when (not (equal (plist-get a key) (plist-get b key)))
return (explain-with-key key)))))))