[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 67ed6ee: Correctly explain test failures with mixed
From: |
Mattias Engdeg�rd |
Subject: |
[Emacs-diffs] master 67ed6ee: Correctly explain test failures with mixed uni/multibyte strings |
Date: |
Sun, 13 Oct 2019 14:29:43 -0400 (EDT) |
branch: master
commit 67ed6ee7337d66dc1101e41bc2e67bde5ab0ecd4
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Correctly explain test failures with mixed uni/multibyte strings
* lisp/emacs-lisp/ert.el (ert--explain-equal-rec):
* test/lisp/emacs-lisp/ert-tests.el (ert-test-explain-equal):
When explaining a difference between a unibyte and a multibyte string,
first convert both to multibyte. Otherwise, we might end up comparing
unibyte char C to multibyte char C, 127<C<256, and not detect the
difference (bug#30219).
---
lisp/emacs-lisp/ert.el | 5 +++++
test/lisp/emacs-lisp/ert-tests.el | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 68762b0..47d20cb 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -516,6 +516,11 @@ Returns nil if they are."
(cl-assert (equal a b) t)
nil))))))))
((pred arrayp)
+ ;; For mixed unibyte/multibyte string comparisons, make both multibyte.
+ (when (and (stringp a)
+ (xor (multibyte-string-p a) (multibyte-string-p b)))
+ (setq a (string-to-multibyte a))
+ (setq b (string-to-multibyte b)))
(if (/= (length a) (length b))
`(arrays-of-different-length ,(length a) ,(length b)
,a ,b
diff --git a/test/lisp/emacs-lisp/ert-tests.el
b/test/lisp/emacs-lisp/ert-tests.el
index 36db1ee..3a9e815 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -627,6 +627,29 @@ This macro is used to test if macroexpansion in `should'
works."
(should (equal (ert--explain-equal 'a sym)
`(different-symbols-with-the-same-name a ,sym)))))
+(ert-deftest ert-test-explain-equal-strings ()
+ (should (equal (ert--explain-equal "abc" "axc")
+ '(array-elt 1 (different-atoms
+ (?b "#x62" "?b")
+ (?x "#x78" "?x")))))
+ (should (equal (ert--explain-equal "abc" "abxc")
+ '(arrays-of-different-length
+ 3 4 "abc" "abxc" first-mismatch-at 2)))
+ (should (equal (ert--explain-equal "xyA" "xyÅ")
+ '(array-elt 2 (different-atoms
+ (?A "#x41" "?A")
+ (?Å "#xc5" "?Å")))))
+ (should (equal (ert--explain-equal "m\xff" "m\u00ff")
+ `(array-elt
+ 1 (different-atoms
+ (#x3fffff "#x3fffff" ,(string-to-multibyte "?\xff"))
+ (#xff "#xff" "?ÿ")))))
+ (should (equal (ert--explain-equal (string-to-multibyte "m\xff") "m\u00ff")
+ `(array-elt
+ 1 (different-atoms
+ (#x3fffff "#x3fffff" ,(string-to-multibyte "?\xff"))
+ (#xff "#xff" "?ÿ"))))))
+
(ert-deftest ert-test-explain-equal-improper-list ()
(should (equal (ert--explain-equal '(a . b) '(a . c))
'(cdr (different-atoms b c)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 67ed6ee: Correctly explain test failures with mixed uni/multibyte strings,
Mattias Engdeg�rd <=