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/>.
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]
39 (org-footnote-normalize)
41 (equal (buffer-string)
42 "Paragraph[1][2][3][4][5]
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
71 (org-test-with-temp-text "* Head1
76 (org-footnote-normalize)
78 (equal (buffer-string)
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]
98 (org-footnote-normalize)
100 (equal (buffer-string)
101 "Paragraph[1][2][3][4][5]
113 ;; 2.2. Put each footnote definition at the end of the section
114 ;; containing its first reference.
115 (org-test-with-temp-text
122 (org-footnote-normalize)
124 (equal (buffer-string)
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
141 (let ((org-footnote-tag-for-non-org-mode-files nil
))
143 (insert "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
151 Some additional text.")
152 (org-footnote-normalize)
154 (equal (buffer-string)
155 "Paragraph[1][2][3][4][5]
157 Some additional text.
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.
173 (insert "Paragraph[fn:1][fn::Anonymous]
177 Some additional text.")
178 (org-footnote-normalize)
180 (equal (buffer-string)
183 Some additional text.
190 ;; 2.2. Any tag already inserted in the buffer should be removed
191 ;; prior to footnotes insertion.
201 (org-footnote-normalize)
203 (equal (buffer-string)
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
))
215 (insert "Body[fn::def]
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)))
227 (equal (buffer-string)
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]
248 (org-footnote-normalize 'sort
)
250 (equal (buffer-string)
251 "Text[fn:1][fn::inline][fn:2][fn:label]
261 (provide 'test-org-footnote
)
262 ;;; test-org-footnote.el ends here