test-org-footnote.el 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. ;;; test-org-footnote.el --- Tests for org-footnote.el
  2. ;; Copyright (C) 2012-2015, 2019 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <mail at nicolasgoaziou dot fr>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Code:
  15. (ert-deftest test-org-footnote/new ()
  16. "Test `org-footnote-new' specifications."
  17. ;; `org-footnote-auto-label' is t.
  18. (should
  19. (string-match-p
  20. "Test\\[fn:1\\]\n+\\[fn:1\\]"
  21. (org-test-with-temp-text "Test<point>"
  22. (let ((org-footnote-auto-label t)
  23. (org-footnote-section nil))
  24. (org-footnote-new))
  25. (buffer-string))))
  26. ;; `org-footnote-auto-label' is `random'.
  27. (should
  28. (string-match-p
  29. "Test\\[fn:\\(.+?\\)\\]\n+\\[fn:\\1\\]"
  30. (org-test-with-temp-text "Test<point>"
  31. (let ((org-footnote-auto-label 'random)
  32. (org-footnote-section nil))
  33. (org-footnote-new))
  34. (buffer-string))))
  35. ;; Error at beginning of line.
  36. (should-error
  37. (org-test-with-temp-text "<point>Test"
  38. (org-footnote-new)))
  39. ;; Error at keywords.
  40. (should-error
  41. (org-test-with-temp-text "#+TIT<point>LE: value"
  42. (org-footnote-new)))
  43. (should-error
  44. (org-test-with-temp-text "#+CAPTION: <point>\nParagraph"
  45. (org-footnote-new)))
  46. ;; Allow new footnotes in blank lines at the beginning of the
  47. ;; document.
  48. (should
  49. (string-match-p
  50. " \\[fn:1\\]"
  51. (org-test-with-temp-text " <point>"
  52. (let ((org-footnote-auto-label t)) (org-footnote-new))
  53. (buffer-string))))
  54. ;; In an headline or inlinetask, point must be either on the
  55. ;; heading itself or on the blank lines below.
  56. (should (org-test-with-temp-text "* H<point>" (org-footnote-new) t))
  57. (should
  58. (org-test-with-temp-text "* H\n <point>\nParagraph" (org-footnote-new) t))
  59. (should-error (org-test-with-temp-text "*<point> H" (org-footnote-new) t))
  60. (should-error
  61. (org-test-with-temp-text "* H <point>:tag:" (org-footnote-new) t))
  62. ;; Allow new footnotes within recursive objects, but not in links.
  63. (should
  64. (string-match-p
  65. " \\*bold\\[fn:1\\]\\*"
  66. (org-test-with-temp-text " *bold<point>*"
  67. (let ((org-footnote-auto-label t)) (org-footnote-new))
  68. (buffer-string))))
  69. (should-error
  70. (org-test-with-temp-text " [[https://orgmode.org][Org mode<point>]]"
  71. (org-footnote-new)))
  72. ;; Allow new footnotes in blank lines after an element or white
  73. ;; spaces after an object.
  74. (should
  75. (string-match-p
  76. " \\[fn:1\\]"
  77. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nA\n#+END_EXAMPLE\n <point>"
  78. (let ((org-footnote-auto-label t)) (org-footnote-new))
  79. (buffer-string))))
  80. (should
  81. (string-match-p
  82. " \\*bold\\*\\[fn:1\\]"
  83. (org-test-with-temp-text " *bold*<point>"
  84. (let ((org-footnote-auto-label t)) (org-footnote-new))
  85. (buffer-string))))
  86. ;; When creating a new footnote, move to its definition.
  87. (should
  88. (string=
  89. "[fn:1]"
  90. (org-test-with-temp-text "Text<point>"
  91. (let ((org-footnote-auto-label t)
  92. (org-footnote-auto-adjust nil))
  93. (org-footnote-new))
  94. (buffer-substring-no-properties (line-beginning-position) (point)))))
  95. ;; Re-order and re-label footnotes properly when
  96. ;; `org-footnote-auto-adjust' is non-nil.
  97. (should
  98. (string=
  99. "[fn:1] 1\n\n[fn:2] \n\n[fn:3] 2\n"
  100. (org-test-with-temp-text
  101. "Text[fn:1]Text<point>Text[fn:2]\n\n[fn:1] 1\n\n[fn:2] 2"
  102. (let ((org-footnote-auto-label t)
  103. (org-footnote-auto-adjust t)
  104. (org-footnote-section nil))
  105. (org-footnote-new))
  106. (buffer-substring-no-properties
  107. (line-beginning-position -1)
  108. (line-beginning-position 4)))))
  109. ;; Do not alter file local variables when inserting new definition
  110. ;; label.
  111. (should
  112. (equal "Paragraph[fn:1]
  113. \[fn:1]
  114. # Local Variables:
  115. # foo: t
  116. # End:"
  117. (org-test-with-temp-text
  118. "Paragraph<point>\n# Local Variables:\n# foo: t\n# End:"
  119. (let ((org-footnote-section nil)) (org-footnote-new))
  120. (buffer-string))))
  121. (should
  122. (equal "Paragraph[fn:1]
  123. * Footnotes
  124. \[fn:1]
  125. # Local Variables:
  126. # foo: t
  127. # End:"
  128. (org-test-with-temp-text
  129. "Paragraph<point>\n# Local Variables:\n# foo: t\n# End:"
  130. (let ((org-footnote-section "Footnotes")) (org-footnote-new))
  131. (buffer-string)))))
  132. (ert-deftest test-org-footnote/delete ()
  133. "Test `org-footnote-delete' specifications."
  134. ;; Regular test.
  135. (should
  136. (equal "Paragraph"
  137. (org-test-with-temp-text "Paragraph<point>[fn:1]\n\n[fn:1] Definition"
  138. (org-footnote-delete)
  139. (org-trim (buffer-string)))))
  140. ;; Remove multiple definitions and references.
  141. (should
  142. (equal "Paragraph and another"
  143. (org-test-with-temp-text
  144. "Paragraph<point>[fn:1] and another[fn:1]
  145. \[fn:1] def
  146. \[fn:1] def"
  147. (org-footnote-delete)
  148. (org-trim (buffer-string)))))
  149. ;; Delete inline footnotes and all references.
  150. (should
  151. (equal "Para and"
  152. (org-test-with-temp-text "Para<point>[fn:label:def] and[fn:label]"
  153. (org-footnote-delete)
  154. (org-trim (buffer-string)))))
  155. ;; Delete anonymous footnotes.
  156. (should
  157. (equal "Para"
  158. (let ((org-footnote-section nil))
  159. (org-test-with-temp-text "Para<point>[fn::def]"
  160. (org-footnote-delete)
  161. (org-trim (buffer-string))))))
  162. ;; With an argument, delete footnote with specified label.
  163. (should
  164. (equal "Paragraph[fn:1] and another\n\n[fn:1] def"
  165. (let ((org-footnote-section nil))
  166. (org-test-with-temp-text
  167. "Paragraph[fn:1] and another[fn:2]\n\n[fn:1] def\n\n[fn:2] def2"
  168. (org-footnote-delete "2")
  169. (org-trim (buffer-string))))))
  170. ;; Error when no argument is specified at point is not at a footnote
  171. ;; reference.
  172. (should-error
  173. (org-test-with-temp-text "Para[fn:1]\n\n[fn:1] Def"
  174. (org-footnote-delete)))
  175. ;; Correctly delete footnotes with multiple paragraphs.
  176. (should
  177. (equal "Para\n\n\nOutside footnote."
  178. (let ((org-footnote-section nil))
  179. (org-test-with-temp-text
  180. "Para[fn:1]\n\n[fn:1] para1\n\npara2\n\n\nOutside footnote."
  181. (org-footnote-delete "1")
  182. (org-trim (buffer-string))))))
  183. ;; Remove blank lines above the footnote but preserve those after
  184. ;; it.
  185. (should
  186. (equal "Text\n\n\nOther text."
  187. (let ((org-footnote-section nil))
  188. (org-test-with-temp-text
  189. "Text[fn:1]\n\n[fn:1] Definition.\n\n\nOther text."
  190. (org-footnote-delete "1")
  191. (buffer-string)))))
  192. ;; Preserve file local variables when deleting a footnote.
  193. (should
  194. (equal
  195. "Paragraph\n# Local Variables:\n# foo: t\n# End:"
  196. (org-test-with-temp-text
  197. "Paragraph[fn:1]\n[fn:1] Def 1\n# Local Variables:\n# foo: t\n# End:"
  198. (let ((org-footnote-section nil)) (org-footnote-delete "1"))
  199. (buffer-string)))))
  200. (ert-deftest test-org-footnote/goto-definition ()
  201. "Test `org-footnote-goto-definition' specifications."
  202. ;; Error on unknown definitions.
  203. (should-error
  204. (org-test-with-temp-text "No footnote definition"
  205. (org-footnote-goto-definition "1")))
  206. ;; Error when trying to reach a definition outside narrowed part of
  207. ;; buffer.
  208. (should-error
  209. (org-test-with-temp-text "Some text<point>\n[fn:1] Definition."
  210. (narrow-to-region (point-min) (point))
  211. (org-footnote-goto-definition "1")))
  212. (should-error
  213. (org-test-with-temp-text "[fn:1] Definition.\n<point>Some text"
  214. (narrow-to-region (point) (point-max))
  215. (org-footnote-goto-definition "1")))
  216. ;; Otherwise, move at the beginning of the definition, including
  217. ;; anonymous footnotes.
  218. (should
  219. (equal
  220. " Definition."
  221. (org-test-with-temp-text "Some text\n[fn:1] Definition."
  222. (org-footnote-goto-definition "1")
  223. (buffer-substring (point) (point-max)))))
  224. (should
  225. (equal
  226. "definition]"
  227. (org-test-with-temp-text "Some text[fn:label:definition]"
  228. (org-footnote-goto-definition "label")
  229. (buffer-substring (point) (point-max))))))
  230. (ert-deftest test-org-footnote/goto-previous-reference ()
  231. "Test `org-footnote-goto-previous-reference' specifications."
  232. ;; Error on unknown reference.
  233. (should-error
  234. (org-test-with-temp-text "No footnote reference"
  235. (org-footnote-goto-previous-reference "1")))
  236. ;; Error when trying to reach a reference outside narrowed part of
  237. ;; buffer.
  238. (should-error
  239. (org-test-with-temp-text "Some text<point>\nReference[fn:1]."
  240. (narrow-to-region (point-min) (point))
  241. (org-footnote-goto-previous-reference "1")))
  242. ;; Otherwise, move to closest reference from point.
  243. (should
  244. (org-test-with-temp-text "First reference[fn:1]\nReference[fn:1].<point>"
  245. (org-footnote-goto-previous-reference "1")
  246. (= (line-end-position) (point-max))))
  247. (should
  248. (org-test-with-temp-text "First reference[fn:1]\nReference[fn:1]."
  249. (org-footnote-goto-previous-reference "1")
  250. (= (line-beginning-position) (point-min)))))
  251. (ert-deftest test-org-footnote/sort ()
  252. "Test `org-footnote-sort' specifications."
  253. ;; Reorder definitions with a nil `org-footnote-section'. In this
  254. ;; case each definition is written at the end of the section
  255. ;; containing its first reference.
  256. (should
  257. (equal
  258. "
  259. Text[fn:1][fn:2]
  260. \[fn:1] Def 1
  261. \[fn:2] Def 2
  262. "
  263. (org-test-with-temp-text "
  264. Text[fn:1][fn:2]
  265. \[fn:2] Def 2
  266. \[fn:1] Def 1"
  267. (let ((org-footnote-section nil)) (org-footnote-sort))
  268. (buffer-string))))
  269. (should
  270. (equal
  271. "
  272. * H1
  273. Text[fn:1]
  274. \[fn:1] Def 1
  275. * H2
  276. Text[fn:2]
  277. \[fn:2] Def 2
  278. "
  279. (org-test-with-temp-text "
  280. * H1
  281. Text[fn:1]
  282. * H2
  283. Text[fn:2]
  284. \[fn:1] Def 1
  285. \[fn:2] Def 2
  286. "
  287. (let ((org-footnote-section nil)) (org-footnote-sort))
  288. (buffer-string))))
  289. ;; Reorder definitions with a non-nil `org-footnote-section'.
  290. (should
  291. (equal
  292. "
  293. Text[fn:1][fn:2]
  294. * Footnotes
  295. \[fn:1] Def 1
  296. \[fn:2] Def 2
  297. "
  298. (org-test-with-temp-text "
  299. Text[fn:1][fn:2]
  300. \[fn:2] Def 2
  301. \[fn:1] Def 1"
  302. (let ((org-footnote-section "Footnotes")) (org-footnote-sort))
  303. (buffer-string))))
  304. ;; When `org-footnote-section' is non-nil, clear previous footnote
  305. ;; sections.
  306. (should
  307. (equal
  308. "
  309. Text[fn:1]
  310. * Headline
  311. * Other headline
  312. * Footnotes
  313. \[fn:1] Def 1
  314. "
  315. (org-test-with-temp-text "
  316. Text[fn:1]
  317. * Footnotes
  318. \[fn:1] Def 1
  319. * Headline
  320. ** Footnotes
  321. * Other headline"
  322. (let ((org-footnote-section "Footnotes")) (org-footnote-sort))
  323. (buffer-string))))
  324. ;; Ignore anonymous footnotes.
  325. (should
  326. (equal
  327. "
  328. Text[fn:1][fn::inline][fn:2]
  329. \[fn:1] Def 1
  330. \[fn:2] Def 2
  331. "
  332. (org-test-with-temp-text
  333. "
  334. Text[fn:1][fn::inline][fn:2]
  335. \[fn:2] Def 2
  336. \[fn:1] Def 1"
  337. (let ((org-footnote-section nil)) (org-footnote-sort))
  338. (buffer-string))))
  339. ;; Ignore inline footnotes.
  340. (should
  341. (equal
  342. "
  343. Text[fn:1][fn:label:inline][fn:2]
  344. \[fn:1] Def 1
  345. \[fn:2] Def 2
  346. "
  347. (org-test-with-temp-text
  348. "
  349. Text[fn:1][fn:label:inline][fn:2]
  350. \[fn:2] Def 2
  351. \[fn:1] Def 1"
  352. (let ((org-footnote-section nil)) (org-footnote-sort))
  353. (buffer-string))))
  354. ;; Handle (deeply) nested footnotes.
  355. (should
  356. (equal
  357. "
  358. Text[fn:1][fn:3]
  359. \[fn:1] Def 1[fn:2]
  360. \[fn:2] Def 2
  361. \[fn:3] Def 3
  362. "
  363. (org-test-with-temp-text "
  364. Text[fn:1][fn:3]
  365. \[fn:1] Def 1[fn:2]
  366. \[fn:3] Def 3
  367. \[fn:2] Def 2
  368. "
  369. (let ((org-footnote-section nil)) (org-footnote-sort))
  370. (buffer-string))))
  371. (should
  372. (equal
  373. "
  374. Text[fn:1][fn:4]
  375. \[fn:1] Def 1[fn:2]
  376. \[fn:2] Def 2[fn:3]
  377. \[fn:3] Def 3
  378. \[fn:4] Def 4
  379. "
  380. (org-test-with-temp-text "
  381. Text[fn:1][fn:4]
  382. \[fn:1] Def 1[fn:2]
  383. \[fn:3] Def 3
  384. \[fn:2] Def 2[fn:3]
  385. \[fn:4] Def 4
  386. "
  387. (let ((org-footnote-section nil)) (org-footnote-sort))
  388. (buffer-string))))
  389. ;; When multiple (nested) references are used, make sure to insert
  390. ;; definition only once.
  391. (should
  392. (equal
  393. "
  394. * Section 1
  395. Text[fn:1]
  396. \[fn:1] Def 1
  397. * Section 2
  398. Text[fn:1]"
  399. (org-test-with-temp-text
  400. "
  401. * Section 1
  402. Text[fn:1]
  403. \[fn:1] Def 1
  404. * Section 2
  405. Text[fn:1]"
  406. (let ((org-footnote-section nil)) (org-footnote-sort))
  407. (buffer-string))))
  408. (should
  409. (equal
  410. "
  411. Text[fn:1][fn:4]
  412. \[fn:1] Def 1[fn:2][fn:3]
  413. \[fn:2] Def 2[fn:3]
  414. \[fn:3] Def 3
  415. \[fn:4] Def 4
  416. "
  417. (org-test-with-temp-text "
  418. Text[fn:1][fn:4]
  419. \[fn:1] Def 1[fn:2][fn:3]
  420. \[fn:3] Def 3
  421. \[fn:2] Def 2[fn:3]
  422. \[fn:4] Def 4
  423. "
  424. (let ((org-footnote-section nil)) (org-footnote-sort))
  425. (buffer-string))))
  426. ;; Insert un-referenced definitions at the end.
  427. (should
  428. (equal
  429. "Text[fn:9]
  430. \[fn:9] B
  431. \[fn:1] A
  432. "
  433. (org-test-with-temp-text "Text[fn:9]\n\n[fn:1] A\n[fn:9] B"
  434. (let ((org-footnote-section nil)) (org-footnote-sort))
  435. (buffer-string))))
  436. ;; When sorting, preserve file local variables.
  437. (should
  438. (equal "
  439. Paragraph[fn:1][fn:2]
  440. \[fn:1] Def 1
  441. \[fn:2] Def 2
  442. # Local Variables:
  443. # foo: t
  444. # End:"
  445. (org-test-with-temp-text
  446. "
  447. Paragraph[fn:1][fn:2]
  448. \[fn:2] Def 2
  449. \[fn:1] Def 1
  450. # Local Variables:
  451. # foo: t
  452. # End:"
  453. (let ((org-footnote-section nil)) (org-footnote-sort))
  454. (buffer-string)))))
  455. (ert-deftest test-org-footnote/renumber-fn:N ()
  456. "Test `org-footnote-renumber-fn:N' specifications."
  457. ;; Renumber (inline) references and definitions.
  458. (should
  459. (equal
  460. "Test[fn:1]"
  461. (org-test-with-temp-text "Test[fn:99]"
  462. (org-footnote-renumber-fn:N)
  463. (buffer-string))))
  464. (should
  465. (equal
  466. "Test[fn:1]\n\n[fn:1] 99"
  467. (org-test-with-temp-text "Test[fn:99]\n\n[fn:99] 99"
  468. (org-footnote-renumber-fn:N)
  469. (buffer-string))))
  470. (should
  471. (equal
  472. "Test[fn:1:99]"
  473. (org-test-with-temp-text "Test[fn:99:99]"
  474. (org-footnote-renumber-fn:N)
  475. (buffer-string))))
  476. ;; No-op if there's no numbered footnote.
  477. (should
  478. (equal
  479. "Test[fn:label]\n\n[fn:label] Def"
  480. (org-test-with-temp-text "Test[fn:label]\n\n[fn:label] Def"
  481. (org-footnote-renumber-fn:N)
  482. (buffer-string))))
  483. ;; Definitions without a reference get the highest numbers.
  484. (should
  485. (equal
  486. "Test[fn:1]\n[fn:1] 1\n[fn:2] 99"
  487. (org-test-with-temp-text "Test[fn:1]\n[fn:1] 1\n[fn:99] 99"
  488. (org-footnote-renumber-fn:N)
  489. (buffer-string))))
  490. ;; Sort labels in sequence. Anonymous footnotes are ignored.
  491. (should
  492. (equal
  493. "Test[fn:1][fn:2:def][fn:3]"
  494. (org-test-with-temp-text "Test[fn:4][fn:3:def][fn:2]"
  495. (org-footnote-renumber-fn:N)
  496. (buffer-string))))
  497. (should
  498. (equal
  499. "Test[fn:1][fn::def][fn:2]"
  500. (org-test-with-temp-text "Test[fn:4][fn::def][fn:2]"
  501. (org-footnote-renumber-fn:N)
  502. (buffer-string)))))
  503. (ert-deftest test-org-footnote/normalize ()
  504. "Test `org-footnote-normalize' specifications."
  505. ;; Normalize regular, inline and anonymous references.
  506. (should
  507. (equal
  508. "Test[fn:1]\n\n[fn:1] def\n"
  509. (org-test-with-temp-text "Test[fn:label]\n[fn:label] def"
  510. (let ((org-footnote-section nil)) (org-footnote-normalize))
  511. (buffer-string))))
  512. (should
  513. (equal
  514. "Test[fn:1]\n\n[fn:1] def\n"
  515. (org-test-with-temp-text "Test[fn:label:def]"
  516. (let ((org-footnote-section nil)) (org-footnote-normalize))
  517. (buffer-string))))
  518. (should
  519. (equal
  520. "Test[fn:1]\n\n[fn:1] def\n"
  521. (org-test-with-temp-text "Test[fn::def]"
  522. (let ((org-footnote-section nil)) (org-footnote-normalize))
  523. (buffer-string))))
  524. ;; Normalization includes sorting.
  525. (should
  526. (equal
  527. "Test[fn:1][fn:2]\n\n[fn:1] def2\n\n[fn:2] def\n"
  528. (org-test-with-temp-text "Test[fn:2][fn:1]\n\n[fn:2] def2\n[fn:1] def"
  529. (let ((org-footnote-section nil)) (org-footnote-normalize))
  530. (buffer-string))))
  531. (should
  532. (equal
  533. "Test[fn:1][fn:2]\n\n[fn:1] def\n\n[fn:2] inline\n"
  534. (org-test-with-temp-text "Test[fn:2][fn::inline]\n[fn:2] def\n"
  535. (let ((org-footnote-section nil)) (org-footnote-normalize))
  536. (buffer-string))))
  537. (should
  538. (equal
  539. "Test[fn:1][fn:3]
  540. \[fn:1] def[fn:2]
  541. \[fn:2] inline
  542. \[fn:3] last
  543. "
  544. (org-test-with-temp-text
  545. "Test[fn:lab1][fn:lab2]\n[fn:lab1] def[fn::inline]\n[fn:lab2] last"
  546. (let ((org-footnote-section nil)) (org-footnote-normalize))
  547. (buffer-string))))
  548. ;; When normalizing an inline reference, fill paragraph whenever the
  549. ;; `org-footnote-fill-after-inline-note-extraction' is non-nil.
  550. (should
  551. (equal
  552. "Test[fn:1] Next\n\n[fn:1] def\n"
  553. (org-test-with-temp-text "Test[fn::def]\nNext"
  554. (let ((org-footnote-section nil)
  555. (org-footnote-fill-after-inline-note-extraction t))
  556. (org-footnote-normalize))
  557. (buffer-string))))
  558. ;; Insert un-referenced definitions at the end.
  559. (should
  560. (equal
  561. "Test[fn:1]\nNext\n\n[fn:1] def\n\n[fn:2] A\n"
  562. (org-test-with-temp-text "Test[fn::def]\nNext\n[fn:unref] A"
  563. (let ((org-footnote-section nil)) (org-footnote-normalize))
  564. (buffer-string))))
  565. ;; Preserve file local variables when normalizing.
  566. (should
  567. (equal "
  568. Paragraph[fn:1][fn:2]
  569. \[fn:1] Def 1
  570. \[fn:2] Def 2
  571. # Local Variables:
  572. # foo: t
  573. # End:"
  574. (org-test-with-temp-text
  575. "
  576. Paragraph[fn:foo][fn:bar]
  577. \[fn:bar] Def 2
  578. \[fn:foo] Def 1
  579. # Local Variables:
  580. # foo: t
  581. # End:"
  582. (let ((org-footnote-section nil)) (org-footnote-normalize))
  583. (buffer-string)))))
  584. (provide 'test-org-footnote)
  585. ;;; test-org-footnote.el ends here