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

;;; Commentary:

;;; Code:

(require 'erc-button)

(defun erc-button-tests--insert-privmsg (speaker &rest msg-parts)
  (declare (indent 1))
  (let ((msg (erc-format-privmessage speaker
                                     (apply #'concat msg-parts) nil t)))
    (erc-display-message nil nil (current-buffer) msg)))

(defun erc-button-tests--populate (test)
  (let ((inhibit-message noninteractive)
        erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)

    (with-current-buffer
        (cl-letf
            (((symbol-function 'erc-server-connect)
              (lambda (&rest _)
                (setq erc-server-process
                      (start-process "sleep" (current-buffer) "sleep" "1"))
                (set-process-query-on-exit-flag erc-server-process nil))))

          (erc-open "localhost" 6667 "tester" "Tester" 'connect
                    nil nil nil nil nil "tester" 'foonet))

      (with-current-buffer (erc--open-target "#chan")
        (erc-update-channel-member
         "#chan" "alice" "alice" t nil nil nil nil nil "fake" "~u" nil nil t)

        (erc-update-channel-member
         "#chan" "bob" "bob" t nil nil nil nil nil "fake" "~u" nil nil t)

        (erc-display-message
         nil 'notice (current-buffer)
         (concat "This server is in debug mode and is logging all user I/O. "
                 "Blah alice (1) bob (2) blah."))

        (funcall test))

      (when noninteractive
        (kill-buffer "#chan")
        (kill-buffer)))))

(ert-deftest erc-button-next ()
  (erc-button-tests--populate
   (lambda ()
     (erc-button-tests--insert-privmsg "alice"
       "(3) bob (4) come, you are a tedious fool: to the purpose.")

     (erc-button-tests--insert-privmsg "bob"
       "(5) alice (6) Come me to what was done to her.")

     (should (= erc-input-marker (point)))

     ;; Break out of input area
     (erc-button-previous 1)
     (should (looking-at (rx "alice (6)")))

     ;; No next button
     (should-error (erc-button-next 1) :type 'user-error)
     (should (looking-at (rx "alice (6)")))

     ;; Next with negative arg is equivalent to previous
     (erc-button-next -1)
     (should (looking-at (rx "bob> (5)")))

     ;; One past end of button
     (forward-char 3)
     (should (looking-at (rx "> (5)")))
     (should-not (get-text-property (point) 'erc-callback))
     (erc-button-previous 1)
     (should (looking-at (rx "bob> (5)")))

     ;; At end of button
     (forward-char 2)
     (should (looking-at (rx "b> (5)")))
     (erc-button-previous 1)
     (should (looking-at (rx "bob (4)")))

     ;; Skip multiple buttons back
     (erc-button-previous 2)
     (should (looking-at (rx "bob (2)")))

     ;; Skip multiple buttons forward
     (erc-button-next 2)
     (should (looking-at (rx "bob (4)")))

     ;; No error as long as some progress made
     (erc-button-previous 100)
     (should (looking-at (rx "alice (1)")))

     ;; Error when no progress made
     (should-error (erc-button-previous 1) :type 'user-error)
     (should (looking-at (rx "alice (1)"))))))

;; See also `erc-scenarios-networks-announced-missing' in
;; erc-scenarios-misc.el for a more realistic example.
(ert-deftest erc-button--display-error-notice-with-keys ()
  (with-current-buffer (get-buffer-create "*fake*")
    (let ((mode erc-button-mode)
          (inhibit-message noninteractive)
          erc-modules
          erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
      (erc-mode)
      (setq erc-server-process
            (start-process "sleep" (current-buffer) "sleep" "1"))
      (set-process-query-on-exit-flag erc-server-process nil)
      (erc--initialize-markers (point) nil)
      (erc-button-mode +1)
      (should (equal (erc-button--display-error-notice-with-keys
                      "If \\[erc-bol] fails, "
                      "see \\[erc-bug] or `erc-mode-map'.")
                     "*** If C-a fails, see M-x erc-bug or `erc-mode-map'."))
      (goto-char (point-min))

      (ert-info ("Keymap substitution succeeds")
        (erc-button-next 1)
        (should (looking-at "C-a"))
        (should (eq (get-text-property (point) 'mouse-face) 'highlight))
        (erc-button-press-button)
        (with-current-buffer "*Help*"
          (goto-char (point-min))
          (should (search-forward "erc-bol" nil t)))
        (erc-button-next 1)
        ;; End of interval correct
        (erc-button-previous 1)
        (should (looking-at "C-a fails")))

      (ert-info ("Extended command mapping succeeds")
        (erc-button-next 1)
        (should (looking-at "M-x erc-bug"))
        (erc-button-press-button)
        (should (eq (get-text-property (point) 'mouse-face) 'highlight))
        (with-current-buffer "*Help*"
          (goto-char (point-min))
          (should (search-forward "erc-bug" nil t))))

      (ert-info ("Symbol-description face preserved") ; mutated by d-e-n-w-k
        (erc-button-next 1)
        (should (equal (get-text-property (point) 'font-lock-face)
                       '(erc-button erc-error-face)))
        (should (eq (get-text-property (point) 'mouse-face) 'highlight))
        (should (eq erc-button-face 'erc-button))) ; extent evaporates

      (ert-info ("Format when trailing args include non-strings")
        (should (equal (erc-button--display-error-notice-with-keys
                        "abc" " %d def" " 45%s" 123 '\6)
                       "*** abc 123 def 456")))

      (when noninteractive
        (unless mode
          (erc-button-mode -1))
        (kill-buffer "*Help*")
        (kill-buffer)))))

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

debug log:

solving ced08d117bc ...
found ced08d117bc in https://git.savannah.gnu.org/cgit/emacs.git

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