org-list: Fix bugs relative to item indentation
[org-mode/org-mode-NeilSmithlineMods.git] / testing / lisp / test-org-list.el
blobb056a9a58a929775dd32e3fea3f878def05f4e61
1 ;;; test-org-list.el --- Tests for org-list.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Code:
22 (ert-deftest test-org-list/list-ending ()
23 "Test if lists end at the right place."
24 ;; With two blank lines.
25 (org-test-with-temp-text "- item\n\n\n Text"
26 (goto-line 4)
27 (should-not (org-in-item-p)))
28 ;; With text less indented than top items.
29 (org-test-with-temp-text "- item\nText"
30 (goto-line 2)
31 (should-not (org-in-item-p)))
32 ;; Though, blank lines and text indentation is ignored in blocks.
33 (org-test-with-temp-text
34 "- item\n #+begin_quote\n\n\nText at column 0\n #+end_quote\n Text"
35 (goto-line 7)
36 (should (org-in-item-p))))
38 (ert-deftest test-org-list/list-navigation ()
39 "Test list navigation specifications."
40 (org-test-with-temp-text "
41 - item A
42 - item B
45 - item 1
46 - item 1.1
47 - item 1.2
48 - item 1.3
49 - item 2
52 - item X
53 - item Y"
54 (let ((org-list-use-circular-motion nil))
55 ;; 1. Test `org-next-item'.
57 ;; 1.1. Should return an error if at last item in
58 ;; a list/sub-list, unless `org-list-use-circular-motion'
59 ;; is non-nil.
60 (goto-line 9)
61 (should-error (org-next-item))
62 (let ((org-list-use-circular-motion t))
63 (should (progn (org-next-item) t)))
64 (goto-line 14)
65 (should-error (org-next-item))
66 (let ((org-list-use-circular-motion t))
67 (should (progn (org-next-item) t)))
68 ;; 1.2. Should jump over sub-lists.
69 (goto-line 6)
70 (org-next-item)
71 (should (looking-at "- item 2"))
72 ;; 1.3. Shouldn't move to another list.
73 (goto-line 3)
74 (should-error (org-next-item))
75 (should-not (looking-at "- item 1"))
76 ;; 1.4. Should move to the list/sub-list first item when
77 ;; `org-list-use-circular-motion' is non-nil.
78 (let ((org-list-use-circular-motion t))
79 (goto-line 10)
80 (org-next-item)
81 (should (looking-at "- item 1"))
82 (goto-line 9)
83 (org-next-item)
84 (should (looking-at " - item 1.1")))
85 ;; 2. Test `org-previous-item'.
87 ;; 2.1. Should return an error if at first item in
88 ;; a list/sub-list, unless `org-list-use-circular-motion is
89 ;; non-nil.
90 (goto-line 7)
91 (should-error (org-previous-item))
92 (let ((org-list-use-circular-motion t))
93 (should (progn (org-previous-item) t)))
94 (goto-line 13)
95 (should-error (org-previous-item))
96 (let ((org-list-use-circular-motion t))
97 (should (progn (org-previous-item) t)))
98 ;; 2.2. Should ignore sub-lists.
99 (goto-line 10)
100 (org-previous-item)
101 (should (looking-at "- item 1"))
102 ;; 2.3. Shouldn't move to another list.
103 (goto-line 6)
104 (should-error (org-previous-item))
105 (should-not (looking-at "- item B"))
106 ;; 2.4. Should move to the list/sub-list last item when
107 ;; `org-list-use-circular-motion' is non-nil.
108 (let ((org-list-use-circular-motion t))
109 (goto-line 6)
110 (org-previous-item)
111 (should (looking-at "- item 2"))
112 (goto-line 7)
113 (org-previous-item)
114 (should (looking-at " - item 1.3"))))))
116 (ert-deftest test-org-list/indent-item ()
117 "Test `org-indent-item' specifications."
118 ;; 1. Error when not at an item.
119 (org-test-with-temp-text "Paragraph."
120 (should-error (org-indent-item)))
121 ;; 2. Error when trying to move first item of a list.
122 (org-test-with-temp-text "
123 - Item 1
124 - Item 2"
125 (forward-line)
126 (should-error (org-indent-item)))
127 ;; 3. Indent a single item, not its children.
128 (org-test-with-temp-text "
129 - Item 1
130 - Item 2
131 - Item 2.1"
132 (search-forward "- Item 2")
133 (let (org-list-demote-modify-bullet) (org-indent-item))
134 (should (equal (buffer-string)
136 - Item 1
137 - Item 2
138 - Item 2.1")))
139 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
141 ;; 4.1. With unordered lists.
142 (org-test-with-temp-text "
143 - Item 1
144 - Item 2"
145 (search-forward "- Item 2")
146 (let ((org-list-demote-modify-bullet '(("-" . "+")))) (org-indent-item))
147 (should (equal (buffer-string)
149 - Item 1
150 + Item 2")))
151 ;; 4.2. and ordered lists.
152 (org-test-with-temp-text "
153 1. Item 1
154 2. Item 2"
155 (search-forward "2. Item 2")
156 (let ((org-plain-list-ordered-item-terminator t)
157 (org-list-demote-modify-bullet '(("1." . "+"))))
158 (org-indent-item))
159 (should (equal (buffer-string)
161 1. Item 1
162 + Item 2")))
163 ;; 5. When a region is selected, indent every item within.
164 (org-test-with-temp-text "
165 - Item 1
166 - Item 2
167 - Item 3
169 (search-forward "- Item 2")
170 (beginning-of-line)
171 (transient-mark-mode 1)
172 (push-mark (point) t t)
173 (goto-char (point-max))
174 (let (org-list-demote-modify-bullet) (org-indent-item))
175 (should (equal (buffer-string)
177 - Item 1
178 - Item 2
179 - Item 3
180 "))))
182 (ert-deftest test-org-list/indent-item-tree ()
183 "Test `org-indent-item-tree' specifications."
184 ;; 1. Error when not at an item.
185 (org-test-with-temp-text "Paragraph."
186 (should-error (org-indent-item-tree)))
187 ;; 2. Indent item along with its children.
188 (org-test-with-temp-text "
189 - Item 1
190 - Item 2
191 - Item 2.1"
192 (search-forward "- Item 2")
193 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
194 (should (equal (buffer-string)
196 - Item 1
197 - Item 2
198 - Item 2.1")))
199 ;; 3. Special case: When indenting top item, move the whole list.
200 (org-test-with-temp-text "
201 - Item 1
202 - Item 2"
203 (search-forward "- Item 1")
204 (let (org-list-demote-modify-bullet org-odd-levels-only)
205 (org-indent-item-tree))
206 (should (equal (buffer-string)
208 - Item 1
209 - Item 2")))
210 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
212 ;; 4.1. With unordered lists.
213 (org-test-with-temp-text "
214 - Item 1
215 - Item 2
216 + Item 2.1"
217 (search-forward "- Item 2")
218 (let ((org-list-demote-modify-bullet '(("-" . "+") ("+" . "-"))))
219 (org-indent-item-tree))
220 (should (equal (buffer-string)
222 - Item 1
223 + Item 2
224 - Item 2.1")))
225 ;; 4.2. and ordered lists.
226 (org-test-with-temp-text "
227 1. Item 1
228 2. Item 2
229 + Item 2.1"
230 (search-forward "2. Item 2")
231 (let ((org-plain-list-ordered-item-terminator t)
232 (org-list-demote-modify-bullet '(("1." . "+") ("+" . "1."))))
233 (org-indent-item-tree))
234 (should (equal (buffer-string)
236 1. Item 1
237 + Item 2
238 1. Item 2.1")))
239 ;; 5. When a region is selected, indent every item within.
240 (org-test-with-temp-text "
241 - Item 1
242 - Item 2
243 - Item 2.1
244 - Item 3
245 - Item 3.1
247 (search-forward "- Item 2")
248 (beginning-of-line)
249 (transient-mark-mode 1)
250 (push-mark (point) t t)
251 (goto-char (point-max))
252 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
253 (should (equal (buffer-string)
255 - Item 1
256 - Item 2
257 - Item 2.1
258 - Item 3
259 - Item 3.1
260 "))))
262 (ert-deftest test-org-list/outdent-item ()
263 "Test `org-outdent-item' specifications."
264 ;; 1. Error when not at an item.
265 (org-test-with-temp-text "Paragraph."
266 (should-error (org-outdent-item)))
267 ;; 2. Error when trying to move first item of a list.
268 (org-test-with-temp-text "
269 - Item 1
270 - Item 2"
271 (forward-line)
272 (should-error (org-outdent-item)))
273 ;; 3. Error when trying to outdent an item without its children.
274 (org-test-with-temp-text "
275 - Item 1
276 - Item 1.1
277 - Item 1.1.1"
278 (search-forward "- Item 1.1")
279 (should-error (org-outdent-item)))
280 ;; 4. Error when trying to outdent before top item.
281 (org-test-with-temp-text "
282 - Item 1
283 - Item 2"
284 (search-forward "- Item 2")
285 (should-error (org-outdent-item)))
286 ;; 5. When a region is selected, outdent every item within.
287 (org-test-with-temp-text "
288 - Item 1
289 - Item 2
290 - Item 3
292 (search-forward "- Item 2")
293 (beginning-of-line)
294 (transient-mark-mode 1)
295 (push-mark (point) t t)
296 (goto-char (point-max))
297 (let (org-list-demote-modify-bullet) (org-outdent-item))
298 (should (equal (buffer-string)
300 - Item 1
301 - Item 2
302 - Item 3
303 "))))
305 (ert-deftest test-org-list/outdent-item-tree ()
306 "Test `org-outdent-item-tree' specifications."
307 ;; 1. Error when not at an item.
308 (org-test-with-temp-text "Paragraph."
309 (should-error (org-outdent-item-tree)))
310 ;; 2. Error when trying to outdent before top item.
311 (org-test-with-temp-text "
312 - Item 1
313 - Item 2"
314 (search-forward "- Item 2")
315 (should-error (org-outdent-item-tree)))
316 ;; 3. Outdent item along with its children.
317 (org-test-with-temp-text "
318 - Item 1
319 - Item 2
320 - Item 2.1"
321 (search-forward "- Item 2")
322 (org-outdent-item-tree)
323 (should (equal (buffer-string)
325 - Item 1
326 - Item 2
327 - Item 2.1")))
328 ;; 3. Special case: When outdenting top item, move the whole list.
329 (org-test-with-temp-text "
330 - Item 1
331 - Item 2"
332 (search-forward "- Item 1")
333 (let (org-odd-levels-only) (org-outdent-item-tree))
334 (should (equal (buffer-string)
336 - Item 1
337 - Item 2")))
338 ;; 5. When a region is selected, outdent every item within.
339 (org-test-with-temp-text "
340 - Item 1
341 - Item 2
342 - Item 2.1
343 - Item 3
344 - Item 3.1
346 (search-forward "- Item 2")
347 (beginning-of-line)
348 (transient-mark-mode 1)
349 (push-mark (point) t t)
350 (goto-char (point-max))
351 (org-outdent-item-tree)
352 (should (equal (buffer-string)
354 - Item 1
355 - Item 2
356 - Item 2.1
357 - Item 3
358 - Item 3.1
359 "))))
362 (provide 'test-org-list)
363 ;;; test-org-list.el ends here