diff options
| author | F. Jason Park | 2024-10-12 14:33:25 -0700 |
|---|---|---|
| committer | F. Jason Park | 2024-10-18 18:37:58 -0700 |
| commit | a5b2de8b54c3a2d7dcb84f7697e18b2257959dfc (patch) | |
| tree | f6c4375da0e18ed6d0bb1d8149602ef890bc481c /test | |
| parent | b00f400d1d3f954e460ea979f07f38f6bb31630e (diff) | |
| download | emacs-a5b2de8b54c3a2d7dcb84f7697e18b2257959dfc.tar.gz emacs-a5b2de8b54c3a2d7dcb84f7697e18b2257959dfc.zip | |
Fix trailing args bug in erc-d-i--parse-message
* test/lisp/erc/resources/erc-d/erc-d-i.el: Require `subr-x'.
(erc-d-i--parse-message): Populate `contents' slot when lone trailing
arg lacks a preceding colon.
* test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message):
Fix expected result.
(erc-d-i--parse-message/privmsg): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/erc/resources/erc-d/erc-d-i.el | 18 | ||||
| -rw-r--r-- | test/lisp/erc/resources/erc-d/erc-d-tests.el | 30 |
2 files changed, 39 insertions, 9 deletions
diff --git a/test/lisp/erc/resources/erc-d/erc-d-i.el b/test/lisp/erc/resources/erc-d/erc-d-i.el index 219ab6d63f0..97cd56408ce 100644 --- a/test/lisp/erc/resources/erc-d/erc-d-i.el +++ b/test/lisp/erc/resources/erc-d/erc-d-i.el | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | (require 'cl-lib) | 24 | (require 'cl-lib) |
| 25 | (require 'subr-x) | ||
| 25 | 26 | ||
| 26 | (cl-defstruct (erc-d-i-message (:conc-name erc-d-i-message.)) | 27 | (cl-defstruct (erc-d-i-message (:conc-name erc-d-i-message.)) |
| 27 | "Identical to `erc-response'. | 28 | "Identical to `erc-response'. |
| @@ -101,18 +102,19 @@ With DECODE, decode as UTF-8 text." | |||
| 101 | (setq s (decode-coding-string s 'utf-8 t))) | 102 | (setq s (decode-coding-string s 'utf-8 t))) |
| 102 | (let ((mes (make-erc-d-i-message :unparsed s :compat (not decode))) | 103 | (let ((mes (make-erc-d-i-message :unparsed s :compat (not decode))) |
| 103 | tokens) | 104 | tokens) |
| 104 | (when-let* (((not (string-empty-p s))) | 105 | (when-let (((not (string-empty-p s))) |
| 105 | ((eq ?@ (aref s 0))) | 106 | ((eq ?@ (aref s 0))) |
| 106 | (m (string-match " " s)) | 107 | (m (string-match " " s)) |
| 107 | (u (substring s 1 m))) | 108 | (u (substring s 1 m))) |
| 108 | (setf (erc-d-i-message.tags mes) (erc-d-i--validate-tags u) | 109 | (setf (erc-d-i-message.tags mes) (erc-d-i--validate-tags u) |
| 109 | s (substring s (1+ m)))) | 110 | s (substring s (1+ m)))) |
| 110 | (if-let* ((m (string-match " :" s)) | 111 | (if-let ((m (string-search " :" s)) |
| 111 | (other-toks (split-string (substring s 0 m) " " t)) | 112 | (other-toks (split-string (substring s 0 m) " " t)) |
| 112 | (rest (substring s (+ 2 m)))) | 113 | (rest (substring s (+ 2 m)))) |
| 113 | (setf (erc-d-i-message.contents mes) rest | 114 | (setf (erc-d-i-message.contents mes) rest |
| 114 | tokens (nconc other-toks (list rest))) | 115 | tokens (nconc other-toks (list rest))) |
| 115 | (setq tokens (split-string s " " t " "))) | 116 | (setf tokens (split-string s " " t " ") |
| 117 | (erc-d-i-message.contents mes) (car (last tokens)))) | ||
| 116 | (when (and tokens (eq ?: (aref (car tokens) 0))) | 118 | (when (and tokens (eq ?: (aref (car tokens) 0))) |
| 117 | (setf (erc-d-i-message.sender mes) (substring (pop tokens) 1))) | 119 | (setf (erc-d-i-message.sender mes) (substring (pop tokens) 1))) |
| 118 | (setf (erc-d-i-message.command mes) (or (pop tokens) "") | 120 | (setf (erc-d-i-message.command mes) (or (pop tokens) "") |
diff --git a/test/lisp/erc/resources/erc-d/erc-d-tests.el b/test/lisp/erc/resources/erc-d/erc-d-tests.el index 63d304907ea..a626ddd8edc 100644 --- a/test/lisp/erc/resources/erc-d/erc-d-tests.el +++ b/test/lisp/erc/resources/erc-d/erc-d-tests.el | |||
| @@ -248,9 +248,37 @@ | |||
| 248 | 'decode)) | 248 | 'decode)) |
| 249 | (should-not (erc-d-i-message.compat ours)) | 249 | (should-not (erc-d-i-message.compat ours)) |
| 250 | (should (equal (erc-d-i-message.command-args ours) '("#chàn"))) | 250 | (should (equal (erc-d-i-message.command-args ours) '("#chàn"))) |
| 251 | (should (equal (erc-d-i-message.contents ours) "")) | 251 | (should (equal (erc-d-i-message.contents ours) "#chàn")) |
| 252 | (should (equal (erc-d-i-message.tags ours) '((foo . "çedilla"))))))) | 252 | (should (equal (erc-d-i-message.tags ours) '((foo . "çedilla"))))))) |
| 253 | 253 | ||
| 254 | (ert-deftest erc-d-i--parse-message/privmsg () | ||
| 255 | (dolist (raw '(":Bob!~bob@gnu.org PRIVMSG #chan :one two" | ||
| 256 | ":Bob!~bob@gnu.org PRIVMSG #chan one" | ||
| 257 | ":Bob!~bob@gnu.org PRIVMSG #chan : " | ||
| 258 | ":Bob!~bob@gnu.org PRIVMSG #chan :" | ||
| 259 | "@account=bob :Bob!~bob@gnu.org PRIVMSG #chan one" | ||
| 260 | "@foo=bar;baz :Bob!~bob@gnu.org PRIVMSG #chan :one")) | ||
| 261 | (dolist (slot '(unparsed | ||
| 262 | sender | ||
| 263 | command | ||
| 264 | command-args | ||
| 265 | contents | ||
| 266 | tags)) | ||
| 267 | (let ((ours (erc-d-i--parse-message raw)) | ||
| 268 | (orig (erc-d-tests--parse-message-upstream raw))) | ||
| 269 | (ert-info ((format "slot: `%s', orig: %S, ours: %S" | ||
| 270 | slot orig ours)) | ||
| 271 | (if (eq slot 'tags) | ||
| 272 | (should (equal (erc-response.tags orig) | ||
| 273 | (mapcar (pcase-lambda (`(,key . ,value)) | ||
| 274 | (if value | ||
| 275 | (list (symbol-name key) value) | ||
| 276 | (list (symbol-name key)))) | ||
| 277 | (reverse (erc-d-i-message.tags ours))))) | ||
| 278 | (should | ||
| 279 | (equal (cl-struct-slot-value 'erc-d-i-message slot ours) | ||
| 280 | (cl-struct-slot-value 'erc-response slot orig))))))))) | ||
| 281 | |||
| 254 | (ert-deftest erc-d-i--unescape-tag-value () | 282 | (ert-deftest erc-d-i--unescape-tag-value () |
| 255 | (should (equal (erc-d-i--unescape-tag-value | 283 | (should (equal (erc-d-i--unescape-tag-value |
| 256 | "\\sabc\\sdef\\s\\sxyz\\s") | 284 | "\\sabc\\sdef\\s\\sxyz\\s") |