summaryrefslogtreecommitdiff
path: root/test/lisp/erc/erc-scenarios-base-statusmsg.el
blob: 480ba7fa8d03c29002295095fd03725aaa01617a (plain)
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
;;; erc-scenarios-base-statusmsg.el --- statusmsg tests -*- lexical-binding: t -*-

;; Copyright (C) 2023-2024 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)))

(ert-deftest erc-scenarios-base-statusmsg ()

  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/display-message")
       (dumb-server (erc-d-run "localhost" t 'statusmsg))
       (erc-autojoin-channels-alist '((foonet "#mine")))
       (erc-modules (cons 'fill-wrap erc-modules))
       (port (process-contact dumb-server :service))
       (erc-show-speaker-membership-status nil)
       (erc-server-flood-penalty 0.1)
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :user "tester"
                                :full-name "tester")
        (funcall expect 5 "This server is in debug mode")))

    (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#mine"))

      (ert-info ("Receive status messages unprefixed")
        (funcall expect 5 "+dummy")
        (funcall expect 5 "(dummy+) hello")
        (should (eq 'statusmsg (erc--get-inserted-msg-prop 'erc--msg)))
        (should (equal "dummy" (erc--get-inserted-msg-prop 'erc--spkr)))
        (should (eq (get-text-property (1- (point)) 'font-lock-face)
                    'erc-default-face))
        (funcall expect 5 "(dummy+) there")
        (should (equal "" (get-text-property (pos-bol) 'display)))

        ;; CTCP ACTION
        (funcall expect 5 "* (dummy+) sad")
        (should (eq 'ctcp-action-statusmsg
                    (erc--get-inserted-msg-prop 'erc--msg)))
        (should (eq (get-text-property (1- (point)) 'font-lock-face)
                    'erc-action-face))
        (funcall expect 5 "* (dummy+) glad")
        (should (equal "" (get-text-property (pos-bol) 'display))))

      (ert-info ("Send status messages")
        ;; We don't have `echo-message' yet, so ERC doesn't currently
        ;; insert commands like "/msg +#mine foo".
        (let ((erc-default-recipients '("+#mine")))
          (erc-send-message "howdy"))
        (funcall expect 5 "(@tester+) howdy")
        (should (eq 'statusmsg-input (erc--get-inserted-msg-prop 'erc--msg)))
        (should (equal "tester" (erc--get-inserted-msg-prop 'erc--spkr)))
        (should (eq (get-text-property (1- (point)) 'font-lock-face)
                    'erc-input-face))
        (let ((erc-default-recipients '("+#mine")))
          (erc-send-message "tenderfoot"))
        (funcall expect 5 "(@tester+) tenderfoot")
        (should (equal "" (get-text-property (pos-bol) 'display)))

        ;; Simulate some "echoed" CTCP ACTION messages since we don't
        ;; actually support that yet.
        (funcall expect 5 "* (@tester+) mad")
        (should (eq 'ctcp-action-statusmsg-input
                    (erc--get-inserted-msg-prop 'erc--msg)))
        (should (equal (get-text-property (1- (point)) 'font-lock-face)
                       '(erc-input-face erc-action-face)))
        (funcall expect 5 "* (@tester+) chad")
        (should (equal "" (get-text-property (pos-bol) 'display))))

      (ert-info ("Receive status messages prefixed")
        (setq erc-show-speaker-membership-status t)
        (erc-scenarios-common-say "/me ready") ; sync
        (funcall expect 5 "* @tester ready")
        (funcall expect 5 "(+dummy+) okie")

        ;; CTCP ACTION
        (funcall expect 5 "* (+dummy+) dokie")
        (funcall expect 5 "* +dummy out")))))

;;; erc-scenarios-base-statusmsg.el ends here