test-org-footnote.el 18 KB

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