aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2017-05-29 23:49:41 +0200
committerStephen Berman2017-05-29 23:49:41 +0200
commit299a96c7f6f8dbba210c373130cd9f2d4eec77a5 (patch)
tree58afd3186bd84bb14af11f6023a452114f9af407
parented222c502b1a0043a8bc606482a11516568a54b6 (diff)
downloademacs-299a96c7f6f8dbba210c373130cd9f2d4eec77a5.tar.gz
emacs-299a96c7f6f8dbba210c373130cd9f2d4eec77a5.zip
Add initial tests for todo-mode.el
*test/lisp/calendar/todo-mode-tests.el: *test/lisp/calendar/todo-mode-resources/todo-test-1.toda: *test/lisp/calendar/todo-mode-resources/todo-test-1.todo: New files. * .gitattributes: Ignore trailing whitespace in todo-mode test data files, since it is part of the todo-mode file format.
-rw-r--r--.gitattributes5
-rw-r--r--test/lisp/calendar/todo-mode-resources/todo-test-1.toda13
-rw-r--r--test/lisp/calendar/todo-mode-resources/todo-test-1.todo12
-rw-r--r--test/lisp/calendar/todo-mode-tests.el124
4 files changed, 154 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
index 59cc2eded5d..7e35433dcc6 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -29,6 +29,11 @@ test/etags/c-src/dostorture.c whitespace=cr-at-eol
29test/etags/cp-src/c.C whitespace=cr-at-eol 29test/etags/cp-src/c.C whitespace=cr-at-eol
30test/etags/html-src/algrthms.html whitespace=cr-at-eol 30test/etags/html-src/algrthms.html whitespace=cr-at-eol
31 31
32# The todo-mode file format includes trailing whitespace, so the test
33# data files cannot avoid it.
34test/lisp/calendar/todo-mode-resources/todo-test-1.toda -whitespace=blank-at-eol
35test/lisp/calendar/todo-mode-resources/todo-test-1.todo -whitespace=blank-at-eol
36
32# The upstream maintainer does not want to remove trailing whitespace. 37# The upstream maintainer does not want to remove trailing whitespace.
33doc/misc/texinfo.tex -whitespace=blank-at-eol 38doc/misc/texinfo.tex -whitespace=blank-at-eol
34 39
diff --git a/test/lisp/calendar/todo-mode-resources/todo-test-1.toda b/test/lisp/calendar/todo-mode-resources/todo-test-1.toda
new file mode 100644
index 00000000000..8ca4e1908da
--- /dev/null
+++ b/test/lisp/calendar/todo-mode-resources/todo-test-1.toda
@@ -0,0 +1,13 @@
1(("testcat1" . [0 0 1 0]) ("testcat2" . [0 0 1 0]) ("testcat3" . [0 0 1 0]))
2--==-- testcat1
3
4==--== DONE
5[DONE May 26, 2017] [May 26, 2017] testcat1 item1
6--==-- testcat2
7
8==--== DONE
9[DONE May 28, 2017] [May 28, 2017] testcat2 item1
10--==-- testcat3
11
12==--== DONE
13[DONE May 28, 2017] [May 28, 2017] testcat3 item1
diff --git a/test/lisp/calendar/todo-mode-resources/todo-test-1.todo b/test/lisp/calendar/todo-mode-resources/todo-test-1.todo
new file mode 100644
index 00000000000..8e845df6b69
--- /dev/null
+++ b/test/lisp/calendar/todo-mode-resources/todo-test-1.todo
@@ -0,0 +1,12 @@
1(("testcat1" . [2 0 0 1]) ("testcat2" . [1 0 0 1]))
2--==-- testcat1
3[May 29, 2017] testcat1 item3
4 has more than one line
5 to test item highlighting
6[May 26, 2017] testcat1 item2
7
8==--== DONE
9--==-- testcat2
10[May 28, 2017] testcat2 item2
11
12==--== DONE
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
new file mode 100644
index 00000000000..70e355ef027
--- /dev/null
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -0,0 +1,124 @@
1;;; todo-mode-tests.el --- tests for todo-mode.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5;; Author: Stephen Berman <stephen.berman@gmx.net>
6;; Keywords: calendar
7
8;; This program is free software; you can redistribute it and/or modify
9;; it under the terms of the GNU General Public License as published by
10;; the Free Software Foundation, either version 3 of the License, or
11;; (at your option) any later version.
12
13;; This program is distributed in the hope that it will be useful,
14;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;; GNU General Public License for more details.
17
18;; You should have received a copy of the GNU General Public License
19;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21;;; Commentary:
22
23;; FIXME:
24;; In its current form this file changes global variables defined in
25;; todo-mode.el, so to avoid problems, these tests should not be run
26;; if todo-mode.el is already loaded.
27
28;;; Code:
29
30(require 'ert)
31(require 'todo-mode)
32
33(defvar todo-test-data-dir
34 (file-truename
35 (expand-file-name "todo-mode-resources/"
36 (file-name-directory (or load-file-name
37 buffer-file-name))))
38 "Base directory of todo-mode.el test data files.")
39
40(defvar todo-test-file-1 (expand-file-name "todo-test-1.todo"
41 todo-test-data-dir)
42 "Todo mode test file.")
43
44(defvar todo-test-archive-1 (expand-file-name "todo-test-1.toda"
45 todo-test-data-dir)
46 "Todo Archive mode test file.")
47
48;; (setq todo-directory-orig todo-directory)
49
50(setq todo-directory todo-test-data-dir)
51
52(defun todo-test-get-archive (num)
53 "Make buffer displaying archive category NUM current."
54 (let ((archive-buf (find-file-noselect todo-test-archive-1)))
55 (set-buffer archive-buf)
56 (todo-archive-mode)
57 (setq todo-category-number num)
58 (todo-category-select)))
59
60(defun todo-test-is-current-buffer (filename)
61 "Return non-nil if FILENAME's buffer is current."
62 (let ((bufname (buffer-file-name (current-buffer))))
63 (and bufname (equal (file-truename bufname) filename))))
64
65(ert-deftest todo-test-todo-quit01 ()
66 "Test the behavior of todo-quit with archive and todo files.
67Invoking todo-quit in todo-archive-mode should make the
68corresponding todo-mode category current, if it exits, otherwise
69the current todo-mode category. Quitting todo-mode without an
70intermediate buffer switch should not make the archive buffer
71current again."
72 (todo-test-get-archive 2)
73 (let ((cat-name (todo-current-category)))
74 (todo-quit)
75 (should (todo-test-is-current-buffer todo-test-file-1))
76 (should (equal (todo-current-category) cat-name))
77 (todo-test-get-archive 1)
78 (setq cat-name (todo-current-category))
79 (todo-quit)
80 (should (todo-test-is-current-buffer todo-test-file-1))
81 (should (equal todo-category-number 1))
82 (todo-forward-category) ; Category 2 in todo file now current.
83 (todo-test-get-archive 3) ; No corresponding category in todo file.
84 (setq cat-name (todo-current-category))
85 (todo-quit)
86 (should (todo-test-is-current-buffer todo-test-file-1))
87 (should (equal todo-category-number 2))
88 (todo-quit)
89 (should-not (todo-test-is-current-buffer todo-test-archive-1))))
90
91(ert-deftest todo-test-todo-quit02 () ; bug#27121
92 "Test the behavior of todo-quit with todo and non-todo buffers.
93If the buffer made current by invoking todo-quit in a todo-mode
94buffer is buried by quit-window, the todo-mode buffer should not
95become current."
96 (todo-show)
97 (should (todo-test-is-current-buffer todo-test-file-1))
98 (let ((dir (dired default-directory)))
99 (todo-show)
100 (todo-quit)
101 (should (equal (current-buffer) dir))
102 (quit-window)
103 (should-not (todo-test-is-current-buffer todo-test-file-1))))
104
105(ert-deftest todo-test-item-highlighting () ; bug#27133
106 "Test whether `todo-toggle-item-highlighting' highlights whole item.
107In particular, all lines of a multiline item should be highlighted."
108 (todo-show)
109 (todo-jump-to-category nil "testcat1") ; For test rerun.
110 (todo-toggle-item-highlighting)
111 (let ((end (1- (todo-item-end)))
112 (beg (todo-item-start)))
113 (should (eq (get-char-property beg 'face) 'hl-line))
114 (should (eq (get-char-property end 'face) 'hl-line))
115 (should (> (count-lines beg end) 1))
116 (should (eq (next-single-char-property-change beg 'face) (1+ end))))
117 (todo-toggle-item-highlighting)) ; Turn off highlighting (for test rerun).
118
119
120;; FIXME: must do this only after running all tests!
121;; (setq todo-directory todo-directory-orig)
122
123(provide 'todo-mode-tests)
124;;; todo-mode-tests.el ends here