unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 9fc744468f3109840e43960ac6169ad11d54153c 10470 bytes (raw)
name: test/lisp/erc/erc-scenarios-match.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
 
;;; erc-scenarios-match.el --- Misc `erc-match' scenarios -*- lexical-binding: t -*-

;; Copyright (C) 2023 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'ert-x)
(eval-and-compile
  (let ((load-path (cons (ert-resource-directory) load-path)))
    (require 'erc-scenarios-common)))

(require 'erc-stamp)
(require 'erc-match)
(require 'erc-fill)

;; This defends against a regression in which all matching by the
;; `erc-match-message' fails when `erc-add-timestamp' precedes it in
;; `erc-insert-modify-hook'.  Basically, `erc-match-message' used to
;; expect an `erc-parsed' text property on the first character in a
;; message, which doesn't exist, when the message content is prefixed
;; by a leading timestamp.

(ert-deftest erc-scenarios-match--stamp-left-current-nick ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/reconnect")
       (dumb-server (erc-d-run "localhost" t 'unexpected-disconnect))
       (port (process-contact dumb-server :service))
       (erc-server-flood-penalty 0.1)
       (erc-insert-timestamp-function 'erc-insert-timestamp-left)
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :full-name "tester"
                                :nick "tester")
        ;; Module `timestamp' precedes `match' in insertion hooks.
        (should (memq 'erc-add-timestamp
                      (memq 'erc-match-message erc-insert-modify-hook)))
        ;; The "match type" is `current-nick'.
        (funcall expect 5 "tester")
        (should (eq (get-text-property (1- (point)) 'font-lock-face)
                    'erc-current-nick-face))))))

;; When hacking on tests that use this fixture, it's best to run it
;; interactively, and check for wierdness before and after doing
;; M-: (remove-from-invisibility-spec 'erc-match) RET.
(defun erc-scenarios-match--invisible-stamp (hiddenp visiblep)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "join/legacy")
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (port (process-contact dumb-server :service))
       (erc-server-flood-penalty 0.1)
       (erc-timestamp-only-if-changed-flag nil)
       (erc-fools '("bob"))
       (erc-text-matched-hook '(erc-hide-fools))
       (erc-autojoin-channels-alist '((FooNet "#chan")))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :full-name "tester"
                                :password "changeme"
                                :nick "tester")
        ;; Module `timestamp' precedes `match' in insertion hooks.
        (should (memq 'erc-add-timestamp
                      (memq 'erc-match-message erc-insert-modify-hook)))
        (funcall expect 5 "This server is in debug mode")))

    (ert-info ("Ensure lines featuring \"bob\" are invisible")
      (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
        (should (funcall expect 10 "<bob> tester, welcome!"))
        (ert-info ("<bob> tester, welcome!") (funcall hiddenp))

        ;; Alice's is the only one visible.
        (should (funcall expect 10 "<alice> tester, welcome!"))
        (ert-info ("<alice> tester, welcome!") (funcall visiblep))

        (should (funcall expect 10 "<bob> alice: But, as it seems"))
        (ert-info ("<bob> alice: But, as it seems") (funcall hiddenp))

        (should (funcall expect 10 "<alice> bob: Well, this is the forest"))
        (ert-info ("<alice> bob: Well, this is the forest") (funcall hiddenp))

        (should (funcall expect 10 "<alice> bob: And will you"))
        (ert-info ("<alice> bob: And will you") (funcall hiddenp))

        (should (funcall expect 10 "<bob> alice: Live, and be prosperous"))
        (ert-info ("<bob> alice: Live, and be prosperous") (funcall hiddenp))

        (should (funcall expect 10 "ERC>"))
        (should-not (get-text-property (pos-bol) 'invisible))
        (should-not (get-text-property (point) 'invisible))))))

;; This asserts that when stamps appear before a message, registered
;; invisibility properties owned by modules span the entire message.
(ert-deftest erc-scenarios-match--stamp-left-fools-invisible ()
  :tags '(:expensive-test)
  (let ((erc-insert-timestamp-function #'erc-insert-timestamp-left))
    (erc-scenarios-match--invisible-stamp

     (lambda ()
       ;; This is a time-stamped message.
       (should (eq (field-at-pos (pos-bol)) 'erc-timestamp))

       ;; Leading stamp has combined `invisible' property value.
       (should (equal (get-text-property (pos-bol) 'invisible)
                      '(timestamp erc-match)))

       ;; Message proper has the `invisible' property `erc-match'.
       (let ((msg-beg (next-single-property-change (pos-bol) 'invisible)))
         (should (eq (get-text-property msg-beg 'invisible) 'erc-match))
         (should (>= (next-single-property-change msg-beg 'invisible nil)
                     (pos-eol)))))

     (lambda ()
       ;; This is a time-stamped message.
       (should (eq (field-at-pos (pos-bol)) 'erc-timestamp))
       (should (get-text-property (pos-bol) 'invisible))

       ;; The entire message proper is visible.
       (let ((msg-beg (next-single-property-change (pos-bol) 'invisible)))
         (should
          (= (next-single-property-change msg-beg 'invisible nil (pos-eol))
             (pos-eol))))))))

(defun erc-scenarios-match--find-eol ()
  (save-excursion
    (goto-char (next-single-property-change (point) 'erc-command))
    (pos-eol)))

;; In most cases, `erc-hide-fools' makes line endings invisible.
(ert-deftest erc-scenarios-match--stamp-right-fools-invisible ()
  :tags '(:expensive-test)
  (let ((erc-insert-timestamp-function #'erc-insert-timestamp-right))
    (erc-scenarios-match--invisible-stamp

     (lambda ()
       (let ((end (erc-scenarios-match--find-eol)))
         ;; The end of the message is a newline.
         (should (= ?\n (char-after end)))

         ;; Every message has a trailing time stamp.
         (should (eq (field-at-pos (1- end)) 'erc-timestamp))

         ;; Stamps have a combined `invisible' property value.
         (should (equal (get-text-property (1- end) 'invisible)
                        '(timestamp erc-match)))

         ;; The final newline is hidden by `match', not `stamps'
         (should (equal (get-text-property end 'invisible) 'erc-match))

         ;; The message proper has the `invisible' property `erc-match',
         ;; and it starts after the preceding newline.
         (should (eq (get-text-property (pos-bol) 'invisible) 'erc-match))

         ;; It ends just before the timestamp.
         (let ((msg-end (next-single-property-change (pos-bol) 'invisible)))
           (should (equal (get-text-property msg-end 'invisible)
                          '(timestamp erc-match)))

           ;; Stamp's `invisible' property extends throughout the stamp
           ;; and ends before the trailing newline.
           (should (= (next-single-property-change msg-end 'invisible) end)))))

     (lambda ()
       (let ((end (erc-scenarios-match--find-eol)))
         ;; This message has a time stamp like all the others.
         (should (eq (field-at-pos (1- end)) 'erc-timestamp))

         ;; The entire message proper is visible.
         (should-not (get-text-property (pos-bol) 'invisible))
         (let ((inv-beg (next-single-property-change (pos-bol) 'invisible)))
           (should (eq (get-text-property inv-beg 'invisible)
                       'timestamp))))))))

;; This asserts that when `erc-fill-wrap-mode' is enabled, ERC hides
;; the preceding message's line ending.
(ert-deftest erc-scenarios-match--stamp-right-invisible-fill-wrap ()
  :tags '(:expensive-test)
  (let ((erc-insert-timestamp-function #'erc-insert-timestamp-right)
        (erc-fill-function #'erc-fill-wrap))
    (erc-scenarios-match--invisible-stamp

     (lambda ()
       ;; Every message has a trailing time stamp.
       (should (eq (field-at-pos (1- (pos-eol))) 'erc-timestamp))

       ;; Stamps appear in the right margin.
       (should (equal (car (get-text-property (1- (pos-eol)) 'display))
                      '(margin right-margin)))

       ;; Stamps have a combined `invisible' property value.
       (should (equal (get-text-property (1- (pos-eol)) 'invisible)
                      '(timestamp erc-match)))

       ;; The message proper has the `invisible' property `erc-match',
       ;; which starts at the preceding newline...
       (should (eq (get-text-property (1- (pos-bol)) 'invisible) 'erc-match))

       ;; ... and ends just before the timestamp.
       (let ((msgend (next-single-property-change (1- (pos-bol)) 'invisible)))
         (should (equal (get-text-property msgend 'invisible)
                        '(timestamp erc-match)))

         ;; The newline before `erc-insert-marker' is still visible.
         (should-not (get-text-property (pos-eol) 'invisible))
         (should (= (next-single-property-change msgend 'invisible)
                    (pos-eol)))))

     (lambda ()
       ;; This message has a time stamp like all the others.
       (should (eq (field-at-pos (1- (pos-eol))) 'erc-timestamp))

       ;; Unlike hidden messages, the preceding newline is visible.
       (should-not (get-text-property (1- (pos-bol)) 'invisible))

       ;; The entire message proper is visible.
       (let ((inv-beg (next-single-property-change (1- (pos-bol)) 'invisible)))
         (should (eq (get-text-property inv-beg 'invisible) 'timestamp)))))))

(eval-when-compile (require 'erc-join))

;;; erc-scenarios-match.el ends here

debug log:

solving 9fc744468f3 ...
found 9fc744468f3 in https://yhetil.org/emacs-bugs/87zg4dm91k.fsf__19941.212928255$1688390142$gmane$org@neverwas.me/
found 61368919d31 in https://yhetil.org/emacs-bugs/87zg4dm91k.fsf__19941.212928255$1688390142$gmane$org@neverwas.me/
found 49e6a3370fc in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 49e6a3370fc371d0fb852b93d48fed61c12821a7	test/lisp/erc/erc-scenarios-match.el

applying [1/2] https://yhetil.org/emacs-bugs/87zg4dm91k.fsf__19941.212928255$1688390142$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-scenarios-match.el b/test/lisp/erc/erc-scenarios-match.el
index 49e6a3370fc..61368919d31 100644


applying [2/2] https://yhetil.org/emacs-bugs/87zg4dm91k.fsf__19941.212928255$1688390142$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-scenarios-match.el b/test/lisp/erc/erc-scenarios-match.el
index 61368919d31..9fc744468f3 100644

Checking patch test/lisp/erc/erc-scenarios-match.el...
Applied patch test/lisp/erc/erc-scenarios-match.el cleanly.
Checking patch test/lisp/erc/erc-scenarios-match.el...
Applied patch test/lisp/erc/erc-scenarios-match.el cleanly.

index at:
100644 9fc744468f3109840e43960ac6169ad11d54153c	test/lisp/erc/erc-scenarios-match.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).