all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 30219@debbugs.gnu.org, Philipp <p.stephani2@gmail.com>
Subject: bug#30219: 27.0.50; (should (equal ...)) bug for string equality
Date: Fri, 11 Oct 2019 11:21:33 +0200	[thread overview]
Message-ID: <FD0143CD-5CEE-4F89-9972-5B65852CE15E@acm.org> (raw)
In-Reply-To: <87lftrrg5l.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 245 bytes --]

11 okt. 2019 kl. 07.43 skrev Lars Ingebrigtsen <larsi@gnus.org>:
> 
> I guess that makes sense.  We (possibly) lose text properties here, but
> we don't care about those anyway in this context, I think?

Oops, that wasn't intended. Second try.


[-- Attachment #2: 0001-Correctly-explain-test-failures-with-mixed-uni-multi.patch --]
[-- Type: application/octet-stream, Size: 3238 bytes --]

From 48514a003a591ca6ef9d5b2cc9678727b3d93b47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 10 Oct 2019 21:20:20 +0200
Subject: [PATCH] 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 da241e6304..16a6d753f3 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -512,6 +512,11 @@ ert--explain-equal-rec
                      (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 36db1eeb42..3a9e81595b 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -627,6 +627,29 @@ ert-test-explain-equal
     (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)))))
-- 
2.21.0 (Apple Git-122)


  reply	other threads:[~2019-10-11  9:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 22:55 bug#30219: 27.0.50; (should (equal ...)) bug for string equality Philipp
2019-10-09 21:29 ` Lars Ingebrigtsen
2019-10-10 14:34 ` Mattias Engdegård
2019-10-10 19:29   ` Mattias Engdegård
2019-10-11  5:43     ` Lars Ingebrigtsen
2019-10-11  9:21       ` Mattias Engdegård [this message]
2019-10-13 18:10         ` Lars Ingebrigtsen
2019-10-13 18:30           ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FD0143CD-5CEE-4F89-9972-5B65852CE15E@acm.org \
    --to=mattiase@acm.org \
    --cc=30219@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=p.stephani2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.