]> code.delx.au - gnu-emacs/blob - test/lisp/gnus/message-tests.el
Merge from origin/emacs-25
[gnu-emacs] / test / lisp / gnus / message-tests.el
1 ;;; message-mode-tests.el --- Tests for message-mode -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
4
5 ;; Author: João Távora <joaotavora@gmail.com>
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22 ;;; Commentary:
23
24 ;; This file contains tests for message-mode.
25
26 ;;; Code:
27
28 (require 'message)
29 (require 'ert)
30 (require 'ert-x)
31
32 (ert-deftest message-mode-propertize ()
33 (with-temp-buffer
34 (unwind-protect
35 (let (message-auto-save-directory)
36 (message-mode)
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)
46 (backward-sexp)
47 (should (string= "here's an opener "
48 (buffer-substring-no-properties
49 (line-beginning-position)
50 (point))))
51 (forward-sexp)
52 (should (string= "and here's a closer )"
53 (buffer-substring-no-properties
54 (line-beginning-position)
55 (point)))))
56 (set-buffer-modified-p nil))))
57
58
59 (ert-deftest message-strip-subject-trailing-was ()
60 (ert-with-function-mocked message-talkative-question nil
61 (with-temp-buffer
62 (let ((no-was "Re: Foo ")
63 (with-was "Re: Foo \t (was: Bar ) ")
64 (stripped-was "Re: Foo")
65 reply)
66
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)))
72
73 ;; Test asking
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? "
78 question))
79 (should show)
80 (should (string-match
81 (concat
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"
86 "See the variable "
87 "`message-subject-trailing-was-query' "
88 "to get rid of this query.")
89 text))
90 (should (string= (match-string 1 text) with-was))
91 (should (string= (match-string 2 text) stripped-was))
92 reply))
93 (message-strip-subject-trailing-was with-was)
94 (should (string= with-was
95 (message-strip-subject-trailing-was with-was)))
96 (setq reply t)
97 (should (string= stripped-was
98 (message-strip-subject-trailing-was with-was)))))))
99
100
101 (provide 'message-mode-tests)
102
103 ;;; message-mode-tests.el ends here