test-org-footnote.el 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 <https://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. (should
  133. (equal "Para[fn:1]
  134. * Footnotes
  135. :properties:
  136. :custom_id: id
  137. :end:
  138. \[fn:1]"
  139. (org-test-with-temp-text
  140. "Para<point>\n* Footnotes\n:properties:\n:custom_id: id\n:end:"
  141. (let ((org-footnote-section "Footnotes"))
  142. (org-footnote-new))
  143. (org-trim (buffer-string))))))
  144. (ert-deftest test-org-footnote/delete ()
  145. "Test `org-footnote-delete' specifications."
  146. ;; Regular test.
  147. (should
  148. (equal "Paragraph"
  149. (org-test-with-temp-text "Paragraph<point>[fn:1]\n\n[fn:1] Definition"
  150. (org-footnote-delete)
  151. (org-trim (buffer-string)))))
  152. ;; Remove multiple definitions and references.
  153. (should
  154. (equal "Paragraph and another"
  155. (org-test-with-temp-text
  156. "Paragraph<point>[fn:1] and another[fn:1]
  157. \[fn:1] def
  158. \[fn:1] def"
  159. (org-footnote-delete)
  160. (org-trim (buffer-string)))))
  161. ;; Delete inline footnotes and all references.
  162. (should
  163. (equal "Para and"
  164. (org-test-with-temp-text "Para<point>[fn:label:def] and[fn:label]"
  165. (org-footnote-delete)
  166. (org-trim (buffer-string)))))
  167. ;; Delete anonymous footnotes.
  168. (should
  169. (equal "Para"
  170. (let ((org-footnote-section nil))
  171. (org-test-with-temp-text "Para<point>[fn::def]"
  172. (org-footnote-delete)
  173. (org-trim (buffer-string))))))
  174. ;; With an argument, delete footnote with specified label.
  175. (should
  176. (equal "Paragraph[fn:1] and another\n\n[fn:1] def"
  177. (let ((org-footnote-section nil))
  178. (org-test-with-temp-text
  179. "Paragraph[fn:1] and another[fn:2]\n\n[fn:1] def\n\n[fn:2] def2"
  180. (org-footnote-delete "2")
  181. (org-trim (buffer-string))))))
  182. ;; Error when no argument is specified at point is not at a footnote
  183. ;; reference.
  184. (should-error
  185. (org-test-with-temp-text "Para[fn:1]\n\n[fn:1] Def"
  186. (org-footnote-delete)))
  187. ;; Correctly delete footnotes with multiple paragraphs.
  188. (should
  189. (equal "Para\n\n\nOutside footnote."
  190. (let ((org-footnote-section nil))
  191. (org-test-with-temp-text
  192. "Para[fn:1]\n\n[fn:1] para1\n\npara2\n\n\nOutside footnote."
  193. (org-footnote-delete "1")
  194. (org-trim (buffer-string))))))
  195. ;; Remove blank lines above the footnote but preserve those after
  196. ;; it.
  197. (should
  198. (equal "Text\n\n\nOther text."
  199. (let ((org-footnote-section nil))
  200. (org-test-with-temp-text
  201. "Text[fn:1]\n\n[fn:1] Definition.\n\n\nOther text."
  202. (org-footnote-delete "1")
  203. (buffer-string)))))
  204. ;; Preserve file local variables when deleting a footnote.
  205. (should
  206. (equal
  207. "Paragraph\n# Local Variables:\n# foo: t\n# End:"
  208. (org-test-with-temp-text
  209. "Paragraph[fn:1]\n[fn:1] Def 1\n# Local Variables:\n# foo: t\n# End:"
  210. (let ((org-footnote-section nil)) (org-footnote-delete "1"))
  211. (buffer-string)))))
  212. (ert-deftest test-org-footnote/goto-definition ()
  213. "Test `org-footnote-goto-definition' specifications."
  214. ;; Error on unknown definitions.
  215. (should-error
  216. (org-test-with-temp-text "No footnote definition"
  217. (org-footnote-goto-definition "1")))
  218. ;; Error when trying to reach a definition outside narrowed part of
  219. ;; buffer.
  220. (should-error
  221. (org-test-with-temp-text "Some text<point>\n[fn:1] Definition."
  222. (narrow-to-region (point-min) (point))
  223. (org-footnote-goto-definition "1")))
  224. (should-error
  225. (org-test-with-temp-text "[fn:1] Definition.\n<point>Some text"
  226. (narrow-to-region (point) (point-max))
  227. (org-footnote-goto-definition "1")))
  228. ;; Otherwise, move at the beginning of the definition, including
  229. ;; anonymous footnotes.
  230. (should
  231. (equal
  232. " Definition."
  233. (org-test-with-temp-text "Some text\n[fn:1] Definition."
  234. (org-footnote-goto-definition "1")
  235. (buffer-substring (point) (point-max)))))
  236. (should
  237. (equal
  238. "definition]"
  239. (org-test-with-temp-text "Some text[fn:label:definition]"
  240. (org-footnote-goto-definition "label")
  241. (buffer-substring (point) (point-max))))))
  242. (ert-deftest test-org-footnote/goto-previous-reference ()
  243. "Test `org-footnote-goto-previous-reference' specifications."
  244. ;; Error on unknown reference.
  245. (should-error
  246. (org-test-with-temp-text "No footnote reference"
  247. (org-footnote-goto-previous-reference "1")))
  248. ;; Error when trying to reach a reference outside narrowed part of
  249. ;; buffer.
  250. (should-error
  251. (org-test-with-temp-text "Some text<point>\nReference[fn:1]."
  252. (narrow-to-region (point-min) (point))
  253. (org-footnote-goto-previous-reference "1")))
  254. ;; Otherwise, move to closest reference from point.
  255. (should
  256. (org-test-with-temp-text "First reference[fn:1]\nReference[fn:1].<point>"
  257. (org-footnote-goto-previous-reference "1")
  258. (= (line-end-position) (point-max))))
  259. (should
  260. (org-test-with-temp-text "First reference[fn:1]\nReference[fn:1]."
  261. (org-footnote-goto-previous-reference "1")
  262. (= (line-beginning-position) (point-min)))))
  263. (ert-deftest test-org-footnote/sort ()
  264. "Test `org-footnote-sort' specifications."
  265. ;; Reorder definitions with a nil `org-footnote-section'. In this
  266. ;; case each definition is written at the end of the section
  267. ;; containing its first reference.
  268. (should
  269. (equal
  270. "
  271. Text[fn:1][fn:2]
  272. \[fn:1] Def 1
  273. \[fn:2] Def 2
  274. "
  275. (org-test-with-temp-text "
  276. Text[fn:1][fn:2]
  277. \[fn:2] Def 2
  278. \[fn:1] Def 1"
  279. (let ((org-footnote-section nil)) (org-footnote-sort))
  280. (buffer-string))))
  281. (should
  282. (equal
  283. "
  284. * H1
  285. Text[fn:1]
  286. \[fn:1] Def 1
  287. * H2
  288. Text[fn:2]
  289. \[fn:2] Def 2
  290. "
  291. (org-test-with-temp-text "
  292. * H1
  293. Text[fn:1]
  294. * H2
  295. Text[fn:2]
  296. \[fn:1] Def 1
  297. \[fn:2] Def 2
  298. "
  299. (let ((org-footnote-section nil)) (org-footnote-sort))
  300. (buffer-string))))
  301. ;; Reorder definitions with a non-nil `org-footnote-section'.
  302. (should
  303. (equal
  304. "
  305. Text[fn:1][fn:2]
  306. * Footnotes
  307. \[fn:1] Def 1
  308. \[fn:2] Def 2
  309. "
  310. (org-test-with-temp-text "
  311. Text[fn:1][fn:2]
  312. \[fn:2] Def 2
  313. \[fn:1] Def 1"
  314. (let ((org-footnote-section "Footnotes")) (org-footnote-sort))
  315. (buffer-string))))
  316. ;; When `org-footnote-section' is non-nil, clear previous footnote
  317. ;; sections.
  318. (should
  319. (equal
  320. "
  321. Text[fn:1]
  322. * Headline
  323. * Other headline
  324. * Footnotes
  325. \[fn:1] Def 1
  326. "
  327. (org-test-with-temp-text "
  328. Text[fn:1]
  329. * Footnotes
  330. \[fn:1] Def 1
  331. * Headline
  332. ** Footnotes
  333. * Other headline"
  334. (let ((org-footnote-section "Footnotes")) (org-footnote-sort))
  335. (buffer-string))))
  336. ;; Ignore anonymous footnotes.
  337. (should
  338. (equal
  339. "
  340. Text[fn:1][fn::inline][fn:2]
  341. \[fn:1] Def 1
  342. \[fn:2] Def 2
  343. "
  344. (org-test-with-temp-text
  345. "
  346. Text[fn:1][fn::inline][fn:2]
  347. \[fn:2] Def 2
  348. \[fn:1] Def 1"
  349. (let ((org-footnote-section nil)) (org-footnote-sort))
  350. (buffer-string))))
  351. ;; Ignore inline footnotes.
  352. (should
  353. (equal
  354. "
  355. Text[fn:1][fn:label:inline][fn:2]
  356. \[fn:1] Def 1
  357. \[fn:2] Def 2
  358. "
  359. (org-test-with-temp-text
  360. "
  361. Text[fn:1][fn:label:inline][fn:2]
  362. \[fn:2] Def 2
  363. \[fn:1] Def 1"
  364. (let ((org-footnote-section nil)) (org-footnote-sort))
  365. (buffer-string))))
  366. ;; Handle (deeply) nested footnotes.
  367. (should
  368. (equal
  369. "
  370. Text[fn:1][fn:3]
  371. \[fn:1] Def 1[fn:2]
  372. \[fn:2] Def 2
  373. \[fn:3] Def 3
  374. "
  375. (org-test-with-temp-text "
  376. Text[fn:1][fn:3]
  377. \[fn:1] Def 1[fn:2]
  378. \[fn:3] Def 3
  379. \[fn:2] Def 2
  380. "
  381. (let ((org-footnote-section nil)) (org-footnote-sort))
  382. (buffer-string))))
  383. (should
  384. (equal
  385. "
  386. Text[fn:1][fn:4]
  387. \[fn:1] Def 1[fn:2]
  388. \[fn:2] Def 2[fn:3]
  389. \[fn:3] Def 3
  390. \[fn:4] Def 4
  391. "
  392. (org-test-with-temp-text "
  393. Text[fn:1][fn:4]
  394. \[fn:1] Def 1[fn:2]
  395. \[fn:3] Def 3
  396. \[fn:2] Def 2[fn:3]
  397. \[fn:4] Def 4
  398. "
  399. (let ((org-footnote-section nil)) (org-footnote-sort))
  400. (buffer-string))))
  401. ;; When multiple (nested) references are used, make sure to insert
  402. ;; definition only once.
  403. (should
  404. (equal
  405. "
  406. * Section 1
  407. Text[fn:1]
  408. \[fn:1] Def 1
  409. * Section 2
  410. Text[fn:1]"
  411. (org-test-with-temp-text
  412. "
  413. * Section 1
  414. Text[fn:1]
  415. \[fn:1] Def 1
  416. * Section 2
  417. Text[fn:1]"
  418. (let ((org-footnote-section nil)) (org-footnote-sort))
  419. (buffer-string))))
  420. (should
  421. (equal
  422. "
  423. Text[fn:1][fn:4]
  424. \[fn:1] Def 1[fn:2][fn:3]
  425. \[fn:2] Def 2[fn:3]
  426. \[fn:3] Def 3
  427. \[fn:4] Def 4
  428. "
  429. (org-test-with-temp-text "
  430. Text[fn:1][fn:4]
  431. \[fn:1] Def 1[fn:2][fn:3]
  432. \[fn:3] Def 3
  433. \[fn:2] Def 2[fn:3]
  434. \[fn:4] Def 4
  435. "
  436. (let ((org-footnote-section nil)) (org-footnote-sort))
  437. (buffer-string))))
  438. ;; Insert un-referenced definitions at the end.
  439. (should
  440. (equal
  441. "Text[fn:9]
  442. \[fn:9] B
  443. \[fn:1] A
  444. "
  445. (org-test-with-temp-text "Text[fn:9]\n\n[fn:1] A\n[fn:9] B"
  446. (let ((org-footnote-section nil)) (org-footnote-sort))
  447. (buffer-string))))
  448. ;; When sorting, preserve file local variables.
  449. (should
  450. (equal "
  451. Paragraph[fn:1][fn:2]
  452. \[fn:1] Def 1
  453. \[fn:2] Def 2
  454. # Local Variables:
  455. # foo: t
  456. # End:"
  457. (org-test-with-temp-text
  458. "
  459. Paragraph[fn:1][fn:2]
  460. \[fn:2] Def 2
  461. \[fn:1] Def 1
  462. # Local Variables:
  463. # foo: t
  464. # End:"
  465. (let ((org-footnote-section nil)) (org-footnote-sort))
  466. (buffer-string)))))
  467. (ert-deftest test-org-footnote/renumber-fn:N ()
  468. "Test `org-footnote-renumber-fn:N' specifications."
  469. ;; Renumber (inline) references and definitions.
  470. (should
  471. (equal
  472. "Test[fn:1]"
  473. (org-test-with-temp-text "Test[fn:99]"
  474. (org-footnote-renumber-fn:N)
  475. (buffer-string))))
  476. (should
  477. (equal
  478. "Test[fn:1]\n\n[fn:1] 99"
  479. (org-test-with-temp-text "Test[fn:99]\n\n[fn:99] 99"
  480. (org-footnote-renumber-fn:N)
  481. (buffer-string))))
  482. (should
  483. (equal
  484. "Test[fn:1:99]"
  485. (org-test-with-temp-text "Test[fn:99:99]"
  486. (org-footnote-renumber-fn:N)
  487. (buffer-string))))
  488. ;; No-op if there's no numbered footnote.
  489. (should
  490. (equal
  491. "Test[fn:label]\n\n[fn:label] Def"
  492. (org-test-with-temp-text "Test[fn:label]\n\n[fn:label] Def"
  493. (org-footnote-renumber-fn:N)
  494. (buffer-string))))
  495. ;; Definitions without a reference get the highest numbers.
  496. (should
  497. (equal
  498. "Test[fn:1]\n[fn:1] 1\n[fn:2] 99"
  499. (org-test-with-temp-text "Test[fn:1]\n[fn:1] 1\n[fn:99] 99"
  500. (org-footnote-renumber-fn:N)
  501. (buffer-string))))
  502. ;; Sort labels in sequence. Anonymous footnotes are ignored.
  503. (should
  504. (equal
  505. "Test[fn:1][fn:2:def][fn:3]"
  506. (org-test-with-temp-text "Test[fn:4][fn:3:def][fn:2]"
  507. (org-footnote-renumber-fn:N)
  508. (buffer-string))))
  509. (should
  510. (equal
  511. "Test[fn:1][fn::def][fn:2]"
  512. (org-test-with-temp-text "Test[fn:4][fn::def][fn:2]"
  513. (org-footnote-renumber-fn:N)
  514. (buffer-string)))))
  515. (ert-deftest test-org-footnote/normalize ()
  516. "Test `org-footnote-normalize' specifications."
  517. ;; Normalize regular, inline and anonymous references.
  518. (should
  519. (equal
  520. "Test[fn:1]\n\n[fn:1] def\n"
  521. (org-test-with-temp-text "Test[fn:label]\n[fn:label] def"
  522. (let ((org-footnote-section nil)) (org-footnote-normalize))
  523. (buffer-string))))
  524. (should
  525. (equal
  526. "Test[fn:1]\n\n[fn:1] def\n"
  527. (org-test-with-temp-text "Test[fn:label:def]"
  528. (let ((org-footnote-section nil)) (org-footnote-normalize))
  529. (buffer-string))))
  530. (should
  531. (equal
  532. "Test[fn:1]\n\n[fn:1] def\n"
  533. (org-test-with-temp-text "Test[fn::def]"
  534. (let ((org-footnote-section nil)) (org-footnote-normalize))
  535. (buffer-string))))
  536. ;; Normalization includes sorting.
  537. (should
  538. (equal
  539. "Test[fn:1][fn:2]\n\n[fn:1] def2\n\n[fn:2] def\n"
  540. (org-test-with-temp-text "Test[fn:2][fn:1]\n\n[fn:2] def2\n[fn:1] def"
  541. (let ((org-footnote-section nil)) (org-footnote-normalize))
  542. (buffer-string))))
  543. (should
  544. (equal
  545. "Test[fn:1][fn:2]\n\n[fn:1] def\n\n[fn:2] inline\n"
  546. (org-test-with-temp-text "Test[fn:2][fn::inline]\n[fn:2] def\n"
  547. (let ((org-footnote-section nil)) (org-footnote-normalize))
  548. (buffer-string))))
  549. (should
  550. (equal
  551. "Test[fn:1][fn:3]
  552. \[fn:1] def[fn:2]
  553. \[fn:2] inline
  554. \[fn:3] last
  555. "
  556. (org-test-with-temp-text
  557. "Test[fn:lab1][fn:lab2]\n[fn:lab1] def[fn::inline]\n[fn:lab2] last"
  558. (let ((org-footnote-section nil)) (org-footnote-normalize))
  559. (buffer-string))))
  560. ;; When normalizing an inline reference, fill paragraph whenever the
  561. ;; `org-footnote-fill-after-inline-note-extraction' is non-nil.
  562. (should
  563. (equal
  564. "Test[fn:1] Next\n\n[fn:1] def\n"
  565. (org-test-with-temp-text "Test[fn::def]\nNext"
  566. (let ((org-footnote-section nil)
  567. (org-footnote-fill-after-inline-note-extraction t))
  568. (org-footnote-normalize))
  569. (buffer-string))))
  570. ;; Insert un-referenced definitions at the end.
  571. (should
  572. (equal
  573. "Test[fn:1]\nNext\n\n[fn:1] def\n\n[fn:2] A\n"
  574. (org-test-with-temp-text "Test[fn::def]\nNext\n[fn:unref] A"
  575. (let ((org-footnote-section nil)) (org-footnote-normalize))
  576. (buffer-string))))
  577. ;; Preserve file local variables when normalizing.
  578. (should
  579. (equal "
  580. Paragraph[fn:1][fn:2]
  581. \[fn:1] Def 1
  582. \[fn:2] Def 2
  583. # Local Variables:
  584. # foo: t
  585. # End:"
  586. (org-test-with-temp-text
  587. "
  588. Paragraph[fn:foo][fn:bar]
  589. \[fn:bar] Def 2
  590. \[fn:foo] Def 1
  591. # Local Variables:
  592. # foo: t
  593. # End:"
  594. (let ((org-footnote-section nil)) (org-footnote-normalize))
  595. (buffer-string)))))
  596. (provide 'test-org-footnote)
  597. ;;; test-org-footnote.el ends here