unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: "Štěpán Němec" <stepnem@gmail.com>
Cc: lars <lars@nocrew.org>, 40562@debbugs.gnu.org
Subject: bug#40562: [patch] Treat records as arrays in ert object comparisons and add support for cl-structs
Date: Sat, 11 Apr 2020 23:06:47 -0400	[thread overview]
Message-ID: <11a23fdb-4512-0b80-0426-460be4fdf1cb@gmail.com> (raw)
In-Reply-To: <87a73heh8u.fsf@gmail.com>

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

On 11/04/2020 19.26, Štěpán Němec wrote:
> This is incorrect, as witnessed by your very example (`c' instead of
> `b'). Records are accessible with `aref', but the first slot is the type
> descriptor, so you're making an off-by-one error here.

Of course, it should be `for slot in (cl-struct-slot-info (type-of a))` not `for slot in (cdr (cl-struct-slot-info (type-of a)))`.  Updated patch attached.

Thanks for the review!

[-- Attachment #2: 0002-lisp-emacs-lisp-ert.el-ert-explain-equal-rec-Add-sup.patch --]
[-- Type: text/x-patch, Size: 1183 bytes --]

From 129ba8aeaa91b6ea44a325ec237f3df7e9400c9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit-Claudel?= <clement.pitclaudel@live.com>
Date: Sat, 11 Apr 2020 16:23:47 -0400
Subject: [PATCH 2/2] * lisp/emacs-lisp/ert.el (ert--explain-equal-rec): Add
 support for cl-structs

---
 lisp/emacs-lisp/ert.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 74202183cc..241eece05b 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -515,6 +515,13 @@ ert--explain-equal-rec
                        `(cdr ,cdr-x)
                      (cl-assert (equal a b) t)
                      nil))))))))
+      ((pred cl-struct-p)
+       (cl-loop for slot in (cl-struct-slot-info (type-of a))
+                for ai across a
+                for bi across b
+                for xf = (ert--explain-equal-rec ai bi)
+                do (when xf (cl-return `(struct-field ,(car slot) ,xf)))
+                finally (cl-assert (equal a b) t)))
       ((or (pred arrayp) (pred recordp))
        ;; For mixed unibyte/multibyte string comparisons, make both multibyte.
        (when (and (stringp a)
-- 
2.17.1


  reply	other threads:[~2020-04-12  3:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 20:34 bug#40562: [patch] Treat records as arrays in ert object comparisons and add support for cl-structs Clément Pit-Claudel
2020-04-11 23:26 ` Štěpán Němec
2020-04-12  3:06   ` Clément Pit-Claudel [this message]
2020-04-12  9:24     ` Štěpán Němec
2020-04-12 15:50       ` Clément Pit-Claudel
2020-04-25 21:27         ` Clément Pit-Claudel
2020-08-08 13:02           ` Lars Ingebrigtsen
2020-08-18 14:07             ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=11a23fdb-4512-0b80-0426-460be4fdf1cb@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=40562@debbugs.gnu.org \
    --cc=lars@nocrew.org \
    --cc=stepnem@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).