1 ;;; erc-track-tests.el --- Tests for erc-track.
3 ;; Copyright (C) 2016 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/>.
28 (ert-deftest erc-track--shorten-aggressive-nil ()
29 "Test non-aggressive erc track buffer name shortening."
30 (let (erc-track-shorten-aggressively)
32 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
36 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
37 '("#linux-de" "#linux-fr"))
38 '("#linux-de" "#linux-fr")))
40 (equal (erc-unique-channel-names
41 '("#dunnet" "#lisp" "#sawfish" "#fsf" "#guile" "#testgnome"
42 "#gnu" "#fsbot" "#hurd" "#hurd-bunny" "#emacs")
43 '("#hurd-bunny" "#hurd" "#sawfish" "#lisp"))
44 '("#hurd-" "#hurd" "#s" "#l")))
46 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
47 '("#em" "#vi" "#el" "#f")))
49 (equal (erc-unique-channel-names
50 '("#emacs" "#burse" "+linux.de" "#starwars"
51 "#bitlbee" "+burse" "#ratpoison")
52 '("+linux.de" "#starwars" "#burse"))
55 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego") '("fsbot"))
58 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
60 (lambda (s) (> (length s) 4)) 1)
63 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
65 (lambda (s) (> (length s) 4)) 2)
68 (equal (erc-unique-channel-names '("deego" "#hurd" "#hurd-bunny" "#emacs")
69 '("#hurd" "#hurd-bunny"))
73 (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
74 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
75 (equal (erc-unique-substrings '("abc" "xyz" "xab")) '("abc" "xyz" "xab"))
76 (equal (erc-unique-substrings '("abc" "abcdefg")) '("abc" "abcd")))) ))
78 (ert-deftest erc-track--shorten-aggressive-t ()
79 "Test aggressive erc track buffer name shortening."
80 (let ((erc-track-shorten-aggressively t))
82 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
86 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
87 '("#linux-de" "#linux-fr"))
88 '("#linux-d" "#linux-f")))
90 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
91 '("#em" "#v" "#el" "#f")))
94 (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
95 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
96 (equal (erc-unique-substrings '("abc" "xyz" "xab")) '("ab" "xy" "xa"))
97 (equal (erc-unique-substrings '("abc" "abcdefg")) '("abc" "abcd")))) ))
99 (ert-deftest erc-track--shorten-aggressive-max ()
100 "Test maximally aggressive erc track buffer name shortening."
101 (let ((erc-track-shorten-aggressively 'max))
103 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
107 (ert-deftest erc-track--erc-faces-in ()
108 "`erc-faces-in' should pick up both 'face and 'font-lock-face properties."
109 (let ((str0 "is bold")
111 ;;(char-property-alias-alist '((face font-lock-face)))
113 (put-text-property 3 (length str0) 'font-lock-face
114 '(bold erc-current-nick-face) str0)
115 (put-text-property 3 (length str1) 'face
116 '(bold erc-current-nick-face) str1)
117 (should (erc-faces-in str0))
118 (should (erc-faces-in str1)) ))