unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob cf243ef43c7e7a45371b7fa1cd648961ac1b08cf 6407 bytes (raw)
name: test/lisp/erc/erc-fill-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
 
;;; erc-fill-tests.el --- Tests for erc-fill  -*- 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 'ert-x)
(require 'erc-fill)

(defun erc-fill-tests--wrap-populate (test)
  (let ((proc (start-process "sleep" (current-buffer) "sleep" "1"))
        (id (erc-networks--id-create 'foonet))
        (erc-insert-modify-hook '(erc-fill erc-add-timestamp))
        (erc-server-users (make-hash-table :test 'equal))
        (erc-fill-function 'erc-fill-wrap)
        (erc-modules '(fill stamp))
        (msg "Hello World")
        erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
    (when (bound-and-true-p erc-button-mode)
      (push 'erc-button-add-buttons erc-insert-modify-hook))
    (erc-mode)
    (setq erc-server-process proc erc-networks--id id)

    (with-current-buffer (get-buffer-create "#chan")
      (erc-mode)
      (erc-munge-invisibility-spec)
      (setq erc-server-process proc
            erc-networks--id id
            erc-channel-users (make-hash-table :test 'equal)
            erc--target (erc--target-from-string "#chan")
            erc-default-recipients (list "#chan"))
      (erc--initialize-markers (point) nil)

      (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)
      (setq msg "This server is in debug mode and is logging all user I/O.\
 If you do not wish for everything you send to be readable\
 by the server owner(s), please disconnect.")

      (erc-display-message nil 'notice (current-buffer) msg)
      (setq msg "bob: come, you are a tedious fool: to the purpose.\
 What was done to Elbow's wife, that he hath cause to complain of?\
 Come me to what was done to her.")

      (erc-display-message
       nil nil (current-buffer)
       (erc--format-privmsg "alice" msg nil t nil))
      (setq msg "alice: Either your unparagoned mistress is dead,\
 or she's outprized by a trifle.")

      (erc-display-message
       nil nil (current-buffer)
       (erc--format-privmsg "bob" msg nil t nil))

      (funcall test)
      (when noninteractive
        (kill-buffer)))))

(ert-deftest erc-fill-wrap--monospace ()
  :tags '(:unstable)

  (erc-fill-tests--wrap-populate

   (lambda ()

     ;; Prefix props are applied properly and faces are accounted
     ;; for when determining widths.
     (goto-char (point-min))
     (should (search-forward "<a" nil t))
     (should (get-text-property (pos-bol) 'line-prefix))
     (should (get-text-property (pos-eol) 'line-prefix))
     (should (equal (get-text-property (pos-bol) 'wrap-prefix)
                    '(space :width 27)))
     (should (equal (get-text-property (pos-eol) 'wrap-prefix)
                    '(space :width 27)))
     (should (pcase (get-text-property (point) 'line-prefix)
               (`(space :width (- 27 (,w)))
                (should (= w (string-pixel-width "<alice> "))))))

     (erc-fill--wrap-nudge 2)

     (should (search-forward "<b" nil t))
     (should (get-text-property (pos-bol) 'line-prefix))
     (should (get-text-property (pos-eol) 'line-prefix))
     (should (equal (get-text-property (pos-bol) 'wrap-prefix)
                    '(space :width 29)))
     (should (equal (get-text-property (pos-eol) 'wrap-prefix)
                    '(space :width 29)))
     (should (pcase (get-text-property (point) 'line-prefix)
               (`(space :width (- 29 (,w)))
                (should (= w (string-pixel-width "<bob> ")))))))))

(ert-deftest erc-fill-wrap--variable-pitch ()
  :tags '(:unstable)
  (unless (and (not noninteractive) (display-graphic-p))
    (ert-skip "Test needs interactive graphical Emacs"))

  (with-selected-frame (make-frame '((name . "other")))
    (set-face-attribute 'default (selected-frame)
                        :family "Sans Serif"
                        :foundry 'unspecified
                        :font 'unspecified)

    (erc-fill-tests--wrap-populate

     (lambda ()

       ;; Prefix props are applied properly and faces are accounted
       ;; for when determining widths.
       (goto-char (point-min))
       (should (search-forward "<a" nil t))
       (should (get-text-property (pos-bol) 'line-prefix))
       (should (get-text-property (pos-eol) 'line-prefix))
       (should (equal (get-text-property (pos-bol) 'wrap-prefix)
                      '(space :width 27)))
       (should (equal (get-text-property (pos-eol) 'wrap-prefix)
                      '(space :width 27)))
       (should (pcase (get-text-property (point) 'line-prefix)
                 (`(space :width (- 27 (,w)))
                  (should (> w (string-pixel-width "<alice> "))))))

       (erc-fill--wrap-nudge 2)

       (should (search-forward "<b" nil t))
       (should (get-text-property (pos-bol) 'line-prefix))
       (should (get-text-property (pos-eol) 'line-prefix))
       (should (equal (get-text-property (pos-bol) 'wrap-prefix)
                      '(space :width 29)))
       (should (equal (get-text-property (pos-eol) 'wrap-prefix)
                      '(space :width 29)))
       (should (pcase (get-text-property (point) 'line-prefix)
                 (`(space :width (- 29 (,w)))
                  (should (> w (string-pixel-width "<bob> "))))))

       ;; FIXME figure out how to get rid of this "void variable
       ;; `erc--results-ewoc'" error, which seems related to operating
       ;; in this second frame.
       ;;
       ;; As a kludge, checking if point made it to the prompt can
       ;; serve as visual confirmation that the test passed.
       (goto-char (point-max))))))

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

debug log:

solving cf243ef43c7 ...
found cf243ef43c7 in https://yhetil.org/emacs-bugs/87a626iu0u.fsf__1312.36317554198$1674655967$gmane$org@neverwas.me/

applying [1/1] https://yhetil.org/emacs-bugs/87a626iu0u.fsf__1312.36317554198$1674655967$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
new file mode 100644
index 00000000000..cf243ef43c7

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

skipping https://yhetil.org/emacs-bugs/87a626iu0u.fsf__1312.36317554198$1674655967$gmane$org@neverwas.me/ for cf243ef43c7
index at:
100644 cf243ef43c7e7a45371b7fa1cd648961ac1b08cf	test/lisp/erc/erc-fill-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).