unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 7f0159544f1f396adfe213cd7f682791bc88d09f 7110 bytes (raw)
name: test/lisp/erc/erc-match-tests.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
 
;;; erc-match-tests.el --- Tests for erc-match.  -*- lexical-binding:t -*-

;; Copyright (C) 2022 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/>.

;;; Commentary:
;;; Code:

(require 'ert-x)
(require 'erc-match)

(ert-deftest erc-pals ()
  (with-temp-buffer
    (setq erc-server-process (start-process "true" (current-buffer) "true")
          erc-server-users (make-hash-table :test #'equal))
    (set-process-query-on-exit-flag erc-server-process nil)
    (erc-add-server-user "FOO[m]" (make-erc-server-user :nickname "foo[m]"))
    (erc-add-server-user "tester" (make-erc-server-user :nickname "tester"))

    (let (erc-pals calls rvs)
      (cl-letf (((symbol-function 'completing-read)
                 (lambda (&rest r) (push r calls) (pop rvs))))

        (ert-info ("`erc-add-pal'")
          (push "foo[m]" rvs)
          (ert-simulate-command '(erc-add-pal))
          (should (equal (cadr (pop calls)) '(("tester") ("foo[m]"))))
          (should (equal erc-pals '("foo\\[m]"))))

        (ert-info ("`erc-match-pal-p'")
          (should (erc-match-pal-p "FOO[m]!~u@example.net" nil)))

        (ert-info ("`erc-delete-pal'")
          (push "foo\\[m]" rvs)
          (ert-simulate-command '(erc-delete-pal))
          (should (equal (cadr (pop calls)) '(("foo\\[m]"))))
          (should-not erc-pals))))))

(ert-deftest erc-fools ()
  (with-temp-buffer
    (setq erc-server-process (start-process "true" (current-buffer) "true")
          erc-server-users (make-hash-table :test #'equal))
    (set-process-query-on-exit-flag erc-server-process nil)
    (erc-add-server-user "FOO[m]" (make-erc-server-user :nickname "foo[m]"))
    (erc-add-server-user "tester" (make-erc-server-user :nickname "tester"))

    (let (erc-fools calls rvs)
      (cl-letf (((symbol-function 'completing-read)
                 (lambda (&rest r) (push r calls) (pop rvs))))

        (ert-info ("`erc-add-fool'")
          (push "foo[m]" rvs)
          (ert-simulate-command '(erc-add-fool))
          (should (equal (cadr (pop calls)) '(("tester") ("foo[m]"))))
          (should (equal erc-fools '("foo\\[m]"))))

        (ert-info ("`erc-match-fool-p'")
          (should (erc-match-fool-p "FOO[m]!~u@example.net" ""))
          (should (erc-match-fool-p "tester!~u@example.net" "FOO[m]: die")))

        (ert-info ("`erc-delete-fool'")
          (push "foo\\[m]" rvs)
          (ert-simulate-command '(erc-delete-fool))
          (should (equal (cadr (pop calls)) '(("foo\\[m]"))))
          (should-not erc-fools))))))

(ert-deftest erc-keywords ()
  (let (erc-keywords calls rvs)
    (cl-letf (((symbol-function 'completing-read)
               (lambda (&rest r) (push r calls) (pop rvs))))

      (ert-info ("`erc-add-keyword'")
        (push "[cit. needed]" rvs)
        (ert-simulate-command '(erc-add-keyword))
        (should (equal (cadr (pop calls)) nil))
        (should (equal erc-keywords '("\\[cit\\. needed]"))))

      (ert-info ("`erc-match-keyword-p'")
        (should (erc-match-keyword-p nil "is pretty [cit. needed]")))

      (ert-info ("`erc-delete-keyword'")
        (push "\\[cit\\. needed]" rvs)
        (ert-simulate-command '(erc-delete-keyword))
        (should (equal (cadr (pop calls)) '(("\\[cit\\. needed]"))))
        (should-not erc-keywords)))))

(ert-deftest erc-dangerous-hosts ()
  (let (erc-dangerous-hosts calls rvs)
    (cl-letf (((symbol-function 'completing-read)
               (lambda (&rest r) (push r calls) (pop rvs))))

      (ert-info ("`erc-add-dangerous-host'")
        (push "example.net" rvs)
        (ert-simulate-command '(erc-add-dangerous-host))
        (should (equal (cadr (pop calls)) nil))
        (should (equal erc-dangerous-hosts '("example\\.net"))))

      (ert-info ("`erc-match-dangerous-host-p'")
        (should (erc-match-dangerous-host-p "FOO[m]!~u@example.net" nil)))

      (ert-info ("`erc-delete-dangerous-host'")
        (push "example\\.net" rvs)
        (ert-simulate-command '(erc-delete-dangerous-host))
        (should (equal (cadr (pop calls)) '(("example\\.net"))))
        (should-not erc-dangerous-hosts)))))

(defun erc-match-tests--populate ()
  (let ((erc-keywords `("five" ("six" font-lock-string-face) "\\<t.."))
        (erc-insert-modify-hook '(erc-match-message)))

    (erc-display-message
     (make-erc-response
      :sender "alice!~u@example.net"
      :command "PRIVMSG"
      :contents "one two three"
      :command-args '("#chan" "one two three"))
     nil (current-buffer)
     (erc-format-privmessage "alice" "one two three" nil t))

    (erc-display-message
     (make-erc-response
      :sender "bob!~u@example.net"
      :command "PRIVMSG"
      :contents "four five six"
      :command-args '("#chan" "four five six"))
     nil (current-buffer)
     (erc-format-privmessage "bob" "four five six" nil t))))

(ert-deftest erc-match-next-keyword ()
  (with-current-buffer (get-buffer-create "#chan")
    (erc-mode)
    (insert "\n\n")
    (setq erc-input-marker (make-marker)
          erc-insert-marker (make-marker)
          erc-server-current-nick "tester")
    (set-marker erc-insert-marker (point-max))
    (erc-display-prompt)
    (erc-match-tests--populate)
    (should (= (point) erc-input-marker))

    (ert-info ("Back once")
      (ert-simulate-command '(erc-match-next-keyword -1))
      (should (looking-at "six")))

    (ert-info ("Back twice")
      (ert-simulate-command '(erc-match-next-keyword -2))
      (should (looking-at "three")))

    (ert-info ("Overshoot")
      (ert-simulate-command '(erc-match-next-keyword -2))
      (should (looking-at "two")))

    (ert-info ("About face")
      (ert-simulate-command '(erc-match-next-keyword 1))
      (should (looking-at "three")))

    (ert-info ("About face")
      (ert-simulate-command '(erc-match-next-keyword 1))
      (should (looking-at "five")))

    (ert-info ("Miss backward")
      (ert-simulate-command '(erc-match-next-keyword -100))
      (should (looking-at "two"))
      (backward-char)
      (let ((p (point)))
        (ert-simulate-command '(erc-match-next-keyword -100))
        (should (= p (point)))))

    (ert-info ("Miss forwards")
      (ert-simulate-command '(erc-match-next-keyword 100))
      (should (looking-at "six"))
      (goto-char (1+ (line-end-position)))
      (let ((p (point)))
        (ert-simulate-command '(erc-match-next-keyword 1))
        (should (= p (point)))))

    (when noninteractive (kill-buffer))))

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

debug log:

solving 7f0159544f ...
found 7f0159544f in https://yhetil.org/emacs-bugs/87fsjb68g1.fsf@neverwas.me/
found aed23e665d in https://yhetil.org/emacs-bugs/87fsjb68g1.fsf@neverwas.me/

applying [1/2] https://yhetil.org/emacs-bugs/87fsjb68g1.fsf@neverwas.me/
diff --git a/test/lisp/erc/erc-match-tests.el b/test/lisp/erc/erc-match-tests.el
new file mode 100644
index 0000000000..aed23e665d


applying [2/2] https://yhetil.org/emacs-bugs/87fsjb68g1.fsf@neverwas.me/
diff --git a/test/lisp/erc/erc-match-tests.el b/test/lisp/erc/erc-match-tests.el
index aed23e665d..7f0159544f 100644

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

index at:
100644 7f0159544f1f396adfe213cd7f682791bc88d09f	test/lisp/erc/erc-match-tests.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).