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
| | ;;; erc-goodies-tests.el --- Tests for erc-goodies -*- 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)
(require 'erc-goodies)
(declare-function erc--initialize-markers "erc" (old-point continued) t)
;; Among other things, this test also asserts that a local module's
;; minor-mode toggle is allowed to disable its mode variable as
;; needed.
(ert-deftest erc-keep-place-indicator-mode ()
(unless (fboundp 'erc--initialize-markers)
(ert-skip "Required patch set for bug#60954 not yet applied"))
(with-current-buffer (get-buffer-create "*erc-keep-place-indicator-mode*")
(erc-mode)
(erc--initialize-markers (point) nil)
(let ((assert-off
(lambda ()
(should-not erc-keep-place-indicator-mode)
(should-not (local-variable-p 'window-configuration-change-hook))
(should-not erc--keep-place-indicator-overlay)))
(assert-on
(lambda ()
(should erc--keep-place-indicator-overlay)
(should (local-variable-p 'window-configuration-change-hook))
(should window-configuration-change-hook)
(should erc-keep-place-mode)))
;;
erc-modules)
(funcall assert-off)
(ert-info ("Value t")
(should (eq erc-keep-place-indicator-buffer-type t))
(erc-keep-place-indicator-mode +1)
(funcall assert-on)
(goto-char (point-min))
(should (search-forward "Enabling" nil t))
(should (memq 'keep-place erc-modules)))
(erc-keep-place-indicator-mode -1)
(funcall assert-off)
(ert-info ("Value `target'")
(let ((erc-keep-place-indicator-buffer-type 'target))
(erc-keep-place-indicator-mode +1)
(funcall assert-off)
(setq erc--target (erc--target-from-string "#chan"))
(erc-keep-place-indicator-mode +1)
(funcall assert-on)))
(erc-keep-place-indicator-mode -1)
(funcall assert-off)
(ert-info ("Value `server'")
(let ((erc-keep-place-indicator-buffer-type 'server))
(erc-keep-place-indicator-mode +1)
(funcall assert-off)
(setq erc--target nil)
(erc-keep-place-indicator-mode +1)
(funcall assert-on)))
;; Populate buffer
(erc-display-message nil 'notice (current-buffer)
"This buffer is for text that is not saved")
(erc-display-message nil 'notice (current-buffer)
"and for lisp evaluation")
(should (search-forward "saved" nil t))
(erc-keep-place-move nil)
(goto-char erc-input-marker)
(ert-info ("Indicator survives reconnect")
(let ((erc--server-reconnecting (buffer-local-variables)))
(cl-letf (((symbol-function 'erc-server-connect) #'ignore))
(erc-open "localhost" 6667 "tester" "Tester" 'connect
nil nil nil nil nil "tester" nil)))
(funcall assert-on)
(should (= (point) erc-input-marker))
(goto-char (overlay-start erc--keep-place-indicator-overlay))
(should (looking-at (rx "*** This buffer is for text")))))
(when noninteractive
(kill-buffer))))
;;; erc-goodies-tests.el ends here
|