]> code.delx.au - gnu-emacs/blob - test/lisp/erc/erc-track-tests.el
Merge from origin/emacs-25
[gnu-emacs] / test / lisp / erc / erc-track-tests.el
1 ;;; erc-track-tests.el --- Tests for erc-track.
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Author: Vivek Dasmohapatra <vivek@etla.org>
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ;;; Code:
24
25 (require 'ert)
26 (require 'erc-track)
27
28 (ert-deftest erc-track--shorten-aggressive-nil ()
29 "Test non-aggressive erc track buffer name shortening."
30 (let (erc-track-shorten-aggressively)
31 (should
32 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
33 '("#emacs" "#vi"))
34 '("#em" "#vi")))
35 (should
36 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
37 '("#linux-de" "#linux-fr"))
38 '("#linux-de" "#linux-fr")))
39 (should
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")))
45 (should
46 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
47 '("#em" "#vi" "#el" "#f")))
48 (should
49 (equal (erc-unique-channel-names
50 '("#emacs" "#burse" "+linux.de" "#starwars"
51 "#bitlbee" "+burse" "#ratpoison")
52 '("+linux.de" "#starwars" "#burse"))
53 '("+l" "#s" "#bu")))
54 (should
55 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego") '("fsbot"))
56 '("fs")))
57 (should
58 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
59 '("fsbot")
60 (lambda (s) (> (length s) 4)) 1)
61 '("f")))
62 (should
63 (equal (erc-unique-channel-names '("fsbot" "#emacs" "deego")
64 '("fsbot")
65 (lambda (s) (> (length s) 4)) 2)
66 '("fs")))
67 (should
68 (equal (erc-unique-channel-names '("deego" "#hurd" "#hurd-bunny" "#emacs")
69 '("#hurd" "#hurd-bunny"))
70 '("#hurd" "#hurd-")))
71 (should
72 (and
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")))) ))
77
78 (ert-deftest erc-track--shorten-aggressive-t ()
79 "Test aggressive erc track buffer name shortening."
80 (let ((erc-track-shorten-aggressively t))
81 (should
82 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
83 '("#emacs" "#vi"))
84 '("#em" "#v")))
85 (should
86 (equal (erc-unique-channel-names '("#linux-de" "#linux-fr")
87 '("#linux-de" "#linux-fr"))
88 '("#linux-d" "#linux-f")))
89 (should
90 (equal (erc-unique-substrings '("#emacs" "#vi" "#electronica" "#folk"))
91 '("#em" "#v" "#el" "#f")))
92 (should
93 (and
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")))) ))
98
99 (ert-deftest erc-track--shorten-aggressive-max ()
100 "Test maximally aggressive erc track buffer name shortening."
101 (let ((erc-track-shorten-aggressively 'max))
102 (should
103 (equal (erc-unique-channel-names '("#emacs" "#vi" "#electronica" "#folk")
104 '("#emacs" "#vi"))
105 '("#e" "#v"))) ))
106
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")
110 (str1 "is bold")
111 ;;(char-property-alias-alist '((face font-lock-face)))
112 )
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)) ))