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/>.
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]
114 ;; 2.2. Put each footnote definition at the end of the section
115 ;; containing its first reference.
116 (org-test-with-temp-text
123 (org-footnote-normalize)
125 (equal (buffer-string)
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
142 (let ((org-footnote-tag-for-non-org-mode-files nil
))
144 (insert "Paragraph[fn:1][fn:label][1][fn:inline:Inline][fn::Anonymous]
152 Some additional text.")
153 (org-footnote-normalize)
155 (equal (buffer-string)
156 "Paragraph[1][2][3][4][5]
158 Some additional text.
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.
174 (insert "Paragraph[fn:1][fn::Anonymous]
178 Some additional text.")
179 (org-footnote-normalize)
181 (equal (buffer-string)
184 Some additional text.
191 ;; 2.2. Any tag already inserted in the buffer should be removed
192 ;; prior to footnotes insertion.
202 (org-footnote-normalize)
204 (equal (buffer-string)
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
))
216 (insert "Body[fn::def]
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)))
228 (equal (buffer-string)
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]
249 (org-footnote-normalize 'sort
)
251 (equal (buffer-string)
252 "Text[fn:1][fn::inline][fn:2][fn:label]
263 (provide 'test-org-footnote
)
264 ;;; test-org-footnote.el ends here