; * doc/lispref/lists.texi (List Elements): Fix last change.
[emacs.git] / test / lisp / erc / erc-track-tests.el
blobda119ed4b139031946d516e2fc4bfe54e90363e0
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/>.
23 ;;; Code:
25 (require 'ert)
26 (require 'erc-track)
27 (require 'font-core)
29 (ert-deftest erc-track--shorten-aggressive-nil ()
30 "Test non-aggressive erc track buffer name shortening."
31 (let (erc-track-shorten-aggressively)
32 (should
33 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
34 '("#emacs" "#vi"))
35 '("#em" "#vi")))
36 (should
37 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
38 '("#linux-de" "#linux-fr"))
39 '("#linux-de" "#linux-fr")))
40 (should
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")))
46 (should
47 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
48 '("#em" "#vi" "#el" "#f")))
49 (should
50 (equal (erc-unique-channel-names
51 '("#emacs" "#burse" "+linux.de" "#starwars"
52 "#bitlbee" "+burse" "#ratpoison")
53 '("+linux.de" "#starwars" "#burse"))
54 '("+l" "#s" "#bu")))
55 (should
56 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego") '("fsbot"))
57 '("fs")))
58 (should
59 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
60 '("fsbot")
61 (lambda (s) (> (length s) 4)) 1)
62 '("f")))
63 (should
64 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
65 '("fsbot")
66 (lambda (s) (> (length s) 4)) 2)
67 '("fs")))
68 (should
69 (equal (erc-unique-channel-names '("deego" "#hurd" "#hurd-bunny" "#emacs")
70 '("#hurd" "#hurd-bunny"))
71 '("#hurd" "#hurd-")))
72 (should
73 (and
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))
82 (should
83 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
84 '("#emacs" "#vi"))
85 '("#em" "#v")))
86 (should
87 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
88 '("#linux-de" "#linux-fr"))
89 '("#linux-d" "#linux-f")))
90 (should
91 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
92 '("#em" "#v" "#el" "#f")))
93 (should
94 (and
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))
103 (should
104 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
105 '("#emacs" "#vi"))
106 '("#e" "#v"))) ))
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")
111 (str1 "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)) ))