test-org-footnote.el 18 KB

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