descr-text-tests.el 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; descr-text-test.el --- ERT tests for descr-text.el -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2014, 2016-2017 Free Software Foundation, Inc.
  3. ;; Author: Michal Nazarewicz <mina86@mina86.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This package defines regression tests for the descr-text package.
  17. ;;; Code:
  18. (require 'ert)
  19. (require 'descr-text)
  20. (ert-deftest descr-text-test-truncate ()
  21. "Tests describe-char-eldoc--truncate function."
  22. (should (equal ""
  23. (describe-char-eldoc--truncate " \t \n" 100)))
  24. (should (equal "foo"
  25. (describe-char-eldoc--truncate "foo" 1)))
  26. (should (equal "foo..."
  27. (describe-char-eldoc--truncate "foo wilma fred" 0)))
  28. (should (equal "foo..."
  29. (describe-char-eldoc--truncate
  30. "foo wilma fred" (length "foo wilma"))))
  31. (should (equal "foo wilma..."
  32. (describe-char-eldoc--truncate
  33. "foo wilma fred" (+ 3 (length "foo wilma")))))
  34. (should (equal "foo wilma..."
  35. (describe-char-eldoc--truncate
  36. "foo wilma fred" (1- (length "foo wilma fred")))))
  37. (should (equal "foo wilma fred"
  38. (describe-char-eldoc--truncate
  39. "foo wilma fred" (length "foo wilma fred"))))
  40. (should (equal "foo wilma fred"
  41. (describe-char-eldoc--truncate
  42. " foo\t wilma \nfred\t " (length "foo wilma fred")))))
  43. (ert-deftest descr-text-test-format-desc ()
  44. "Tests describe-char-eldoc--format function."
  45. (should (equal "U+2026: Horizontal ellipsis (Po: Punctuation, Other)"
  46. (describe-char-eldoc--format ?…)))
  47. (should (equal "U+2026: Horizontal ellipsis (Punctuation, Other)"
  48. (describe-char-eldoc--format ?… 51)))
  49. (should (equal "U+2026: Horizontal ellipsis (Po)"
  50. (describe-char-eldoc--format ?… 40)))
  51. (should (equal "Horizontal ellipsis (Po)"
  52. (describe-char-eldoc--format ?… 30)))
  53. (should (equal "Horizontal ellipsis"
  54. (describe-char-eldoc--format ?… 20)))
  55. (should (equal "Horizontal..."
  56. (describe-char-eldoc--format ?… 10))))
  57. (ert-deftest descr-text-test-desc ()
  58. "Tests describe-char-eldoc function."
  59. (with-temp-buffer
  60. (insert "a…")
  61. (goto-char (point-min))
  62. (should (eq ?a (following-char))) ; make sure we are where we think we are
  63. ;; Function should return nil for an ASCII character.
  64. (should (not (describe-char-eldoc)))
  65. (goto-char (1+ (point)))
  66. (should (eq ?… (following-char)))
  67. (let ((eldoc-echo-area-use-multiline-p t))
  68. ;; Function should return description of an Unicode character.
  69. (should (equal "U+2026: Horizontal ellipsis (Po: Punctuation, Other)"
  70. (describe-char-eldoc))))
  71. (goto-char (point-max))
  72. ;; At the end of the buffer, function should return nil and not blow up.
  73. (should (not (describe-char-eldoc)))))
  74. (provide 'descr-text-test)
  75. ;;; descr-text-test.el ends here