1 ;;; message-mode-tests.el --- Tests for message-mode -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 ;; Author: João Távora <joaotavora@gmail.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This file contains tests for message-mode.
32 (ert-deftest message-mode-propertize ()
35 (let (message-auto-save-directory)
37 (insert "here's an opener (\n"
38 "here's a sad face :-(\n"
39 "> here's citing someone with an opener (\n"
40 "and here's a closer ")
41 (let ((last-command-event ?\)))
42 (ert-simulate-command '(self-insert-command 1)))
43 ;; Auto syntax propertization doesn't kick in until
44 ;; parse-sexp-lookup-properties is set.
45 (setq-local parse-sexp-lookup-properties t)
47 (should (string= "here's an opener "
48 (buffer-substring-no-properties
49 (line-beginning-position)
52 (should (string= "and here's a closer )"
53 (buffer-substring-no-properties
54 (line-beginning-position)
56 (set-buffer-modified-p nil))))
59 (ert-deftest message-strip-subject-trailing-was ()
60 (ert-with-function-mocked message-talkative-question nil
62 (let ((no-was "Re: Foo ")
63 (with-was "Re: Foo \t (was: Bar ) ")
64 (stripped-was "Re: Foo")
67 ;; Test unconditional stripping
68 (setq-local message-subject-trailing-was-query t)
69 (should (string= no-was (message-strip-subject-trailing-was no-was)))
70 (should (string= stripped-was
71 (message-strip-subject-trailing-was with-was)))
74 (setq-local message-subject-trailing-was-query 'ask)
75 (fset 'message-talkative-question
76 (lambda (_ question show text)
77 (should (string= "Strip `(was: <old subject>)' in subject? "
82 "Strip `(was: <old subject>)' in subject "
83 "and use the new one instead\\?\n\n"
84 "Current subject is: \"\\(.*\\)\"\n\n"
85 "New subject would be: \"\\(.*\\)\"\n\n"
87 "`message-subject-trailing-was-query' "
88 "to get rid of this query.")
90 (should (string= (match-string 1 text) with-was))
91 (should (string= (match-string 2 text) stripped-was))
93 (message-strip-subject-trailing-was with-was)
94 (should (string= with-was
95 (message-strip-subject-trailing-was with-was)))
97 (should (string= stripped-was
98 (message-strip-subject-trailing-was with-was)))))))
101 (provide 'message-mode-tests)
103 ;;; message-mode-tests.el ends here