message-tests.el 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ;;; message-mode-tests.el --- Tests for message-mode -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
  3. ;; Author: João Távora <joaotavora@gmail.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 file contains tests for message-mode.
  17. ;;; Code:
  18. (require 'message)
  19. (require 'ert)
  20. (require 'ert-x)
  21. (ert-deftest message-mode-propertize ()
  22. (with-temp-buffer
  23. (unwind-protect
  24. (let (message-auto-save-directory)
  25. (message-mode)
  26. (insert "here's an opener (\n"
  27. "here's a sad face :-(\n"
  28. "> here's citing someone with an opener (\n"
  29. "and here's a closer ")
  30. (let ((last-command-event ?\)))
  31. (ert-simulate-command '(self-insert-command 1)))
  32. ;; Auto syntax propertization doesn't kick in until
  33. ;; parse-sexp-lookup-properties is set.
  34. (setq-local parse-sexp-lookup-properties t)
  35. (backward-sexp)
  36. (should (string= "here's an opener "
  37. (buffer-substring-no-properties
  38. (line-beginning-position)
  39. (point))))
  40. (forward-sexp)
  41. (should (string= "and here's a closer )"
  42. (buffer-substring-no-properties
  43. (line-beginning-position)
  44. (point)))))
  45. (set-buffer-modified-p nil))))
  46. (ert-deftest message-strip-subject-trailing-was ()
  47. (ert-with-function-mocked message-talkative-question nil
  48. (with-temp-buffer
  49. (let ((no-was "Re: Foo ")
  50. (with-was "Re: Foo \t (was: Bar ) ")
  51. (stripped-was "Re: Foo")
  52. reply)
  53. ;; Test unconditional stripping
  54. (setq-local message-subject-trailing-was-query t)
  55. (should (string= no-was (message-strip-subject-trailing-was no-was)))
  56. (should (string= stripped-was
  57. (message-strip-subject-trailing-was with-was)))
  58. ;; Test asking
  59. (setq-local message-subject-trailing-was-query 'ask)
  60. (fset 'message-talkative-question
  61. (lambda (_ question show text)
  62. (should (string= "Strip `(was: <old subject>)' in subject? "
  63. question))
  64. (should show)
  65. (should (string-match
  66. (concat
  67. "Strip `(was: <old subject>)' in subject "
  68. "and use the new one instead\\?\n\n"
  69. "Current subject is: \"\\(.*\\)\"\n\n"
  70. "New subject would be: \"\\(.*\\)\"\n\n"
  71. "See the variable "
  72. "`message-subject-trailing-was-query' "
  73. "to get rid of this query.")
  74. text))
  75. (should (string= (match-string 1 text) with-was))
  76. (should (string= (match-string 2 text) stripped-was))
  77. reply))
  78. (message-strip-subject-trailing-was with-was)
  79. (should (string= with-was
  80. (message-strip-subject-trailing-was with-was)))
  81. (setq reply t)
  82. (should (string= stripped-was
  83. (message-strip-subject-trailing-was with-was)))))))
  84. (provide 'message-mode-tests)
  85. ;;; message-mode-tests.el ends here