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
| | ;;; erc-match-tests.el --- Tests for erc-match. -*- lexical-binding:t -*-
;; Copyright (C) 2022 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-match)
(ert-deftest erc-pals ()
(with-temp-buffer
(setq erc-server-process (start-process "true" (current-buffer) "true")
erc-server-users (make-hash-table :test #'equal))
(set-process-query-on-exit-flag erc-server-process nil)
(erc-add-server-user "FOO[m]" (make-erc-server-user :nickname "foo[m]"))
(erc-add-server-user "tester" (make-erc-server-user :nickname "tester"))
(let (erc-pals calls rvs)
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest r) (push r calls) (pop rvs))))
(ert-info ("`erc-add-pal'")
(push "foo[m]" rvs)
(ert-simulate-command '(erc-add-pal))
(should (equal (cadr (pop calls)) '(("tester") ("foo[m]"))))
(should (equal erc-pals '("foo\\[m]"))))
(ert-info ("`erc-match-pal-p'")
(should (erc-match-pal-p "FOO[m]!~u@example.net" nil)))
(ert-info ("`erc-delete-pal'")
(push "foo\\[m]" rvs)
(ert-simulate-command '(erc-delete-pal))
(should (equal (cadr (pop calls)) '(("foo\\[m]"))))
(should-not erc-pals))))))
(ert-deftest erc-fools ()
(with-temp-buffer
(setq erc-server-process (start-process "true" (current-buffer) "true")
erc-server-users (make-hash-table :test #'equal))
(set-process-query-on-exit-flag erc-server-process nil)
(erc-add-server-user "FOO[m]" (make-erc-server-user :nickname "foo[m]"))
(erc-add-server-user "tester" (make-erc-server-user :nickname "tester"))
(let (erc-fools calls rvs)
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest r) (push r calls) (pop rvs))))
(ert-info ("`erc-add-fool'")
(push "foo[m]" rvs)
(ert-simulate-command '(erc-add-fool))
(should (equal (cadr (pop calls)) '(("tester") ("foo[m]"))))
(should (equal erc-fools '("foo\\[m]"))))
(ert-info ("`erc-match-fool-p'")
(should (erc-match-fool-p "FOO[m]!~u@example.net" ""))
(should (erc-match-fool-p "tester!~u@example.net" "FOO[m]: die")))
(ert-info ("`erc-delete-fool'")
(push "foo\\[m]" rvs)
(ert-simulate-command '(erc-delete-fool))
(should (equal (cadr (pop calls)) '(("foo\\[m]"))))
(should-not erc-fools))))))
(ert-deftest erc-keywords ()
(let (erc-keywords calls rvs)
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest r) (push r calls) (pop rvs))))
(ert-info ("`erc-add-keyword'")
(push "[cit. needed]" rvs)
(ert-simulate-command '(erc-add-keyword))
(should (equal (cadr (pop calls)) nil))
(should (equal erc-keywords '("\\[cit\\. needed]"))))
(ert-info ("`erc-match-keyword-p'")
(should (erc-match-keyword-p nil "is pretty [cit. needed]")))
(ert-info ("`erc-delete-keyword'")
(push "\\[cit\\. needed]" rvs)
(ert-simulate-command '(erc-delete-keyword))
(should (equal (cadr (pop calls)) '(("\\[cit\\. needed]"))))
(should-not erc-keywords)))))
(ert-deftest erc-dangerous-hosts ()
(let (erc-dangerous-hosts calls rvs)
(cl-letf (((symbol-function 'completing-read)
(lambda (&rest r) (push r calls) (pop rvs))))
(ert-info ("`erc-add-dangerous-host'")
(push "example.net" rvs)
(ert-simulate-command '(erc-add-dangerous-host))
(should (equal (cadr (pop calls)) nil))
(should (equal erc-dangerous-hosts '("example\\.net"))))
(ert-info ("`erc-match-dangerous-host-p'")
(should (erc-match-dangerous-host-p "FOO[m]!~u@example.net" nil)))
(ert-info ("`erc-delete-dangerous-host'")
(push "example\\.net" rvs)
(ert-simulate-command '(erc-delete-dangerous-host))
(should (equal (cadr (pop calls)) '(("example\\.net"))))
(should-not erc-dangerous-hosts)))))
;;; erc-match-tests.el ends here
|