org.el (org-display-inline-images): Honor the ̀beg' parameter.
[org-mode/org-mode-NeilSmithlineMods.git] / testing / lisp / test-org-footnote.el
blob91f2b97d60b2cdd9f412475fb4eca53f47241f89
1 ;;; test-org-footnote.el --- Tests for org-footnote.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-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
113 ")))
114 ;; 2.2. Put each footnote definition at the end of the section
115 ;; containing its first reference.
116 (org-test-with-temp-text
117 "* Head 1
118 Text[fn:1:Def1]
119 * Head 2
120 Text[fn:1]
121 * Head 3
122 Text[fn:2:Def2]"
123 (org-footnote-normalize)
124 (should
125 (equal (buffer-string)
126 "* Head 1
127 Text[1]
129 \[1] Def1
130 * Head 2
131 Text[1]
132 * Head 3
133 Text[2]
135 \[2] Def2
136 ")))))
138 (ert-deftest test-org-footnote/normalize-outside-org ()
139 "Test `org-footnote-normalize' specifications for buffers not in Org mode."
140 ;; 1. In a non-Org buffer, footnotes definitions are always put at
141 ;; its end.
142 (let ((org-footnote-tag-for-non-org-mode-files nil))
143 (with-temp-buffer
144 (insert "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
146 \[fn:1] Standard
148 \[fn:label] Labelled
150 \[1] Numbered
152 Some additional text.")
153 (org-footnote-normalize)
154 (should
155 (equal (buffer-string)
156 "Paragraph[1][2][3][4][5]
158 Some additional text.
160 \[1] Standard
162 \[2] Labelled
164 \[3] Numbered
166 \[4] Inline
168 \[5] Anonymous"))))
169 ;; 2. With a special tag.
170 (let ((org-footnote-tag-for-non-org-mode-files "Footnotes:"))
171 ;; 2.1. The tag must be inserted before the footnotes, separated
172 ;; from the rest of the text with a blank line.
173 (with-temp-buffer
174 (insert "Paragraph[fn:1][fn::Anonymous]
176 \[fn:1] Standard
178 Some additional text.")
179 (org-footnote-normalize)
180 (should
181 (equal (buffer-string)
182 "Paragraph[1][2]
184 Some additional text.
186 Footnotes:
188 \[1] Standard
190 \[2] Anonymous")))
191 ;; 2.2. Any tag already inserted in the buffer should be removed
192 ;; prior to footnotes insertion.
193 (with-temp-buffer
194 (insert "Text[fn:1]
195 Footnotes:
197 Additional text.
199 Footnotes:
201 \[fn:1] Definition")
202 (org-footnote-normalize)
203 (should
204 (equal (buffer-string)
205 "Text[1]
207 Additional text.
209 Footnotes:
211 \[1] Definition"))))
212 ;; 3. As an exception, in `message-mode' buffer, if a signature is
213 ;; present, insert footnotes before it.n
214 (let ((org-footnote-tag-for-non-org-mode-files nil))
215 (with-temp-buffer
216 (insert "Body[fn::def]
218 Fake signature
220 Signature")
221 ;; Mimic `message-mode'.
222 (let ((major-mode 'message-mode)
223 (message-cite-prefix-regexp "\\([ ]*[_.[:word:]]+>+\\|[ ]*[]>|]\\)+")
224 (message-signature-separator "^-- $"))
225 (flet ((message-point-in-header-p nil nil))
226 (org-footnote-normalize)))
227 (should
228 (equal (buffer-string)
229 "Body[1]
231 Fake signature
233 \[1] def
236 Signature")))))
238 (ert-deftest test-org-footnote/sort ()
239 "Test footnotes definitions sorting."
240 (let ((org-footnote-section nil))
241 (org-test-with-temp-text
242 "Text[fn:1][fn::inline][fn:2][fn:label]
244 \[fn:label] C
246 \[fn:1] A
248 \[fn:2] B"
249 (org-footnote-normalize 'sort)
250 (should
251 (equal (buffer-string)
252 "Text[fn:1][fn::inline][fn:2][fn:label]
254 \[fn:1] A
256 \[fn:2] B
258 \[fn:label] C
260 ")))))
263 (provide 'test-org-footnote)
264 ;;; test-org-footnote.el ends here