org-agenda.el (org-agenda-local-vars): Don't include `org-agenda-show-window'
[org-mode.git] / testing / lisp / test-org-footnote.el
blobf55ed843bb36f47f04f2bb2abdf3e079a7623148
1 ;;; test-org-footnote.el --- Tests for org-footnote.el
3 ;; Copyright (C) 2012, 2013 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-footnote/normalize-in-org ()
23 "Test specifications for `org-footnote-normalize' in an Org buffer."
24 ;; 1. With a non-nil `org-footnote-section'.
25 (let ((org-footnote-section "Footnotes")
26 (org-blank-before-new-entry '((heading . auto))))
27 ;; 1.1. Normalize each type of footnote: standard, labelled,
28 ;; numbered, inline, anonymous.
29 (org-test-with-temp-text
30 "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
32 * Footnotes
34 \[fn:1] Standard
36 \[fn:label] Labelled
38 \[1] Numbered"
39 (org-footnote-normalize)
40 (should
41 (equal (buffer-string)
42 "Paragraph[1][2][3][4][5]
44 * Footnotes
46 \[1] Standard
48 \[2] Labelled
50 \[3] Numbered
52 \[4] Inline
54 \[5] Anonymous
57 ")))
58 ;; 1.2. When no footnote section is present, create it. Follow
59 ;; `org-blank-before-new-entry' specifications when doing so.
60 (org-test-with-temp-text "Paragraph[fn:1]\n\n[fn:1] Definition"
61 (org-footnote-normalize)
62 (should (equal (buffer-string)
63 "Paragraph[1]\n\n* Footnotes\n\n[1] Definition")))
64 (org-test-with-temp-text "Paragraph[fn:1]\n* Head1\n[fn:1] Definition"
65 (let ((org-blank-before-new-entry '((heading))))
66 (org-footnote-normalize))
67 (should (equal (buffer-string)
68 "Paragraph[1]\n* Head1\n* Footnotes\n\n[1] Definition")))
69 ;; 1.3. When the footnote section is misplaced, move it at the end
70 ;; of the buffer.
71 (org-test-with-temp-text "* Head1
72 Body[fn:1]
73 * Footnotes
74 \[fn:1] Definition 1
75 * Head2"
76 (org-footnote-normalize)
77 (should
78 (equal (buffer-string)
79 "* Head1
80 Body[1]
81 * Head2
83 * Footnotes
85 \[1] Definition 1"))))
86 ;; 2. With a nil `org-footnote-section'.
87 (let ((org-footnote-section nil))
88 ;; 2.1. Normalize each type of footnote: standard, labelled,
89 ;; numbered, inline, anonymous.
90 (org-test-with-temp-text
91 "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
93 \[fn:1] Standard
95 \[fn:label] Labelled
97 \[1] Numbered"
98 (org-footnote-normalize)
99 (should
100 (equal (buffer-string)
101 "Paragraph[1][2][3][4][5]
103 \[1] Standard
105 \[2] Labelled
107 \[3] Numbered
109 \[4] Inline
111 \[5] Anonymous
112 ")))
113 ;; 2.2. Put each footnote definition at the end of the section
114 ;; containing its first reference.
115 (org-test-with-temp-text
116 "* Head 1
117 Text[fn:1:Def1]
118 * Head 2
119 Text[fn:1]
120 * Head 3
121 Text[fn:2:Def2]"
122 (org-footnote-normalize)
123 (should
124 (equal (buffer-string)
125 "* Head 1
126 Text[1]
128 \[1] Def1
129 * Head 2
130 Text[1]
131 * Head 3
132 Text[2]
134 \[2] Def2
135 ")))))
137 (ert-deftest test-org-footnote/normalize-outside-org ()
138 "Test `org-footnote-normalize' specifications for buffers not in Org mode."
139 ;; 1. In a non-Org buffer, footnotes definitions are always put at
140 ;; its end.
141 (let ((org-footnote-tag-for-non-org-mode-files nil))
142 (with-temp-buffer
143 (insert "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
145 \[fn:1] Standard
147 \[fn:label] Labelled
149 \[1] Numbered
151 Some additional text.")
152 (org-footnote-normalize)
153 (should
154 (equal (buffer-string)
155 "Paragraph[1][2][3][4][5]
157 Some additional text.
159 \[1] Standard
161 \[2] Labelled
163 \[3] Numbered
165 \[4] Inline
167 \[5] Anonymous"))))
168 ;; 2. With a special tag.
169 (let ((org-footnote-tag-for-non-org-mode-files "Footnotes:"))
170 ;; 2.1. The tag must be inserted before the footnotes, separated
171 ;; from the rest of the text with a blank line.
172 (with-temp-buffer
173 (insert "Paragraph[fn:1][fn::Anonymous]
175 \[fn:1] Standard
177 Some additional text.")
178 (org-footnote-normalize)
179 (should
180 (equal (buffer-string)
181 "Paragraph[1][2]
183 Some additional text.
185 Footnotes:
187 \[1] Standard
189 \[2] Anonymous")))
190 ;; 2.2. Any tag already inserted in the buffer should be removed
191 ;; prior to footnotes insertion.
192 (with-temp-buffer
193 (insert "Text[fn:1]
194 Footnotes:
196 Additional text.
198 Footnotes:
200 \[fn:1] Definition")
201 (org-footnote-normalize)
202 (should
203 (equal (buffer-string)
204 "Text[1]
206 Additional text.
208 Footnotes:
210 \[1] Definition"))))
211 ;; 3. As an exception, in `message-mode' buffer, if a signature is
212 ;; present, insert footnotes before it.n
213 (let ((org-footnote-tag-for-non-org-mode-files nil))
214 (with-temp-buffer
215 (insert "Body[fn::def]
217 Fake signature
219 Signature")
220 ;; Mimic `message-mode'.
221 (let ((major-mode 'message-mode)
222 (message-cite-prefix-regexp "\\([ ]*[_.[:word:]]+>+\\|[ ]*[]>|]\\)+")
223 (message-signature-separator "^-- $"))
224 (flet ((message-point-in-header-p nil nil))
225 (org-footnote-normalize)))
226 (should
227 (equal (buffer-string)
228 "Body[1]
230 Fake signature
232 \[1] def
235 Signature")))))
237 (ert-deftest test-org-footnote/sort ()
238 "Test footnotes definitions sorting."
239 (let ((org-footnote-section nil))
240 (org-test-with-temp-text
241 "Text[fn:1][fn::inline][fn:2][fn:label]
243 \[fn:label] C
245 \[fn:1] A
247 \[fn:2] B"
248 (org-footnote-normalize 'sort)
249 (should
250 (equal (buffer-string)
251 "Text[fn:1][fn::inline][fn:2][fn:label]
253 \[fn:1] A
255 \[fn:2] B
257 \[fn:label] C
258 ")))))
261 (provide 'test-org-footnote)
262 ;;; test-org-footnote.el ends here