erc-track-tests.el 5.1 KB

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