1 ;;; erc-track-tests.el --- Tests for erc-track.
3 ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Author: Vivek Dasmohapatra <vivek@etla.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (ert-deftest erc-track--shorten-aggressive-nil
()
30 "Test non-aggressive erc track buffer name shortening."
31 (let (erc-track-shorten-aggressively)
33 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
37 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
38 '("#linux-de" "#linux-fr"))
39 '("#linux-de" "#linux-fr")))
41 (equal (erc-unique-channel-names
42 '("#dunnet" "#lisp" "#sawfish" "#fsf" "#guile" "#testgnome"
43 "#gnu" "#fsbot" "#hurd" "#hurd-bunny" "#emacs")
44 '("#hurd-bunny" "#hurd" "#sawfish" "#lisp"))
45 '("#hurd-" "#hurd" "#s" "#l")))
47 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
48 '("#em" "#vi" "#el" "#f")))
50 (equal (erc-unique-channel-names
51 '("#emacs" "#burse" "+linux.de" "#starwars"
52 "#bitlbee" "+burse" "#ratpoison")
53 '("+linux.de" "#starwars" "#burse"))
56 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego") '("fsbot"))
59 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
61 (lambda (s) (> (length s
) 4)) 1)
64 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
66 (lambda (s) (> (length s
) 4)) 2)
69 (equal (erc-unique-channel-names '("deego" "#hurd" "#hurd-bunny" "#emacs")
70 '("#hurd" "#hurd-bunny"))
74 (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
75 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
76 (equal (erc-unique-substrings '("abc" "xyz" "xab")) '("abc" "xyz" "xab"))
77 (equal (erc-unique-substrings '("abc" "abcdefg")) '("abc" "abcd")))) ))
79 (ert-deftest erc-track--shorten-aggressive-t
()
80 "Test aggressive erc track buffer name shortening."
81 (let ((erc-track-shorten-aggressively t
))
83 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
87 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
88 '("#linux-de" "#linux-fr"))
89 '("#linux-d" "#linux-f")))
91 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
92 '("#em" "#v" "#el" "#f")))
95 (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
96 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
97 (equal (erc-unique-substrings '("abc" "xyz" "xab")) '("ab" "xy" "xa"))
98 (equal (erc-unique-substrings '("abc" "abcdefg")) '("abc" "abcd")))) ))
100 (ert-deftest erc-track--shorten-aggressive-max
()
101 "Test maximally aggressive erc track buffer name shortening."
102 (let ((erc-track-shorten-aggressively 'max
))
104 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
108 (ert-deftest erc-track--erc-faces-in
()
109 "`erc-faces-in' should pick up both 'face and 'font-lock-face properties."
110 (let ((str0 "is bold")
112 ;; Turn on Font Lock mode: this initialize `char-property-alias-alist'
113 ;; to '((face font-lock-face)). Note that `font-lock-mode' don't
114 ;; turn on the mode if the test is run on batch mode or if the
115 ;; buffer name starts with ?\s (Bug#23954).
116 (unless font-lock-mode
(font-lock-default-function 1))
117 (put-text-property 3 (length str0
) 'font-lock-face
118 '(bold erc-current-nick-face
) str0
)
119 (put-text-property 3 (length str1
) 'face
120 '(bold erc-current-nick-face
) str1
)
121 (should (erc-faces-in str0
))
122 (should (erc-faces-in str1
)) ))