summaryrefslogtreecommitdiff
path: root/test/lisp/erc/erc-scenarios-fill-wrap.el
blob: 0dfeb9bf365ab4bf930ac05ae6792f4ebe70e1d7 (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
;;; erc-scenarios-fill-wrap.el --- Fill-wrap module -*- lexical-binding: t -*-

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

(defun erc-scenarios-fill-wrap--merged-p ()
  (get-text-property (pos-bol) 'erc-fill--wrap-merge))

;; This asserts that an intervening date stamp between two messages
;; from the same speaker will trigger a break in merge detection, so
;; the second message's speaker tag won't be hidden.
(ert-deftest erc-scenarios-fill-wrap/merge-datestamp ()
  :tags '(:expensive-test)

  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "fill/wrap")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'merge-datestamp))
       (erc-stamp--tz t)
       ;; Start at 2023-10-22T06:16:43.445Z
       (erc-stamp--current-time (if (< emacs-major-version 29)
                                    '(25908 23515 445000 0)
                                  '(1697930203445 . 1000)))
       (erc-timer-hook (cons (lambda (&rest _)
                               (setq erc-stamp--current-time
                                     (time-add erc-stamp--current-time 15)))
                             erc-timer-hook))
       (expect (erc-d-t-make-expecter))
       (erc-autojoin-channels-alist '((foonet "#chan" "#control")))
       (erc-modules `(nicks fill-wrap scrolltobottom ,@erc-modules))
       (port (process-contact dumb-server :service)))

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

    (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "dummy"))
      (funcall expect 10 "<dummy> hi")
      (funcall expect 10 "<dummy> there"))

    (with-current-buffer "#chan"
      (funcall expect 10 "<bob> tester, welcome")

      ;; Force date change.
      (setq erc-stamp--current-time
            (time-add erc-stamp--current-time (* 60 60))))

    (with-current-buffer "#control"
      (erc-send-message "1"))

    (with-current-buffer "#chan"
      (funcall expect 10 "[Sun Oct 22 2023]")
      (funcall expect 10 "<bob> one")
      (should-not (erc-scenarios-fill-wrap--merged-p)))

    (with-current-buffer "#control"
      (erc-send-message "2"))

    (with-current-buffer "dummy"
      (funcall expect 10 "[Sun Oct 22 2023]")
      (funcall expect 10 "<dummy> again")
      (should-not (erc-scenarios-fill-wrap--merged-p)))

    (with-current-buffer "#chan"
      (funcall expect 10 "<alice> bob: He was famous"))

    (erc-scrolltobottom-mode -1)))

;;; erc-scenarios-fill-wrap.el ends here