unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 7eccb859dbc3e9aa78c7ee1e598168be5328b1b8 5154 bytes (raw)
name: test/lisp/erc/erc-scenarios-prompt-format.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
 
;;; erc-scenarios-prompt-format.el --- erc-prompt-format-mode -*- 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)))

(defvar erc-fill-wrap-align-prompt)
(defvar erc-fill-wrap-use-pixels)

(defun erc-scenarios-prompt-format--assert (needle &rest props)
  (save-excursion
    (goto-char erc-insert-marker)
    (should (search-forward needle nil t))
    (pcase-dolist (`(,k . ,v) props)
      (should (equal (get-text-property (point) k) v)))))

;; This makes assertions about the option `erc-fill-wrap-align-prompt'
;; as well as the standard value of `erc-prompt-format'.  One minor
;; omission is that this doesn't check behavior in query buffers.
(ert-deftest erc-scenarios-prompt-format ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/modes")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'chan-changed))
       (erc-modules (cons 'fill-wrap erc-modules))
       (erc-fill-wrap-align-prompt t)
       (erc-fill-wrap-use-pixels nil)
       (erc-prompt #'erc-prompt-format)
       (erc-autojoin-channels-alist '((Libera.Chat "#chan")))
       (expect (erc-d-t-make-expecter))
       ;; Collect samples of `line-prefix' to verify deltas as the
       ;; prompt grows and shrinks.
       (line-prefixes nil)
       (stash-pfx (lambda ()
                    (pcase (get-text-property erc-insert-marker 'line-prefix)
                      (`(space :width (- erc-fill--wrap-value ,n))
                       (car (push n line-prefixes)))))))

    (ert-info ("Connect to Libera.Chat")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port (process-contact dumb-server :service)
                                :nick "tester"
                                :full-name "tester")
        (funcall expect 5 "Welcome to the Libera.Chat")
        (funcall stash-pfx)
        (funcall expect 5 "changed mode")
        ;; New prompt is shorter than default with placeholders, like
        ;; "(foo?)(bar?)" (assuming we win the inherent race).
        (should (>= (car line-prefixes) (funcall stash-pfx)))
        (erc-scenarios-prompt-format--assert "user-" '(display . ("Ziw")))))

    (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
      (should-not erc-channel-key)
      (should-not erc-channel-user-limit)

      (ert-info ("Receive notice that mode has changed")
        (erc-d-t-wait-for 10 (equal erc-channel-modes '("n" "t")))
        (funcall stash-pfx)
        (erc-scenarios-common-say "ready before")
        (funcall expect 10 " has changed mode for #chan to +Qu")
        (erc-d-t-wait-for 10 (equal erc-channel-modes '("Q" "n" "t" "u")))
        ;; Prompt is longer now, so too is the `line-prefix' subtrahend.
        (should (< (car line-prefixes) (funcall stash-pfx)))
        (erc-scenarios-prompt-format--assert "Qntu")
        (erc-scenarios-prompt-format--assert "#chan>"))

      (ert-info ("Key stored locally")
        (erc-scenarios-common-say "ready key")
        (funcall expect 10 " has changed mode for #chan to +k hunter2")
        ;; Prompt has grown by 1.
        (should (< (car line-prefixes) (funcall stash-pfx)))
        (erc-scenarios-prompt-format--assert "Qkntu"))

      (ert-info ("Limit stored locally")
        (erc-scenarios-common-say "ready limit")
        (funcall expect 10 " has changed mode for #chan to +l 3")
        (erc-d-t-wait-for 10 (eql erc-channel-user-limit 3))
        (should (equal erc-channel-modes '("Q" "n" "t" "u")))
        ;; Prompt has grown by 1 again.
        (should (< (car line-prefixes) (funcall stash-pfx)))
        (erc-scenarios-prompt-format--assert "Qklntu"))

      (ert-info ("Modes removed and local state deletion succeeds")
        (erc-scenarios-common-say "ready drop")
        (funcall expect 10 " has changed mode for #chan to -lu")
        (funcall expect 10 " has changed mode for #chan to -Qk *")
        (erc-d-t-wait-for 10 (equal erc-channel-modes '("n" "t")))
        ;; Prompt has shrunk.
        (should (> (car line-prefixes) (funcall stash-pfx)))
        (erc-scenarios-prompt-format--assert "nt"))

      (should-not erc-channel-key)
      (should-not erc-channel-user-limit)
      (funcall expect 10 "<Chad> after"))))

;;; erc-scenarios-prompt-format.el ends here

debug log:

solving 7eccb859dbc ...
found 7eccb859dbc 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).