test-org-element.el 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  1. ;;; test-org-element.el --- Tests for org-element.el
  2. ;; Copyright (C) 2012 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  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. (unless (featurep 'org-element)
  15. (signal 'missing-test-dependency "org-element"))
  16. (defun org-test-parse-and-interpret (text)
  17. "Parse TEXT as Org syntax and interpret it.
  18. Return interpreted string."
  19. (with-temp-buffer
  20. (org-mode)
  21. (insert text)
  22. (org-element-interpret-data (org-element-parse-buffer))))
  23. ;;; Test `org-element-map'
  24. (ert-deftest test-org-element/map ()
  25. "Test `org-element-map'."
  26. ;; Can map to `plain-text' objects.
  27. (should
  28. (= 2
  29. (org-test-with-temp-text "Some text \alpha
  30. #+BEGIN_CENTER
  31. Some other text
  32. #+END_CENTER"
  33. (let ((count 0))
  34. (org-element-map
  35. (org-element-parse-buffer) 'plain-text
  36. (lambda (s) (when (string-match "text" s) (incf count))))
  37. count))))
  38. ;; Applies to secondary strings
  39. (should
  40. (org-element-map '("some " (bold nil "bold") "text") 'bold 'identity))
  41. ;; Enter secondary strings before entering contents.
  42. (should
  43. (equal
  44. "alpha"
  45. (org-element-property
  46. :name
  47. (org-test-with-temp-text "* Some \\alpha headline\n\\beta entity."
  48. (org-element-map (org-element-parse-buffer) 'entity 'identity nil t)))))
  49. ;; Apply NO-RECURSION argument.
  50. (should-not
  51. (org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
  52. (org-element-map
  53. (org-element-parse-buffer) 'entity 'identity nil nil 'center-block)))
  54. ;; Use WITH-AFFILIATED argument.
  55. (should
  56. (equal
  57. '("a" "1" "b" "2")
  58. (org-test-with-temp-text "#+CAPTION[a]: 1\n#+CAPTION[b]: 2\nParagraph"
  59. (org-element-map
  60. (org-element-at-point) 'plain-text 'identity nil nil nil t)))))
  61. ;;; Test Setters
  62. (ert-deftest test-org-element/put-property ()
  63. "Test `org-element-put-property' specifications."
  64. (org-test-with-temp-text "* Headline\n *a*"
  65. (let ((tree (org-element-parse-buffer)))
  66. (org-element-put-property
  67. (org-element-map tree 'bold 'identity nil t) :test 1)
  68. (should (org-element-property
  69. :test (org-element-map tree 'bold 'identity nil t))))))
  70. (ert-deftest test-org-element/set-contents ()
  71. "Test `org-element-set-contents' specifications."
  72. ;; Accept multiple entries.
  73. (should
  74. (equal '("b" (italic nil "a"))
  75. (org-test-with-temp-text "* Headline\n *a*"
  76. (let ((tree (org-element-parse-buffer)))
  77. (org-element-set-contents
  78. (org-element-map tree 'bold 'identity nil t) "b" '(italic nil "a"))
  79. (org-element-contents
  80. (org-element-map tree 'bold 'identity nil t))))))
  81. ;; Accept atoms and elements.
  82. (should
  83. (equal '("b")
  84. (org-test-with-temp-text "* Headline\n *a*"
  85. (let ((tree (org-element-parse-buffer)))
  86. (org-element-set-contents
  87. (org-element-map tree 'bold 'identity nil t) "b")
  88. (org-element-contents
  89. (org-element-map tree 'bold 'identity nil t))))))
  90. (should
  91. (equal '((italic nil "b"))
  92. (org-test-with-temp-text "* Headline\n *a*"
  93. (let ((tree (org-element-parse-buffer)))
  94. (org-element-set-contents
  95. (org-element-map tree 'bold 'identity nil t) '(italic nil "b"))
  96. (org-element-contents
  97. (org-element-map tree 'bold 'identity nil t))))))
  98. ;; Allow nil contents.
  99. (should-not
  100. (org-test-with-temp-text "* Headline\n *a*"
  101. (let ((tree (org-element-parse-buffer)))
  102. (org-element-set-contents (org-element-map tree 'bold 'identity nil t))
  103. (org-element-contents (org-element-map tree 'bold 'identity nil t))))))
  104. (ert-deftest test-org-element/set-element ()
  105. "Test `org-element-set-element' specifications."
  106. (org-test-with-temp-text "* Headline\n*a*"
  107. (let ((tree (org-element-parse-buffer)))
  108. (org-element-set-element
  109. (org-element-map tree 'bold 'identity nil t)
  110. '(italic nil "b"))
  111. ;; Check if object is correctly replaced.
  112. (should (org-element-map tree 'italic 'identity))
  113. (should-not (org-element-map tree 'bold 'identity))
  114. ;; Check if new object's parent is correctly set.
  115. (should
  116. (eq
  117. (org-element-property :parent
  118. (org-element-map tree 'italic 'identity nil t))
  119. (org-element-map tree 'paragraph 'identity nil t))))))
  120. (ert-deftest test-org-element/adopt-elements ()
  121. "Test `org-element-adopt-elements' specifications."
  122. ;; Adopt an element.
  123. (should
  124. (equal '(plain-text italic)
  125. (org-test-with-temp-text "* Headline\n *a*"
  126. (let ((tree (org-element-parse-buffer)))
  127. (org-element-adopt-elements
  128. (org-element-map tree 'bold 'identity nil t) '(italic nil "a"))
  129. (mapcar (lambda (blob) (org-element-type blob))
  130. (org-element-contents
  131. (org-element-map tree 'bold 'identity nil t)))))))
  132. ;; Adopt a string.
  133. (should
  134. (equal '("a" "b")
  135. (org-test-with-temp-text "* Headline\n *a*"
  136. (let ((tree (org-element-parse-buffer)))
  137. (org-element-adopt-elements
  138. (org-element-map tree 'bold 'identity nil t) "b")
  139. (org-element-contents
  140. (org-element-map tree 'bold 'identity nil t)))))))
  141. ;;; Test Parsers
  142. ;;;; Affiliated Keywords
  143. (ert-deftest test-org-element/affiliated-keywords-parser ()
  144. "Test affiliated keywords parsing."
  145. ;; Read simple keywords.
  146. (should
  147. (equal "para"
  148. (org-element-property
  149. :name
  150. (org-test-with-temp-text "#+NAME: para\nParagraph"
  151. (org-element-at-point)))))
  152. (should
  153. (= 1
  154. (org-element-property
  155. :begin
  156. (org-test-with-temp-text "#+NAME: para\nParagraph"
  157. (org-element-at-point)))))
  158. ;; Parse multiple keywords.
  159. (should
  160. (equal
  161. '("line2" "line1")
  162. (org-element-property
  163. :attr_ascii
  164. (org-test-with-temp-text
  165. "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
  166. (org-element-at-point)))))
  167. ;; Parse "parsed" keywords.
  168. (should
  169. (equal
  170. '(("caption"))
  171. (org-test-with-temp-text "#+CAPTION: caption\nParagraph"
  172. (car (org-element-property :caption (org-element-at-point))))))
  173. ;; Parse dual keywords.
  174. (should
  175. (equal
  176. '((("long") "short"))
  177. (org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
  178. (org-element-property :caption (org-element-at-point)))))
  179. ;; Allow multiple caption keywords.
  180. (should
  181. (equal
  182. '((("l2") "s2") (("l1") "s1"))
  183. (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
  184. (org-element-property :caption (org-element-at-point))))))
  185. ;;;; Babel Call
  186. (ert-deftest test-org-element/babel-call-parser ()
  187. "Test `babel-call' parsing."
  188. ;; Standard test.
  189. (should
  190. (org-test-with-temp-text "#+CALL: test()"
  191. (org-element-map (org-element-parse-buffer) 'babel-call 'identity)))
  192. ;; Ignore case.
  193. (should
  194. (org-test-with-temp-text "#+call: test()"
  195. (org-element-map (org-element-parse-buffer) 'babel-call 'identity))))
  196. ;;;; Bold
  197. (ert-deftest test-org-element/bold-parser ()
  198. "Test `bold' parser."
  199. ;; Standard test.
  200. (should
  201. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  202. (org-test-with-temp-text "*bold*"
  203. (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))))
  204. ;; Multi-line markup.
  205. (should
  206. (equal
  207. (org-element-contents
  208. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  209. (org-test-with-temp-text "*first line\nsecond line*"
  210. (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))))
  211. '("first line\nsecond line"))))
  212. ;;;; Center Block
  213. (ert-deftest test-org-element/center-block-parser ()
  214. "Test `center-block' parser."
  215. ;; Standard test.
  216. (should
  217. (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
  218. (org-element-map (org-element-parse-buffer) 'center-block 'identity)))
  219. ;; Ignore case.
  220. (should
  221. (org-test-with-temp-text "#+begin_center\nText\n#+end_center"
  222. (org-element-map (org-element-parse-buffer) 'center-block 'identity)))
  223. ;; Test folded block.
  224. (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
  225. (org-cycle)
  226. (should
  227. (org-element-property
  228. :hiddenp
  229. (org-element-map
  230. (org-element-parse-buffer) 'center-block 'identity nil t))))
  231. ;; Ignore incomplete block.
  232. (should-not
  233. (org-test-with-temp-text "#+BEGIN_CENTER"
  234. (org-element-map
  235. (org-element-parse-buffer) 'center-block 'identity nil t))))
  236. ;;;; Clock
  237. (ert-deftest test-org-element/clock-parser ()
  238. "Test `clock' parser."
  239. ;; Running clock.
  240. (let* ((org-clock-string "CLOCK:")
  241. (clock (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
  242. (org-element-map
  243. (org-element-parse-buffer) 'clock 'identity nil t))))
  244. (should (eq (org-element-property :status clock) 'running))
  245. (should (equal (org-element-property :value clock)
  246. "[2012-01-01 sun. 00:01]"))
  247. (should-not (org-element-property :time clock)))
  248. ;; Closed clock.
  249. (let* ((org-clock-string "CLOCK:")
  250. (clock (org-test-with-temp-text "
  251. CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
  252. (org-element-map
  253. (org-element-parse-buffer) 'clock 'identity nil t))))
  254. (should (eq (org-element-property :status clock) 'closed))
  255. (should (equal (org-element-property :value clock)
  256. "[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"))
  257. (should (equal (org-element-property :time clock) "0:01"))))
  258. ;;;; Code
  259. (ert-deftest test-org-element/code-parser ()
  260. "Test `code' parser."
  261. ;; Regular test.
  262. (should
  263. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  264. (org-test-with-temp-text "~code~"
  265. (org-element-map (org-element-parse-buffer) 'code 'identity))))
  266. ;; Multi-line markup.
  267. (should
  268. (equal
  269. (org-element-property
  270. :value
  271. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  272. (org-test-with-temp-text "~first line\nsecond line~"
  273. (org-element-map
  274. (org-element-parse-buffer) 'code 'identity nil t))))
  275. "first line\nsecond line")))
  276. ;;;; Comment
  277. (ert-deftest test-org-element/comment-parser ()
  278. "Test `comment' parser."
  279. ;; Regular comment.
  280. (should
  281. (org-test-with-temp-text "# Comment"
  282. (org-element-map (org-element-parse-buffer) 'comment 'identity)))
  283. ;; Inline comment.
  284. (should
  285. (org-test-with-temp-text " # Comment"
  286. (org-element-map (org-element-parse-buffer) 'comment 'identity)))
  287. ;; Preserve indentation.
  288. (should
  289. (equal
  290. (org-element-property
  291. :value
  292. (org-test-with-temp-text "# No blank\n# One blank"
  293. (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
  294. "No blank\n One blank"))
  295. ;; Comment with blank lines.
  296. (should
  297. (equal
  298. (org-element-property
  299. :value
  300. (org-test-with-temp-text "# First part\n# \n#\n# Second part"
  301. (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
  302. "First part\n\n\nSecond part"))
  303. ;; Do not mix comments and keywords.
  304. (should
  305. (eq 1
  306. (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
  307. (length (org-element-map
  308. (org-element-parse-buffer) 'comment 'identity)))))
  309. (should
  310. (equal "comment"
  311. (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
  312. (org-element-property
  313. :value
  314. (org-element-map
  315. (org-element-parse-buffer) 'comment 'identity nil t))))))
  316. ;;;; Comment Block
  317. (ert-deftest test-org-element/comment-block-parser ()
  318. "Test `comment-block' parser."
  319. ;; Standard test.
  320. (should
  321. (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
  322. (org-element-map
  323. (org-element-parse-buffer) 'comment-block 'identity)))
  324. ;; Ignore case.
  325. (should
  326. (org-test-with-temp-text "#+begin_comment\nText\n#+end_comment"
  327. (org-element-map
  328. (org-element-parse-buffer) 'comment-block 'identity)))
  329. ;; Test folded block.
  330. (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
  331. (org-cycle)
  332. (should
  333. (org-element-property
  334. :hiddenp
  335. (org-element-map
  336. (org-element-parse-buffer) 'comment-block 'identity nil t))))
  337. ;; Ignore incomplete block.
  338. (should-not
  339. (org-test-with-temp-text "#+BEGIN_COMMENT"
  340. (org-element-map
  341. (org-element-parse-buffer) 'comment-block 'identity nil t))))
  342. ;;;; Drawer
  343. (ert-deftest test-org-element/drawer-parser ()
  344. "Test `drawer' parser."
  345. ;; Standard test.
  346. (should
  347. (let ((org-drawers '("TEST")))
  348. (org-test-with-temp-text ":TEST:\nText\n:END:"
  349. (org-element-map (org-element-parse-buffer) 'drawer 'identity))))
  350. ;; Do not mix regular drawers and property drawers.
  351. (should-not
  352. (let ((org-drawers '("PROPERTIES")))
  353. (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
  354. (org-element-map
  355. (org-element-parse-buffer) 'drawer 'identity nil t))))
  356. ;; Ignore incomplete drawer.
  357. (should-not
  358. (let ((org-drawers '("TEST")))
  359. (org-test-with-temp-text ":TEST:"
  360. (org-element-map
  361. (org-element-parse-buffer) 'drawer 'identity nil t)))))
  362. ;;;; Dynamic Block
  363. (ert-deftest test-org-element/dynamic-block-parser ()
  364. "Test `dynamic-block' parser."
  365. ;; Standard test.
  366. (should
  367. (org-test-with-temp-text
  368. "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
  369. (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
  370. ;; Folded view
  371. (org-test-with-temp-text
  372. "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
  373. (org-cycle)
  374. (should
  375. (org-element-property
  376. :hiddenp
  377. (org-element-map
  378. (org-element-parse-buffer) 'dynamic-block 'identity nil t))))
  379. ;; Ignore case.
  380. (should
  381. (org-test-with-temp-text
  382. "#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
  383. (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
  384. ;; Ignore incomplete block.
  385. (should-not
  386. (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
  387. (org-element-map
  388. (org-element-parse-buffer) 'dynamic-block 'identity nil t))))
  389. ;;;; Entity
  390. (ert-deftest test-org-element/entity-parser ()
  391. "Test `entity' parser."
  392. ;; Without brackets.
  393. (should
  394. (org-test-with-temp-text "\\sin"
  395. (org-element-map (org-element-parse-buffer) 'entity 'identity)))
  396. ;; With brackets.
  397. (should
  398. (org-element-property
  399. :use-brackets-p
  400. (org-test-with-temp-text "\\alpha{}text"
  401. (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
  402. ;; User-defined entity.
  403. (should
  404. (equal
  405. (org-element-property
  406. :name
  407. (let ((org-entities-user
  408. '(("test" "test" nil "test" "test" "test" "test"))))
  409. (org-test-with-temp-text "\\test"
  410. (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
  411. "test")))
  412. ;;;; Example Block
  413. (ert-deftest test-org-element/example-block-parser ()
  414. "Test `example-block' parser."
  415. ;; Standard test.
  416. (should
  417. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
  418. (org-element-map (org-element-parse-buffer) 'example-block 'identity)))
  419. ;; Test folded block.
  420. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
  421. (org-cycle)
  422. (should
  423. (org-element-property
  424. :hiddenp
  425. (org-element-map
  426. (org-element-parse-buffer) 'example-block 'identity nil t))))
  427. ;; Ignore incomplete block.
  428. (should-not
  429. (org-test-with-temp-text "#+BEGIN_EXAMPLE"
  430. (org-element-map
  431. (org-element-parse-buffer) 'example-block 'identity nil t)))
  432. ;; Properly un-escape code.
  433. (should
  434. (equal "* Headline\n #+keyword\nText\n"
  435. (org-test-with-temp-text
  436. "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
  437. (org-element-property :value (org-element-at-point))))))
  438. (ert-deftest test-org-element/block-switches ()
  439. "Test `example-block' and `src-block' switches parsing."
  440. (let ((org-coderef-label-format "(ref:%s)"))
  441. ;; 1. Test "-i" switch.
  442. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  443. (should-not
  444. (org-element-property :preserve-indent (org-element-at-point))))
  445. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  446. (should (org-element-property :preserve-indent (org-element-at-point))))
  447. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
  448. (should-not
  449. (org-element-property :preserve-indent (org-element-at-point))))
  450. (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
  451. (should (org-element-property :preserve-indent (org-element-at-point))))
  452. ;; 2. "-n -r -k" combination should number lines, retain labels but
  453. ;; not use them in coderefs.
  454. (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
  455. (let ((element (org-element-at-point)))
  456. (should (and (org-element-property :number-lines element)
  457. (org-element-property :retain-labels element)
  458. (not (org-element-property :use-labels element))))))
  459. (org-test-with-temp-text
  460. "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
  461. (let ((element (org-element-at-point)))
  462. (should (and (org-element-property :number-lines element)
  463. (org-element-property :retain-labels element)
  464. (not (org-element-property :use-labels element))))))
  465. ;; 3. "-n -r" combination should number-lines remove labels and not
  466. ;; use them in coderefs.
  467. (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
  468. (let ((element (org-element-at-point)))
  469. (should (and (org-element-property :number-lines element)
  470. (not (org-element-property :retain-labels element))
  471. (not (org-element-property :use-labels element))))))
  472. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
  473. (let ((element (org-element-at-point)))
  474. (should (and (org-element-property :number-lines element)
  475. (not (org-element-property :retain-labels element))
  476. (not (org-element-property :use-labels element))))))
  477. ;; 4. "-n" or "+n" should number lines, retain labels and use them
  478. ;; in coderefs.
  479. (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
  480. (let ((element (org-element-at-point)))
  481. (should (and (org-element-property :number-lines element)
  482. (org-element-property :retain-labels element)
  483. (org-element-property :use-labels element)))))
  484. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
  485. (let ((element (org-element-at-point)))
  486. (should (and (org-element-property :number-lines element)
  487. (org-element-property :retain-labels element)
  488. (org-element-property :use-labels element)))))
  489. (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
  490. (let ((element (org-element-at-point)))
  491. (should (and (org-element-property :number-lines element)
  492. (org-element-property :retain-labels element)
  493. (org-element-property :use-labels element)))))
  494. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
  495. (let ((element (org-element-at-point)))
  496. (should (and (org-element-property :number-lines element)
  497. (org-element-property :retain-labels element)
  498. (org-element-property :use-labels element)))))
  499. ;; 5. No switch should not number lines, but retain labels and use
  500. ;; them in coderefs.
  501. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
  502. (let ((element (org-element-at-point)))
  503. (should (and (not (org-element-property :number-lines element))
  504. (org-element-property :retain-labels element)
  505. (org-element-property :use-labels element)))))
  506. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  507. (let ((element (org-element-at-point)))
  508. (should (and (not (org-element-property :number-lines element))
  509. (org-element-property :retain-labels element)
  510. (org-element-property :use-labels element)))))
  511. ;; 6. "-r" switch only: do not number lines, remove labels, and
  512. ;; don't use labels in coderefs.
  513. (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
  514. (let ((element (org-element-at-point)))
  515. (should (and (not (org-element-property :number-lines element))
  516. (not (org-element-property :retain-labels element))
  517. (not (org-element-property :use-labels element))))))
  518. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
  519. (let ((element (org-element-at-point)))
  520. (should (and (not (org-element-property :number-lines element))
  521. (not (org-element-property :retain-labels element))
  522. (not (org-element-property :use-labels element))))))
  523. ;; 7. Recognize coderefs with user-defined syntax.
  524. (org-test-with-temp-text
  525. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
  526. (let ((element (org-element-at-point)))
  527. (should
  528. (equal (org-element-property :label-fmt element) "[ref:%s]"))))
  529. (org-test-with-temp-text
  530. "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
  531. (let ((element (org-element-at-point)))
  532. (should
  533. (equal (org-element-property :label-fmt element) "[ref:%s]"))))))
  534. ;;;; Export Block
  535. (ert-deftest test-org-element/export-block-parser ()
  536. "Test `export-block' parser."
  537. ;; Standard test.
  538. (should
  539. (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
  540. (org-element-map
  541. (let ((org-element-block-name-alist
  542. '(("LATEX" . org-element-export-block-parser))))
  543. (org-element-parse-buffer))
  544. 'export-block 'identity)))
  545. ;; Test folded block.
  546. (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
  547. (org-cycle)
  548. (should
  549. (org-element-property
  550. :hiddenp
  551. (org-element-map
  552. (let ((org-element-block-name-alist
  553. '(("LATEX" . org-element-export-block-parser))))
  554. (org-element-parse-buffer))
  555. 'export-block 'identity nil t))))
  556. ;; Ignore case.
  557. (should
  558. (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
  559. (org-element-map
  560. (let ((org-element-block-name-alist
  561. '(("LATEX" . org-element-export-block-parser))))
  562. (org-element-parse-buffer))
  563. 'export-block 'identity)))
  564. ;; Ignore incomplete block.
  565. (should-not
  566. (org-test-with-temp-text "#+BEGIN_LATEX"
  567. (org-element-map
  568. (let ((org-element-block-name-alist
  569. '(("LATEX" . org-element-export-block-parser))))
  570. (org-element-parse-buffer))
  571. 'export-block 'identity nil t))))
  572. ;;;; Export Snippet
  573. (ert-deftest test-org-element/export-snippet-parser ()
  574. "Test `export-snippet' parser."
  575. (should
  576. (equal
  577. '("back-end" . "contents")
  578. (org-test-with-temp-text "@@back-end:contents@@"
  579. (org-element-map
  580. (org-element-parse-buffer) 'export-snippet
  581. (lambda (snippet) (cons (org-element-property :back-end snippet)
  582. (org-element-property :value snippet)))
  583. nil t)))))
  584. ;;;; Fixed Width
  585. (ert-deftest test-org-element/fixed-width ()
  586. "Test fixed-width area parsing."
  587. ;; Preserve indentation.
  588. (should
  589. (org-test-with-temp-text ": no blank\n: one blank"
  590. (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
  591. ;; Fixed-width with empty lines.
  592. (should
  593. (org-test-with-temp-text ": first part\n:\n: \n: second part"
  594. (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
  595. ;; Parse indented fixed-width markers.
  596. (should
  597. (org-test-with-temp-text "Text\n : no blank\n : one blank"
  598. (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
  599. ;; Distinguish fixed-width areas within a list and outside of it.
  600. (should
  601. (= 2
  602. (length
  603. (org-test-with-temp-text "
  604. - Item
  605. : fixed-width inside
  606. : fixed-width outside"
  607. (org-element-map
  608. (org-element-parse-buffer) 'fixed-width 'identity))))))
  609. ;;;; Footnote Definition
  610. (ert-deftest test-org-element/footnote-definition-parser ()
  611. "Test `footnote-definition' parser."
  612. (should
  613. (org-test-with-temp-text "[fn:1] Definition"
  614. (org-element-map
  615. (org-element-parse-buffer) 'footnote-definition 'identity nil t)))
  616. ;; Footnote with more contents
  617. (should
  618. (= 28
  619. (org-element-property
  620. :end
  621. (org-test-with-temp-text "[fn:1] Definition\n| a | b |"
  622. (org-element-map
  623. (org-element-parse-buffer)
  624. 'footnote-definition 'identity nil t)))))
  625. ;; Footnote starting with special syntax.
  626. (should-not
  627. (org-test-with-temp-text "[fn:1] - no item"
  628. (org-element-map (org-element-parse-buffer) 'item 'identity))))
  629. ;;;; Footnotes Reference.
  630. (ert-deftest test-org-element/footnote-reference-parser ()
  631. "Test `footnote-reference' parser."
  632. ;; 1. Parse a standard reference.
  633. (org-test-with-temp-text "Text[fn:label]"
  634. (should
  635. (org-element-map
  636. (org-element-parse-buffer) 'footnote-reference 'identity)))
  637. ;; 2. Parse a normalized reference.
  638. (org-test-with-temp-text "Text[1]"
  639. (should
  640. (org-element-map
  641. (org-element-parse-buffer) 'footnote-reference 'identity)))
  642. ;; 3. Parse an inline reference.
  643. (org-test-with-temp-text "Text[fn:test:def]"
  644. (should
  645. (org-element-map
  646. (org-element-parse-buffer) 'footnote-reference 'identity)))
  647. ;; 4. Parse an anonymous reference.
  648. (org-test-with-temp-text "Text[fn::def]"
  649. (should
  650. (org-element-map
  651. (org-element-parse-buffer) 'footnote-reference 'identity)))
  652. ;; 5. Parse nested footnotes.
  653. (org-test-with-temp-text "Text[fn::def [fn:label]]"
  654. (should
  655. (= 2
  656. (length
  657. (org-element-map
  658. (org-element-parse-buffer) 'footnote-reference 'identity)))))
  659. ;; 6. Parse adjacent footnotes.
  660. (org-test-with-temp-text "Text[fn:label1][fn:label2]"
  661. (should
  662. (= 2
  663. (length
  664. (org-element-map
  665. (org-element-parse-buffer) 'footnote-reference 'identity)))))
  666. ;; 7. Only properly closed footnotes are recognized as such.
  667. (org-test-with-temp-text "Text[fn:label"
  668. (should-not
  669. (org-element-map
  670. (org-element-parse-buffer) 'footnote-reference 'identity))))
  671. ;;;; Headline
  672. (ert-deftest test-org-element/headline-quote-keyword ()
  673. "Test QUOTE keyword recognition."
  674. ;; Reference test.
  675. (org-test-with-temp-text "* Headline"
  676. (let ((org-quote-string "QUOTE"))
  677. (should-not (org-element-property :quotedp (org-element-at-point)))))
  678. ;; Standard position.
  679. (org-test-with-temp-text "* QUOTE Headline"
  680. (let* ((org-quote-string "QUOTE")
  681. (headline (org-element-at-point)))
  682. (should (org-element-property :quotedp headline))
  683. ;; Test removal from raw value.
  684. (should (equal (org-element-property :raw-value headline) "Headline"))))
  685. ;; Case sensitivity.
  686. (org-test-with-temp-text "* QUOTE Headline"
  687. (let* ((org-quote-string "Quote")
  688. (headline (org-element-at-point)))
  689. (should-not (org-element-property :quotedp headline))
  690. (should (equal (org-element-property :raw-value headline)
  691. "QUOTE Headline"))))
  692. ;; With another keyword.
  693. (org-test-with-temp-text "* TODO QUOTE Headline"
  694. (let* ((org-quote-string "QUOTE")
  695. (org-todo-keywords '((sequence "TODO" "DONE")))
  696. (headline (org-element-at-point)))
  697. (should (org-element-property :quotedp headline))
  698. (should (equal (org-element-property :raw-value headline) "Headline"))))
  699. ;; With the keyword only.
  700. (org-test-with-temp-text "* QUOTE"
  701. (let* ((org-quote-string "QUOTE")
  702. (headline (org-element-at-point)))
  703. (should (org-element-property :quotedp headline))
  704. (should (equal (org-element-property :raw-value headline) "")))))
  705. (ert-deftest test-org-element/headline-comment-keyword ()
  706. "Test COMMENT keyword recognition."
  707. ;; Reference test.
  708. (org-test-with-temp-text "* Headline"
  709. (let ((org-comment-string "COMMENT"))
  710. (should-not (org-element-property :commentedp (org-element-at-point)))))
  711. ;; Standard position.
  712. (org-test-with-temp-text "* COMMENT Headline"
  713. (let ((org-comment-string "COMMENT")
  714. (headline (org-element-at-point)))
  715. (should (org-element-property :commentedp headline))
  716. (should (equal (org-element-property :raw-value headline) "Headline"))))
  717. ;; Case sensitivity.
  718. (org-test-with-temp-text "* COMMENT Headline"
  719. (let* ((org-comment-string "Comment")
  720. (headline (org-element-at-point)))
  721. (should-not (org-element-property :commentedp headline))
  722. (should (equal (org-element-property :raw-value headline)
  723. "COMMENT Headline"))))
  724. ;; With another keyword.
  725. (org-test-with-temp-text "* TODO COMMENT Headline"
  726. (let* ((org-comment-string "COMMENT")
  727. (org-todo-keywords '((sequence "TODO" "DONE")))
  728. (headline (org-element-at-point)))
  729. (should (org-element-property :commentedp headline))
  730. (should (equal (org-element-property :raw-value headline) "Headline"))))
  731. ;; With the keyword only.
  732. (org-test-with-temp-text "* COMMENT"
  733. (let* ((org-comment-string "COMMENT")
  734. (headline (org-element-at-point)))
  735. (should (org-element-property :commentedp headline))
  736. (should (equal (org-element-property :raw-value headline) "")))))
  737. (ert-deftest test-org-element/headline-archive-tag ()
  738. "Test ARCHIVE tag recognition."
  739. ;; Reference test.
  740. (org-test-with-temp-text "* Headline"
  741. (let ((org-archive-tag "ARCHIVE"))
  742. (should-not (org-element-property :archivedp (org-element-at-point)))))
  743. ;; Single tag.
  744. (org-test-with-temp-text "* Headline :ARCHIVE:"
  745. (let ((org-archive-tag "ARCHIVE"))
  746. (let ((headline (org-element-at-point)))
  747. (should (org-element-property :archivedp headline))
  748. ;; Test tag removal.
  749. (should-not (org-element-property :tags headline))))
  750. (let ((org-archive-tag "Archive"))
  751. (should-not (org-element-property :archivedp (org-element-at-point)))))
  752. ;; Multiple tags.
  753. (org-test-with-temp-text "* Headline :test:ARCHIVE:"
  754. (let ((org-archive-tag "ARCHIVE"))
  755. (let ((headline (org-element-at-point)))
  756. (should (org-element-property :archivedp headline))
  757. ;; Test tag removal.
  758. (should (equal (org-element-property :tags headline) '("test")))))))
  759. ;;;; Horizontal Rule
  760. (ert-deftest test-org-element/horizontal-rule-parser ()
  761. "Test `horizontal-rule' parser."
  762. ;; Standard.
  763. (should
  764. (org-test-with-temp-text "-----"
  765. (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
  766. ;; Indented.
  767. (should
  768. (org-test-with-temp-text " -----"
  769. (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
  770. ;; Hyphen must be alone on the line.
  771. (should-not
  772. (org-test-with-temp-text "-----wrong"
  773. (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
  774. ;; 4 hyphens is too small.
  775. (should-not
  776. (org-test-with-temp-text "----"
  777. (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity))))
  778. ;;;; Inline Babel Call
  779. (ert-deftest test-org-element/inline-babel-call-parser ()
  780. "Test `inline-babel-call' parser."
  781. (should
  782. (org-test-with-temp-text "call_test()"
  783. (org-element-map
  784. (org-element-parse-buffer) 'inline-babel-call 'identity))))
  785. ;;;; Inline Src Block
  786. (ert-deftest test-org-element/inline-src-block-parser ()
  787. "Test `inline-src-block' parser."
  788. (should
  789. (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
  790. (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
  791. ;; Test parsing at the beginning of an item.
  792. (should
  793. (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
  794. (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))))
  795. ;;;; Inlinetask
  796. (ert-deftest test-org-element/inlinetask-parser ()
  797. "Test `inlinetask' parser."
  798. (when (featurep 'org-inlinetask)
  799. (let ((org-inlinetask-min-level 15))
  800. ;; 1. Regular inlinetask.
  801. (should
  802. (org-test-with-temp-text
  803. "*************** Task\nTest\n*************** END"
  804. (org-element-map (org-element-parse-buffer) 'inlinetask 'identity)))
  805. ;; 2. Degenerate inlinetask.
  806. (should
  807. (org-test-with-temp-text "*************** Task"
  808. (org-element-map (org-element-parse-buffer) 'inlinetask 'identity)))
  809. ;; TODO keyword.
  810. (should
  811. (equal
  812. "TODO"
  813. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  814. (org-test-with-temp-text "*************** TODO Task"
  815. (org-element-property
  816. :todo-keyword
  817. (org-element-map
  818. (org-element-parse-buffer) 'inlinetask 'identity nil t))))))
  819. ;; Planning info.
  820. (should
  821. (equal
  822. "2012-03-29 thu."
  823. (org-test-with-temp-text "
  824. *************** Task
  825. DEADLINE: <2012-03-29 thu.>"
  826. (org-element-property
  827. :deadline
  828. (org-element-map
  829. (org-element-parse-buffer) 'inlinetask 'identity nil t)))))
  830. ;; Priority.
  831. (should
  832. (equal
  833. ?A
  834. (org-test-with-temp-text "
  835. *************** [#A] Task"
  836. (org-element-property
  837. :priority
  838. (org-element-map
  839. (org-element-parse-buffer) 'inlinetask 'identity nil t)))))
  840. ;; Tags.
  841. (should
  842. (equal
  843. '("test")
  844. (org-test-with-temp-text "
  845. *************** Task :test:"
  846. (org-element-property
  847. :tags
  848. (org-element-map
  849. (org-element-parse-buffer) 'inlinetask 'identity nil t))))))))
  850. ;;;; Italic
  851. (ert-deftest test-org-element/italic-parser ()
  852. "Test `italic' parser."
  853. ;; Regular test.
  854. (should
  855. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  856. (org-test-with-temp-text "/italic/"
  857. (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
  858. ;; Multi-line markup.
  859. (should
  860. (equal
  861. (org-element-contents
  862. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  863. (org-test-with-temp-text "/first line\nsecond line/"
  864. (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
  865. '("first line\nsecond line"))))
  866. ;;;; Item
  867. (ert-deftest test-org-element/item-parser ()
  868. "Test `item' parser."
  869. ;; Standard test.
  870. (should
  871. (org-test-with-temp-text "- item"
  872. (org-element-map (org-element-parse-buffer) 'item 'identity)))
  873. ;; Counter.
  874. (should
  875. (= 6
  876. (org-element-property
  877. :counter
  878. (org-test-with-temp-text "6. [@6] item"
  879. (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
  880. ;; Tag
  881. (should
  882. (equal
  883. '("tag")
  884. (org-element-property
  885. :tag
  886. (org-test-with-temp-text "- tag :: description"
  887. (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
  888. ;; No tags in ordered lists.
  889. (should-not
  890. (org-element-property
  891. :tag
  892. (org-test-with-temp-text "1. tag :: description"
  893. (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
  894. ;; Check-boxes
  895. (should
  896. (equal
  897. '(trans on off)
  898. (org-test-with-temp-text "
  899. - [-] item 1
  900. - [X] item 1.1
  901. - [ ] item 1.2"
  902. (org-element-map
  903. (org-element-parse-buffer) 'item
  904. (lambda (item) (org-element-property :checkbox item))))))
  905. ;; Folded state.
  906. (org-test-with-temp-text "* Headline
  907. - item
  908. paragraph below"
  909. (forward-line)
  910. (let ((org-cycle-include-plain-lists t)) (org-cycle))
  911. (should
  912. (org-element-property
  913. :hiddenp
  914. (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
  915. ;; Item starting with special syntax.
  916. (should
  917. (equal '(("- item"))
  918. (org-test-with-temp-text "- - item"
  919. (org-element-map
  920. (org-element-parse-buffer) 'paragraph 'org-element-contents)))))
  921. ;;;; Keyword
  922. (ert-deftest test-org-element/keyword-parser ()
  923. "Test `keyword' parser."
  924. ;; Standard test.
  925. (should
  926. (org-test-with-temp-text "#+KEYWORD: value"
  927. (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
  928. ;; Keywords are case-insensitive.
  929. (should
  930. (org-test-with-temp-text "#+keyword: value"
  931. (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
  932. ;; Affiliated keywords are not keywords.
  933. (should-not
  934. (org-test-with-temp-text "#+NAME: value
  935. Paragraph"
  936. (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
  937. ;; Do not mix keywords with Babel calls and dynamic blocks.
  938. (should-not
  939. (org-test-with-temp-text "#+CALL: fun()"
  940. (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
  941. (should-not
  942. (org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
  943. (org-element-map (org-element-parse-buffer) 'keyword 'identity))))
  944. ;;;; Latex Environment
  945. (ert-deftest test-org-element/latex-environment-parser ()
  946. "Test `latex-environment' parser."
  947. (should
  948. (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
  949. (org-element-map
  950. (org-element-parse-buffer) 'latex-environment 'identity)))
  951. ;; Allow nested environments.
  952. (should
  953. (equal
  954. "\\begin{outer}
  955. \\begin{inner}
  956. e^{i\\pi}+1=0
  957. \\end{inner}
  958. \\end{outer}"
  959. (org-test-with-temp-text "
  960. \\begin{outer}
  961. \\begin{inner}
  962. e^{i\\pi}+1=0
  963. \\end{inner}
  964. \\end{outer}"
  965. (org-element-property
  966. :value
  967. (org-element-map
  968. (org-element-parse-buffer) 'latex-environment 'identity nil t))))))
  969. ;;;; Latex Fragment
  970. (ert-deftest test-org-element/latex-fragment-parser ()
  971. "Test `latex-fragment' parser."
  972. (let ((org-latex-regexps
  973. '(("begin" "^[ ]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^�]+?\\\\end{\\2}\\)" 1 t)
  974. ("$1" "\\([^$]\\|^\\)\\(\\$[^ \n,;.$]\\$\\)\\([- .,?;:'\")�]\\|$\\)" 2 nil)
  975. ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \n,;.$][^$\n ]*?\\(\n[^$\n ]*?\\)\\{0,2\\}[^ \n,.$]\\)\\$\\)\\)\\([- .,?;:'\")�]\\|$\\)" 2 nil)
  976. ("\\(" "\\\\([^�]*?\\\\)" 0 nil)
  977. ("\\[" "\\\\\\[[^�]*?\\\\\\]" 0 nil)
  978. ("$$" "\\$\\$[^�]*?\\$\\$" 0 nil))))
  979. (should
  980. (org-test-with-temp-text "$a$"
  981. (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
  982. (should
  983. (org-test-with-temp-text "$$a$$"
  984. (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
  985. (should
  986. (org-test-with-temp-text "\\(a\\)"
  987. (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
  988. (should
  989. (org-test-with-temp-text "\\[a\\]"
  990. (org-element-map
  991. (org-element-parse-buffer) 'latex-fragment 'identity)))))
  992. ;;;; Line Break
  993. (ert-deftest test-org-element/line-break-parser ()
  994. "Test `line-break' parser."
  995. ;; Regular test.
  996. (should
  997. (org-test-with-temp-text "Text \\\\"
  998. (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
  999. ;; Line break with trailing white spaces.
  1000. (should
  1001. (org-test-with-temp-text "Text \\\\ "
  1002. (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
  1003. ;; Three backslashes are too much.
  1004. (should-not
  1005. (org-test-with-temp-text "Text \\\\\\"
  1006. (org-element-map (org-element-parse-buffer) 'line-break 'identity))))
  1007. ;;;; Link
  1008. (ert-deftest test-org-element/link-parser ()
  1009. "Test `link' parser."
  1010. ;; 1. Radio target.
  1011. (should
  1012. (equal
  1013. "radio"
  1014. (org-test-with-temp-text "A radio link"
  1015. (org-element-property
  1016. :type
  1017. (org-element-map
  1018. (let ((org-target-link-regexp "radio")) (org-element-parse-buffer))
  1019. 'link 'identity nil t)))))
  1020. ;; 2. Standard link.
  1021. ;;
  1022. ;; 2.1. With description.
  1023. (should
  1024. (equal
  1025. '("Orgmode.org")
  1026. (org-test-with-temp-text "[[http://orgmode.org][Orgmode.org]]"
  1027. (org-element-contents
  1028. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1029. ;; 2.2. Without description.
  1030. (should
  1031. (equal
  1032. "http"
  1033. (org-test-with-temp-text "[[http://orgmode.org]]"
  1034. (org-element-property
  1035. :type
  1036. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1037. ;; 2.3. With expansion.
  1038. (should
  1039. (equal
  1040. "//orgmode.org/worg"
  1041. (org-test-with-temp-text "[[Org:worg]]"
  1042. (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/"))))
  1043. (org-element-property
  1044. :path
  1045. (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))))
  1046. ;; 2.4. With translation.
  1047. (should
  1048. (equal
  1049. "127.0.0.1"
  1050. (org-test-with-temp-text "[[http://orgmode.org]]"
  1051. (flet ((link-translate (type path) (cons type "127.0.0.1")))
  1052. (let ((org-link-translation-function 'link-translate))
  1053. (org-element-property
  1054. :path
  1055. (org-element-map
  1056. (org-element-parse-buffer) 'link 'identity nil t)))))))
  1057. ;; 2.5. Id link.
  1058. (should
  1059. (equal
  1060. "id"
  1061. (org-test-with-temp-text "[[id:aaaa]]"
  1062. (org-element-property
  1063. :type
  1064. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1065. ;; 2.6. Custom-id link.
  1066. (should
  1067. (equal
  1068. "custom-id"
  1069. (org-test-with-temp-text "[[#some-id]]"
  1070. (org-element-property
  1071. :type
  1072. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1073. ;; 2.7 Coderef link.
  1074. (should
  1075. (equal
  1076. "coderef"
  1077. (org-test-with-temp-text "[[(reference)]]"
  1078. (org-element-property
  1079. :type
  1080. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1081. ;; 2.8 Fuzzy link.
  1082. (should
  1083. (equal
  1084. "fuzzy"
  1085. (org-test-with-temp-text "[[target-or-title]]"
  1086. (org-element-property
  1087. :type
  1088. (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
  1089. ;; 2.9 File-type link with search option.
  1090. (should
  1091. (equal
  1092. '(("file" "projects.org" "*task title"))
  1093. (org-test-with-temp-text "[[file:projects.org::*task title]]"
  1094. (org-element-map
  1095. (org-element-parse-buffer) 'link
  1096. (lambda (l) (list (org-element-property :type l)
  1097. (org-element-property :path l)
  1098. (org-element-property :search-option l)))))))
  1099. ;; 2.10 File-type link with application.
  1100. (should
  1101. (equal
  1102. '(("file" "projects.org" "docview"))
  1103. (org-test-with-temp-text "[[docview:projects.org]]"
  1104. (org-element-map
  1105. (org-element-parse-buffer) 'link
  1106. (lambda (l) (list (org-element-property :type l)
  1107. (org-element-property :path l)
  1108. (org-element-property :application l)))))))
  1109. ;; 3. Plain link.
  1110. (should
  1111. (org-test-with-temp-text "A link: http://orgmode.org"
  1112. (org-element-map (org-element-parse-buffer) 'link 'identity)))
  1113. ;; 4. Angular link.
  1114. (should
  1115. (org-test-with-temp-text "A link: <http://orgmode.org>"
  1116. (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))
  1117. ;;;; Macro
  1118. (ert-deftest test-org-element/macro-parser ()
  1119. "Test `macro' parser."
  1120. ;; Without arguments.
  1121. (should
  1122. (org-test-with-temp-text "{{{macro}}}"
  1123. (org-element-map (org-element-parse-buffer) 'macro 'identity)))
  1124. ;; With arguments.
  1125. (should
  1126. (org-test-with-temp-text "{{{macro(arg1,arg2)}}}"
  1127. (org-element-map (org-element-parse-buffer) 'macro 'identity))))
  1128. ;;;; Node Property
  1129. (ert-deftest test-org-element/node-property ()
  1130. "Test `node-property' parser."
  1131. ;; Standard test.
  1132. (should
  1133. (equal '("abc" "value")
  1134. (org-test-with-temp-text ":PROPERTIES:\n:abc: value\n:END:"
  1135. (progn (forward-line)
  1136. (let ((element (org-element-at-point)))
  1137. (list (org-element-property :key element)
  1138. (org-element-property :value element)))))))
  1139. ;; Value should be trimmed.
  1140. (should
  1141. (equal "value"
  1142. (org-test-with-temp-text ":PROPERTIES:\n:abc: value \n:END:"
  1143. (progn (forward-line)
  1144. (let ((element (org-element-at-point)))
  1145. (org-element-property :value element))))))
  1146. ;; A node property requires to be wrapped within a property drawer.
  1147. (should-not
  1148. (eq 'node-property
  1149. (org-test-with-temp-text ":abc: value"
  1150. (org-element-type (org-element-at-point))))))
  1151. ;;;; Paragraph
  1152. (ert-deftest test-org-element/paragraph-parser ()
  1153. "Test `paragraph' parser."
  1154. ;; Standard test.
  1155. (should
  1156. (org-test-with-temp-text "Paragraph"
  1157. (org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t)))
  1158. ;; Property find end of a paragraph stuck to another element.
  1159. (should
  1160. (eq ?#
  1161. (org-test-with-temp-text "Paragraph\n# Comment"
  1162. (org-element-map
  1163. (org-element-parse-buffer) 'paragraph
  1164. (lambda (p) (char-after (org-element-property :end p)))
  1165. nil t))))
  1166. ;; Include ill-formed Keywords.
  1167. (should
  1168. (org-test-with-temp-text "#+wrong_keyword something"
  1169. (org-element-map (org-element-parse-buffer) 'paragraph 'identity)))
  1170. ;; Include incomplete-drawers.
  1171. (should
  1172. (let ((org-drawers '("TEST")))
  1173. (org-test-with-temp-text ":TEST:\nParagraph"
  1174. (let ((elem (org-element-at-point)))
  1175. (and (eq (org-element-type elem) 'paragraph)
  1176. (= (point-max) (org-element-property :end elem)))))))
  1177. ;; Include non-existent drawers.
  1178. (should
  1179. (let ((org-drawers '("TEST")))
  1180. (org-test-with-temp-text ":NONAME:"
  1181. (org-element-map (org-element-parse-buffer) 'paragraph 'identity))))
  1182. ;; Include incomplete blocks.
  1183. (should
  1184. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph"
  1185. (let ((elem (org-element-at-point)))
  1186. (and (eq (org-element-type elem) 'paragraph)
  1187. (= (point-max) (org-element-property :end elem))))))
  1188. ;; Include incomplete dynamic blocks.
  1189. (should
  1190. (org-test-with-temp-text "#+BEGIN: \nParagraph"
  1191. (let ((elem (org-element-at-point)))
  1192. (and (eq (org-element-type elem) 'paragraph)
  1193. (= (point-max) (org-element-property :end elem))))))
  1194. ;; Include incomplete latex environments.
  1195. (should
  1196. (org-test-with-temp-text "\begin{equation}\nParagraph"
  1197. (let ((elem (org-element-at-point)))
  1198. (and (eq (org-element-type elem) 'paragraph)
  1199. (= (point-max) (org-element-property :end elem))))))
  1200. ;; Do not steal affiliated keywords from container.
  1201. (should
  1202. (org-test-with-temp-text "#+ATTR_LATEX: test\n- item 1"
  1203. (let ((elem (progn (search-forward "item") (org-element-at-point))))
  1204. (and (eq (org-element-type elem) 'paragraph)
  1205. (not (org-element-property :attr_latex elem))
  1206. (/= (org-element-property :begin elem) 1))))))
  1207. ;;;; Plain List
  1208. (ert-deftest test-org-element/plain-list-parser ()
  1209. "Test `plain-list' parser."
  1210. (should
  1211. (org-test-with-temp-text "- item"
  1212. (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
  1213. ;; Blank lines after the list only belong to outer plain list.
  1214. (org-test-with-temp-text "
  1215. - outer
  1216. - inner
  1217. Outside list"
  1218. (let ((endings (org-element-map
  1219. (org-element-parse-buffer) 'plain-list
  1220. (lambda (pl) (org-element-property :end pl)))))
  1221. ;; Move to ending of outer list.
  1222. (goto-char (car endings))
  1223. (should (looking-at "Outside list"))
  1224. ;; Move to ending of inner list.
  1225. (goto-char (nth 1 endings))
  1226. (should (looking-at "^$")))))
  1227. ;;;; Planning
  1228. (ert-deftest test-org-element/planning-parser ()
  1229. "Test `planning' parser."
  1230. (should
  1231. (equal
  1232. (org-element-property
  1233. :closed
  1234. (org-test-with-temp-text "CLOSED: [2012-03-29 thu.]"
  1235. (org-element-map (org-element-parse-buffer) 'planning 'identity nil t)))
  1236. "2012-03-29 thu."))
  1237. (should
  1238. (equal
  1239. (org-element-property
  1240. :deadline
  1241. (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
  1242. (org-element-map (org-element-parse-buffer) 'planning 'identity nil t)))
  1243. "2012-03-29 thu."))
  1244. (should
  1245. (equal
  1246. (org-element-property
  1247. :scheduled
  1248. (org-test-with-temp-text "SCHEDULED: <2012-03-29 thu.>"
  1249. (org-element-map (org-element-parse-buffer) 'planning 'identity nil t)))
  1250. "2012-03-29 thu.")))
  1251. ;;;; Property Drawer
  1252. (ert-deftest test-org-element/property-drawer ()
  1253. "Test `property-drawer' parser."
  1254. ;; Standard test.
  1255. (should
  1256. (let ((org-drawers '("PROPERTIES")))
  1257. (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
  1258. (org-element-map
  1259. (org-element-parse-buffer) 'property-drawer 'identity nil t))))
  1260. ;; Do not mix property drawers and regular drawers.
  1261. (should-not
  1262. (let ((org-drawers '("TEST")))
  1263. (org-test-with-temp-text ":TEST:\n:prop: value\n:END:"
  1264. (org-element-map
  1265. (org-element-parse-buffer) 'property-drawer 'identity nil t))))
  1266. ;; Ignore incomplete drawer.
  1267. (should-not
  1268. (let ((org-drawers '("PROPERTIES")))
  1269. (org-test-with-temp-text ":PROPERTIES:\n:prop: value"
  1270. (org-element-map
  1271. (org-element-parse-buffer) 'property-drawer 'identity nil t)))))
  1272. ;;;; Quote Block
  1273. (ert-deftest test-org-element/quote-block-parser ()
  1274. "Test `quote-block' parser."
  1275. ;; Regular test.
  1276. (should
  1277. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  1278. (org-element-map (org-element-parse-buffer) 'quote-block 'identity)))
  1279. ;; Test folded block.
  1280. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  1281. (org-cycle)
  1282. (should
  1283. (org-element-property
  1284. :hiddenp
  1285. (org-element-map
  1286. (org-element-parse-buffer) 'quote-block 'identity nil t))))
  1287. ;; Ignore incomplete block.
  1288. (should-not
  1289. (org-test-with-temp-text "#+BEGIN_QUOTE"
  1290. (org-element-map
  1291. (org-element-parse-buffer) 'quote-block 'identity nil t))))
  1292. ;;;; Quote Section
  1293. (ert-deftest test-org-element/quote-section-parser ()
  1294. "Test `quote-section' parser."
  1295. (should
  1296. (let ((org-quote-string "QUOTE"))
  1297. (org-test-with-temp-text "* QUOTE Headline\nBody"
  1298. (org-element-map (org-element-parse-buffer) 'quote-section 'identity))))
  1299. (should-not
  1300. (let ((org-quote-string "TEST"))
  1301. (org-test-with-temp-text "* QUOTE Headline\nBody"
  1302. (org-element-map (org-element-parse-buffer) 'quote-section 'identity)))))
  1303. ;;;; Radio Target
  1304. (ert-deftest test-org-element/radio-target-parser ()
  1305. "Test `radio-target' parser."
  1306. ;; Standard test.
  1307. (should
  1308. (org-test-with-temp-text "<<<radio>>>"
  1309. (org-element-map (org-element-parse-buffer) 'radio-target 'identity)))
  1310. ;; Radio targets with objects.
  1311. (should
  1312. (org-test-with-temp-text "<<<radio \\alpha>>>"
  1313. (org-element-map (org-element-parse-buffer) 'radio-target 'identity))))
  1314. ;;;; Section
  1315. (ert-deftest test-org-element/section-parser ()
  1316. "Test `section' parser."
  1317. ;; Standard test.
  1318. (should
  1319. (org-test-with-temp-text "* Headline\nText"
  1320. (org-element-map (org-element-parse-buffer) 'section 'identity)))
  1321. ;; There's a section before the first headline.
  1322. (should
  1323. (org-test-with-temp-text "Text"
  1324. (org-element-map (org-element-parse-buffer) 'section 'identity)))
  1325. ;; A section cannot be empty.
  1326. (should-not
  1327. (org-test-with-temp-text "* Headline 1\n* Headline 2"
  1328. (org-element-map (org-element-parse-buffer) 'section 'identity)))
  1329. ;; A section doesn't contain sub-trees.
  1330. (should-not
  1331. (org-test-with-temp-text "* Head\nText\n** Sub-Head"
  1332. (org-element-map
  1333. (org-element-map (org-element-parse-buffer) 'section 'identity nil t)
  1334. 'headline 'identity))))
  1335. ;;;; Special Block
  1336. (ert-deftest test-org-element/special-block-parser ()
  1337. "Test `special-block' parser."
  1338. ;; Standard test.
  1339. (let ((special-block
  1340. (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
  1341. (org-element-map
  1342. (org-element-parse-buffer) 'special-block 'identity nil t))))
  1343. (should (equal (org-element-property :type special-block) "SPECIAL"))
  1344. (should (org-element-map special-block 'paragraph 'identity)))
  1345. ;; Test folded block.
  1346. (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
  1347. (org-cycle)
  1348. (should
  1349. (org-element-property
  1350. :hiddenp
  1351. (org-element-map
  1352. (org-element-parse-buffer) 'special-block 'identity nil t))))
  1353. ;; Ignore incomplete block.
  1354. (should-not
  1355. (org-test-with-temp-text "#+BEGIN_SPECIAL"
  1356. (org-element-map
  1357. (org-element-parse-buffer) 'special-block 'identity nil t))))
  1358. ;;;; Src Block
  1359. (ert-deftest test-org-element/src-block-parser ()
  1360. "Test `src-block' parser."
  1361. ;; Regular tests.
  1362. (should
  1363. (org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
  1364. (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
  1365. ;; Test folded block.
  1366. (org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
  1367. (org-cycle)
  1368. (should
  1369. (org-element-property
  1370. :hiddenp
  1371. (org-element-map
  1372. (org-element-parse-buffer) 'src-block 'identity nil t))))
  1373. ;; Ignore incomplete block.
  1374. (should-not
  1375. (org-test-with-temp-text "#+BEGIN_SRC"
  1376. (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
  1377. ;; Properly un-escape code.
  1378. (should
  1379. (equal "* Headline\n #+keyword\nText\n"
  1380. (org-test-with-temp-text
  1381. "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
  1382. (org-element-property :value (org-element-at-point))))))
  1383. ;;;; Statistics Cookie
  1384. (ert-deftest test-org-element/statistics-cookie ()
  1385. "Test `statistics-cookie' parser."
  1386. ;; With numbers.
  1387. (should
  1388. (org-test-with-temp-text "[1/2]"
  1389. (org-element-map (org-element-parse-buffer) 'statistics-cookie 'identity)))
  1390. ;; With percents.
  1391. (should
  1392. (org-test-with-temp-text "[33%]"
  1393. (org-element-map
  1394. (org-element-parse-buffer) 'statistics-cookie 'identity))))
  1395. ;;;; Strike Through
  1396. (ert-deftest test-org-element/strike-through-parser ()
  1397. "Test `strike-through' parser."
  1398. ;; Regular test.
  1399. (should
  1400. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1401. (org-test-with-temp-text "+strike-through+"
  1402. (org-element-map (org-element-parse-buffer) 'strike-through 'identity))))
  1403. ;; Multi-line markup.
  1404. (should
  1405. (equal
  1406. (org-element-contents
  1407. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1408. (org-test-with-temp-text "+first line\nsecond line+"
  1409. (org-element-map
  1410. (org-element-parse-buffer) 'strike-through 'identity nil t))))
  1411. '("first line\nsecond line"))))
  1412. ;;;; Subscript
  1413. (ert-deftest test-org-element/subscript-parser ()
  1414. "Test `subscript' parser."
  1415. ;; Without braces.
  1416. (should
  1417. (org-test-with-temp-text "a_b"
  1418. (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
  1419. ;; With braces.
  1420. (should
  1421. (org-test-with-temp-text "a_{b}"
  1422. (org-element-map (org-element-parse-buffer) 'subscript 'identity))))
  1423. ;;;; Superscript
  1424. (ert-deftest test-org-element/superscript-parser ()
  1425. "Test `superscript' parser."
  1426. ;; Without braces.
  1427. (should
  1428. (org-test-with-temp-text "a^b"
  1429. (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
  1430. ;; With braces.
  1431. (should
  1432. (org-test-with-temp-text "a^{b}"
  1433. (org-element-map (org-element-parse-buffer) 'superscript 'identity))))
  1434. ;;;; Table
  1435. (ert-deftest test-org-element/table-parser ()
  1436. "Test `table' parser."
  1437. (should
  1438. (org-test-with-temp-text "| a |"
  1439. (org-element-map (org-element-parse-buffer) 'table 'identity)))
  1440. ;; TBLFM keyword is case insensitive.
  1441. (should
  1442. (org-test-with-temp-text "| a |\n#+tblfm: test"
  1443. (org-element-property
  1444. :tblfm
  1445. (org-element-map (org-element-parse-buffer) 'table 'identity nil t))))
  1446. ;; Handle multiple TBLFM lines.
  1447. (should
  1448. (= 2
  1449. (org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
  1450. (length (org-element-property
  1451. :tblfm
  1452. (org-element-map
  1453. (org-element-parse-buffer) 'table 'identity nil t)))))))
  1454. ;;;; Table Cell
  1455. (ert-deftest test-org-element/table-cell-parser ()
  1456. "Test `table-cell' parser."
  1457. (should
  1458. (org-test-with-temp-text "| a |"
  1459. (org-element-map (org-element-parse-buffer) 'table-cell 'identity))))
  1460. ;;;; Table Row
  1461. (ert-deftest test-org-element/table-row-parser ()
  1462. "Test `table-row' parser."
  1463. (should
  1464. (equal '(standard rule)
  1465. (org-test-with-temp-text "| a |\n|---|"
  1466. (org-element-map
  1467. (org-element-parse-buffer) 'table-row
  1468. (lambda (row) (org-element-property :type row)))))))
  1469. ;;;; Target
  1470. (ert-deftest test-org-element/target-parser ()
  1471. "Test `target' parser."
  1472. (should
  1473. (org-test-with-temp-text "<<target>>"
  1474. (org-element-map (org-element-parse-buffer) 'target 'identity))))
  1475. ;;;; Timestamp
  1476. (ert-deftest test-org-element/timestamp ()
  1477. "Test `timestamp' parser."
  1478. ;; Active timestamp.
  1479. (should
  1480. (org-test-with-temp-text "<2012-03-29 16:40>"
  1481. (eq (org-element-property :type
  1482. (org-element-map
  1483. (org-element-parse-buffer)
  1484. 'timestamp 'identity nil t))
  1485. 'active)))
  1486. ;; Inactive timestamp.
  1487. (should
  1488. (org-test-with-temp-text "[2012-03-29 16:40]"
  1489. (eq (org-element-property :type
  1490. (org-element-map
  1491. (org-element-parse-buffer)
  1492. 'timestamp 'identity nil t))
  1493. 'inactive)))
  1494. ;; Date range.
  1495. (should
  1496. (org-test-with-temp-text "[2012-03-29 16:40]--[2012-03-29 16:41]"
  1497. (eq (org-element-property :type
  1498. (org-element-map
  1499. (org-element-parse-buffer)
  1500. 'timestamp 'identity nil t))
  1501. 'inactive-range)))
  1502. ;; Timestamps are not planning elements.
  1503. (should-not
  1504. (org-test-with-temp-text "SCHEDULED: <2012-03-29 16:40>"
  1505. (org-element-map (org-element-parse-buffer) 'timestamp 'identity))))
  1506. ;;;; Underline
  1507. (ert-deftest test-org-element/underline-parser ()
  1508. "Test `underline' parser."
  1509. ;; Regular test.
  1510. (should
  1511. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1512. (org-test-with-temp-text "_underline_"
  1513. (org-element-map (org-element-parse-buffer) 'underline 'identity))))
  1514. ;; Multi-line markup.
  1515. (should
  1516. (equal
  1517. (org-element-contents
  1518. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1519. (org-test-with-temp-text "_first line\nsecond line_"
  1520. (org-element-map
  1521. (org-element-parse-buffer) 'underline 'identity nil t))))
  1522. '("first line\nsecond line"))))
  1523. ;;;; Verbatim
  1524. (ert-deftest test-org-element/verbatim-parser ()
  1525. "Test `verbatim' parser."
  1526. ;; Regular test.
  1527. (should
  1528. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1529. (org-test-with-temp-text "=verbatim="
  1530. (org-element-map (org-element-parse-buffer) 'verbatim 'identity))))
  1531. ;; Multi-line markup.
  1532. (should
  1533. (equal
  1534. (org-element-property
  1535. :value
  1536. (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
  1537. (org-test-with-temp-text "=first line\nsecond line="
  1538. (org-element-map
  1539. (org-element-parse-buffer) 'verbatim 'identity nil t))))
  1540. "first line\nsecond line")))
  1541. ;;;; Verse Block
  1542. (ert-deftest test-org-element/verse-block-parser ()
  1543. "Test `verse-block' parser."
  1544. ;; Standard test.
  1545. (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
  1546. (should
  1547. (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
  1548. ;; Ignore case.
  1549. (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
  1550. (should
  1551. (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
  1552. ;; Parse folding.
  1553. (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
  1554. (org-hide-block-all)
  1555. (should
  1556. (org-element-property
  1557. :hiddenp
  1558. (org-element-map
  1559. (org-element-parse-buffer) 'verse-block 'identity nil t))))
  1560. ;; Parse objects in verse blocks.
  1561. (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
  1562. (should (org-element-map (org-element-parse-buffer) 'entity 'identity)))
  1563. ;; Ignore incomplete verse block.
  1564. (should-not
  1565. (org-test-with-temp-text "#+BEGIN_VERSE"
  1566. (org-element-map
  1567. (org-element-parse-buffer) 'verse-block 'identity nil t))))
  1568. ;;; Test Interpreters.
  1569. (ert-deftest test-org-element/affiliated-keywords-interpreter ()
  1570. "Test if affiliated keywords are correctly interpreted."
  1571. ;; Interpret simple keywords.
  1572. (should
  1573. (equal
  1574. (org-element-interpret-data
  1575. '(org-data nil (paragraph (:name "para") "Paragraph")))
  1576. "#+NAME: para\nParagraph\n"))
  1577. ;; Interpret multiple keywords.
  1578. (should
  1579. (equal
  1580. (org-element-interpret-data
  1581. '(org-data nil (paragraph (:attr_ascii ("line2" "line1")) "Paragraph")))
  1582. "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
  1583. ;; Interpret parsed keywords.
  1584. (should
  1585. (equal
  1586. (org-element-interpret-data
  1587. '(org-data nil (paragraph (:caption (("caption"))) "Paragraph")))
  1588. "#+CAPTION: caption\nParagraph\n"))
  1589. ;; Interpret dual keywords.
  1590. (should
  1591. (equal
  1592. (org-element-interpret-data
  1593. '(org-data nil (paragraph (:caption ((("long") "short"))) "Paragraph")))
  1594. "#+CAPTION[short]: long\nParagraph\n"))
  1595. ;; Interpret multiple parsed dual keywords.
  1596. (should
  1597. (equal
  1598. (org-element-interpret-data
  1599. '(org-data nil (paragraph
  1600. (:caption ((("l2") "s2") (("l1") "s1"))) "Paragraph")))
  1601. "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph\n")))
  1602. (ert-deftest test-org-element/center-block-interpreter ()
  1603. "Test center block interpreter."
  1604. (should
  1605. (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
  1606. "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
  1607. (ert-deftest test-org-element/drawer-interpreter ()
  1608. "Test drawer interpreter."
  1609. (should
  1610. (equal (let ((org-drawers '("TEST")))
  1611. (org-test-parse-and-interpret ":TEST:\nTest\n:END:"))
  1612. ":TEST:\nTest\n:END:\n")))
  1613. (ert-deftest test-org-element/dynamic-block-interpreter ()
  1614. "Test dynamic block interpreter."
  1615. (should
  1616. (equal (org-test-parse-and-interpret
  1617. "#+BEGIN: myblock :parameter value1\nTest\n#+END:")
  1618. "#+BEGIN: myblock :parameter value1\nTest\n#+END:\n")))
  1619. (ert-deftest test-org-element/footnote-definition-interpreter ()
  1620. "Test footnote definition interpreter."
  1621. (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")))
  1622. (ert-deftest test-org-element/headline-interpreter ()
  1623. "Test headline and section interpreters."
  1624. ;; 1. Standard test.
  1625. (should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
  1626. ;; 2. With TODO keywords.
  1627. (should
  1628. (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  1629. (org-test-parse-and-interpret "* TODO Headline"))
  1630. "* TODO Headline\n"))
  1631. ;; 3. With tags...
  1632. ;;
  1633. ;; 3.1. ... and a positive `org-tags-column' value.
  1634. (should
  1635. (equal (let ((org-tags-column 20))
  1636. (org-test-parse-and-interpret "* Headline :tag:"))
  1637. "* Headline :tag:\n"))
  1638. ;; 3.2. ... and a negative `org-tags-column' value.
  1639. (should
  1640. (equal (let ((org-tags-column -20))
  1641. (org-test-parse-and-interpret "* Headline :tag:"))
  1642. "* Headline :tag:\n"))
  1643. ;; 3.3. ... and a null `org-tags-column' value.
  1644. (should
  1645. (equal (let ((org-tags-column 0))
  1646. (org-test-parse-and-interpret "* Headline :tag:"))
  1647. "* Headline :tag:\n"))
  1648. ;; 4. With priority cookie.
  1649. (should
  1650. (equal (org-test-parse-and-interpret "* [#B] Headline")
  1651. "* [#B] Headline\n"))
  1652. ;; 5. With comment keyword.
  1653. (should
  1654. (equal (let ((org-comment-string "COMMENT"))
  1655. (org-test-parse-and-interpret "* COMMENT Headline"))
  1656. "* COMMENT Headline\n"))
  1657. ;; 6. With quote section.
  1658. (should
  1659. (equal (let ((org-quote-string "QUOTE"))
  1660. (org-test-parse-and-interpret "* QUOTE Headline"))
  1661. "* QUOTE Headline\n"))
  1662. ;; 7. Keep same number of blank lines before body.
  1663. (should
  1664. (equal (org-test-parse-and-interpret
  1665. "* Headline\n\n\nText after two blank lines.")
  1666. "* Headline\n\n\nText after two blank lines.\n")))
  1667. (ert-deftest test-org-element/inlinetask-interpreter ()
  1668. "Test inlinetask interpretation."
  1669. (when (featurep 'org-inlinetask)
  1670. (let ((org-inlinetask-min-level 15))
  1671. ;; 1. Regular inlinetask.
  1672. (should (equal (org-test-parse-and-interpret
  1673. "*************** Task\nTest\n*************** END")
  1674. "*************** Task\nTest\n*************** END\n"))
  1675. ;; 2. Degenerate inlinetask.
  1676. (should (equal (org-test-parse-and-interpret "*************** Task")
  1677. "*************** Task\n"))
  1678. ;; 3. Prefer degenerate form when there are no contents.
  1679. (should (equal (org-test-parse-and-interpret
  1680. "*************** Task\n*************** END")
  1681. "*************** Task\n"))
  1682. ;; 4. With TODO keywords.
  1683. (should
  1684. (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  1685. (org-test-parse-and-interpret "*************** TODO Task"))
  1686. "*************** TODO Task\n"))
  1687. ;; 5. With tags...
  1688. ;;
  1689. ;; 5.1. ... and a positive `org-tags-column' value.
  1690. (should
  1691. (equal (let ((org-tags-column 30))
  1692. (org-test-parse-and-interpret "*************** Task :tag:"))
  1693. "*************** Task :tag:\n"))
  1694. ;; 5.2. ... and a negative `org-tags-column' value.
  1695. (should
  1696. (equal (let ((org-tags-column -30))
  1697. (org-test-parse-and-interpret "*************** Task :tag:"))
  1698. "*************** Task :tag:\n"))
  1699. ;; 5.3. ... and a null `org-tags-column' value.
  1700. (should
  1701. (equal (let ((org-tags-column 0))
  1702. (org-test-parse-and-interpret "*************** Task :tag:"))
  1703. "*************** Task :tag:\n"))
  1704. ;; 6. With priority cookie.
  1705. (should
  1706. (equal (org-test-parse-and-interpret "*************** [#B] Task")
  1707. "*************** [#B] Task\n")))))
  1708. (ert-deftest test-org-element/plain-list-interpreter ()
  1709. "Test plain-list and item interpreters."
  1710. (let ((org-list-two-spaces-after-bullet-regexp nil))
  1711. ;; 1. Unordered list.
  1712. (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
  1713. ;; 2. Description list.
  1714. (should
  1715. (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
  1716. ;; 3. Ordered list.
  1717. (should
  1718. (equal (let ((org-plain-list-ordered-item-terminator t))
  1719. (org-test-parse-and-interpret "1. Item"))
  1720. "1. Item\n"))
  1721. ;; 4. Ordered list with counter.
  1722. (should
  1723. (equal (let ((org-plain-list-ordered-item-terminator t))
  1724. (org-test-parse-and-interpret "1. [@5] Item"))
  1725. "5. [@5] Item\n"))
  1726. ;; 5. List with check-boxes.
  1727. (should
  1728. (equal (org-test-parse-and-interpret
  1729. "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
  1730. "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
  1731. ;; 6. Item not starting with a paragraph.
  1732. (should
  1733. (equal (org-test-parse-and-interpret "-\n | a | b |")
  1734. "- \n | a | b |\n"))))
  1735. (ert-deftest test-org-element/quote-block-interpreter ()
  1736. "Test quote block interpreter."
  1737. (should (equal (org-test-parse-and-interpret
  1738. "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
  1739. "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
  1740. (ert-deftest test-org-element/special-block-interpreter ()
  1741. "Test special block interpreter."
  1742. (should (equal (org-test-parse-and-interpret
  1743. "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
  1744. "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
  1745. (ert-deftest test-org-element/babel-call-interpreter ()
  1746. "Test babel call interpreter."
  1747. ;; 1. Without argument.
  1748. (should (equal (org-test-parse-and-interpret "#+CALL: test()")
  1749. "#+CALL: test()\n"))
  1750. ;; 2. With argument.
  1751. (should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
  1752. "#+CALL: test(x=2)\n"))
  1753. ;; 3. With header arguments.
  1754. (should (equal (org-test-parse-and-interpret
  1755. "#+CALL: test[:results output]()[:results html]")
  1756. "#+CALL: test[:results output]()[:results html]\n")))
  1757. (ert-deftest test-org-element/clock-interpreter ()
  1758. "Test clock interpreter."
  1759. ;; Running clock.
  1760. (should
  1761. (equal (let ((org-clock-string "CLOCK:"))
  1762. (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]"))
  1763. "CLOCK: [2012-01-01 sun. 00:01]\n"))
  1764. ;; Closed clock.
  1765. (should
  1766. (equal
  1767. (let ((org-clock-string "CLOCK:"))
  1768. (org-test-parse-and-interpret "
  1769. CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))
  1770. "CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01\n")))
  1771. (ert-deftest test-org-element/comment-interpreter ()
  1772. "Test comment interpreter."
  1773. ;; Regular comment.
  1774. (should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
  1775. ;; Inline comment.
  1776. (should (equal (org-test-parse-and-interpret " # Comment")
  1777. "# Comment\n"))
  1778. ;; Preserve indentation.
  1779. (should (equal (org-test-parse-and-interpret " # No blank\n# One blank")
  1780. "# No blank\n# One blank\n")))
  1781. (ert-deftest test-org-element/comment-block-interpreter ()
  1782. "Test comment block interpreter."
  1783. (should (equal (org-test-parse-and-interpret
  1784. "#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
  1785. "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n")))
  1786. (ert-deftest test-org-element/example-block-interpreter ()
  1787. "Test example block interpreter."
  1788. ;; Without switches.
  1789. (should (equal (org-test-parse-and-interpret
  1790. "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE")
  1791. "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"))
  1792. ;; With switches.
  1793. (should
  1794. (equal (org-test-parse-and-interpret
  1795. "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
  1796. "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n"))
  1797. ;; Preserve code escaping.
  1798. (should
  1799. (equal (org-test-parse-and-interpret
  1800. "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE")
  1801. "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE\n")))
  1802. (ert-deftest test-org-element/export-block-interpreter ()
  1803. "Test export block interpreter."
  1804. (should (equal (org-test-parse-and-interpret
  1805. "#+BEGIN_HTML\nTest\n#+END_HTML")
  1806. "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
  1807. (ert-deftest test-org-element/fixed-width-interpreter ()
  1808. "Test fixed width interpreter."
  1809. ;; Standard test.
  1810. (should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
  1811. ;; Preserve indentation.
  1812. (should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
  1813. ": 2 blanks\n: 1 blank\n")))
  1814. (ert-deftest test-org-element/horizontal-rule-interpreter ()
  1815. "Test horizontal rule interpreter."
  1816. (should (equal (org-test-parse-and-interpret "-------") "-----\n")))
  1817. (ert-deftest test-org-element/keyword-interpreter ()
  1818. "Test keyword interpreter."
  1819. (should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
  1820. "#+KEYWORD: value\n")))
  1821. (ert-deftest test-org-element/latex-environment-interpreter ()
  1822. "Test latex environment interpreter."
  1823. (should (equal (org-test-parse-and-interpret
  1824. "\\begin{equation}\n1+1=2\n\\end{equation}")
  1825. "\\begin{equation}\n1+1=2\n\\end{equation}\n")))
  1826. (ert-deftest test-org-element/planning-interpreter ()
  1827. "Test planning interpreter."
  1828. (let ((org-closed-string "CLOSED:")
  1829. (org-deadline-string "DEADLINE:")
  1830. (org-scheduled-string "SCHEDULED:"))
  1831. (should
  1832. (equal
  1833. (org-test-parse-and-interpret
  1834. "* Headline
  1835. CLOSED: [2012-01-01] DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>")
  1836. "* Headline
  1837. CLOSED: [2012-01-01] DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n"))))
  1838. (ert-deftest test-org-element/property-drawer-interpreter ()
  1839. "Test property drawer interpreter."
  1840. (should (equal (let ((org-property-format "%-10s %s"))
  1841. (org-test-parse-and-interpret
  1842. ":PROPERTIES:\n:prop: value\n:END:"))
  1843. ":PROPERTIES:\n:prop: value\n:END:\n")))
  1844. (ert-deftest test-org-element/src-block-interpreter ()
  1845. "Test src block interpreter."
  1846. ;; With arguments.
  1847. (should
  1848. (equal (let ((org-edit-src-content-indentation 2))
  1849. (org-test-parse-and-interpret
  1850. "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC"))
  1851. "#+BEGIN_SRC emacs-lisp :results silent\n (+ 1 1)\n#+END_SRC\n"))
  1852. ;; With switches.
  1853. (should
  1854. (equal (let ((org-edit-src-content-indentation 2))
  1855. (org-test-parse-and-interpret
  1856. "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC"))
  1857. "#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
  1858. ;; Preserve code escaping.
  1859. (should
  1860. (equal (org-test-parse-and-interpret
  1861. "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC")
  1862. "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n")))
  1863. (ert-deftest test-org-element/table-interpreter ()
  1864. "Test table, table-row and table-cell interpreters."
  1865. ;; 1. Simple table.
  1866. (should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
  1867. "| a | b |\n| c | d |\n"))
  1868. ;; 2. With horizontal rules.
  1869. (should (equal (org-test-parse-and-interpret
  1870. "| a | b |\n|---+---|\n| c | d |")
  1871. "| a | b |\n|---+---|\n| c | d |\n"))
  1872. ;; 3. With meta-data.
  1873. (should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
  1874. "| / | < | > |\n| * | 1 | 2 |\n"))
  1875. ;; 4. With a formula.
  1876. (should
  1877. (equal (org-test-parse-and-interpret
  1878. "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)")
  1879. "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)\n"))
  1880. ;; 5. With multiple formulas.
  1881. (should
  1882. (equal (org-test-parse-and-interpret
  1883. "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2")
  1884. "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n")))
  1885. (ert-deftest test-org-element/timestamp-interpreter ()
  1886. "Test timestamp interpreter."
  1887. ;; Active.
  1888. (should (equal (org-test-parse-and-interpret "<2012-03-29 16:40>")
  1889. "<2012-03-29 16:40>\n"))
  1890. ;; Inactive.
  1891. (should (equal (org-test-parse-and-interpret "[2012-03-29 16:40]")
  1892. "[2012-03-29 16:40]\n"))
  1893. ;; Active range.
  1894. (should (equal (org-test-parse-and-interpret
  1895. "<2012-03-29 16:40>--<2012-03-29 16:41>")
  1896. "<2012-03-29 16:40>--<2012-03-29 16:41>\n"))
  1897. ;; Inactive range.
  1898. (should (equal (org-test-parse-and-interpret
  1899. "[2012-03-29 16:40]--[2012-03-29 16:41]")
  1900. "[2012-03-29 16:40]--[2012-03-29 16:41]\n"))
  1901. ;; Diary.
  1902. (should (equal (org-test-parse-and-interpret "<%%org-float t 4 2>")
  1903. "<%%org-float t 4 2>\n"))
  1904. ;; Timestamp with repeater interval.
  1905. (should (equal (org-test-parse-and-interpret "<2012-03-29 +1y>")
  1906. "<2012-03-29 +1y>\n")))
  1907. (ert-deftest test-org-element/verse-block-interpreter ()
  1908. "Test verse block interpretation."
  1909. (should
  1910. (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
  1911. "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
  1912. (ert-deftest test-org-element/bold-interpreter ()
  1913. "Test bold interpreter."
  1914. (should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
  1915. (ert-deftest test-org-element/code-interpreter ()
  1916. "Test code interpreter."
  1917. (should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
  1918. (ert-deftest test-org-element/entity-interpreter ()
  1919. "Test entity interpreter."
  1920. ;; 1. Without brackets.
  1921. (should
  1922. (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
  1923. ;; 2. With brackets.
  1924. (should
  1925. (equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
  1926. (ert-deftest test-org-element/export-snippet-interpreter ()
  1927. "Test export snippet interpreter."
  1928. (should (equal (org-test-parse-and-interpret "@@back-end:contents@@")
  1929. "@@back-end:contents@@\n")))
  1930. (ert-deftest test-org-element/footnote-reference-interpreter ()
  1931. "Test footnote reference interpreter."
  1932. ;; 1. Regular reference.
  1933. (should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
  1934. ;; 2. Normalized reference.
  1935. (should (equal (org-test-parse-and-interpret "Text[1]") "Text[1]\n"))
  1936. ;; 3. Named reference.
  1937. (should (equal (org-test-parse-and-interpret "Text[fn:label]")
  1938. "Text[fn:label]\n"))
  1939. ;; 4. Inline reference.
  1940. (should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
  1941. "Text[fn:label:def]\n"))
  1942. ;; 5. Anonymous reference.
  1943. (should (equal (org-test-parse-and-interpret "Text[fn::def]")
  1944. "Text[fn::def]\n")))
  1945. (ert-deftest test-org-element/inline-babel-call-interpreter ()
  1946. "Test inline babel call interpreter."
  1947. ;; 1. Without arguments.
  1948. (should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
  1949. ;; 2. With arguments.
  1950. (should (equal (org-test-parse-and-interpret "call_test(x=2)")
  1951. "call_test(x=2)\n"))
  1952. ;; 3. With header arguments.
  1953. (should (equal (org-test-parse-and-interpret
  1954. "call_test[:results output]()[:results html]")
  1955. "call_test[:results output]()[:results html]\n")))
  1956. (ert-deftest test-org-element/inline-src-block-interpreter ()
  1957. "Test inline src block interpreter."
  1958. ;; 1. Without header argument.
  1959. (should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
  1960. "src_emacs-lisp{(+ 1 1)}\n"))
  1961. ;; 2. With header arguments.
  1962. (should (equal (org-test-parse-and-interpret
  1963. "src_emacs-lisp[:results silent]{(+ 1 1)}")
  1964. "src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
  1965. (ert-deftest test-org-element/italic-interpreter ()
  1966. "Test italic interpreter."
  1967. (should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
  1968. (ert-deftest test-org-element/latex-fragment-interpreter ()
  1969. "Test latex fragment interpreter."
  1970. (let ((org-latex-regexps
  1971. '(("begin" "^[ ]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^�]+?\\\\end{\\2}\\)" 1 t)
  1972. ("$1" "\\([^$]\\|^\\)\\(\\$[^ \n,;.$]\\$\\)\\([- .,?;:'\")�]\\|$\\)" 2 nil)
  1973. ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \n,;.$][^$\n ]*?\\(\n[^$\n ]*?\\)\\{0,2\\}[^ \n,.$]\\)\\$\\)\\)\\([- .,?;:'\")�]\\|$\\)" 2 nil)
  1974. ("\\(" "\\\\([^�]*?\\\\)" 0 nil)
  1975. ("\\[" "\\\\\\[[^�]*?\\\\\\]" 0 nil)
  1976. ("$$" "\\$\\$[^�]*?\\$\\$" 0 nil))))
  1977. (should (equal (org-test-parse-and-interpret "\\command{}")
  1978. "\\command{}\n"))
  1979. (should (equal (org-test-parse-and-interpret "$x$") "$x$\n"))
  1980. (should (equal (org-test-parse-and-interpret "$x+y$") "$x+y$\n"))
  1981. (should (equal (org-test-parse-and-interpret "$$x+y$$") "$$x+y$$\n"))
  1982. (should (equal (org-test-parse-and-interpret "\\(x+y\\)") "\\(x+y\\)\n"))
  1983. (should (equal (org-test-parse-and-interpret "\\[x+y\\]") "\\[x+y\\]\n"))))
  1984. (ert-deftest test-org-element/line-break-interpreter ()
  1985. "Test line break interpreter."
  1986. (should (equal (org-test-parse-and-interpret "First line \\\\ \nSecond line")
  1987. "First line \\\\\nSecond line\n")))
  1988. (ert-deftest test-org-element/link-interpreter ()
  1989. "Test link interpreter."
  1990. ;; 1. Links targeted from a radio target.
  1991. (should (equal (let ((org-target-link-regexp "radio-target"))
  1992. (org-test-parse-and-interpret "a radio-target"))
  1993. "a radio-target\n"))
  1994. ;; 2. Regular links.
  1995. ;;
  1996. ;; 2.1. Without description.
  1997. (should (equal (org-test-parse-and-interpret "[[http://orgmode.org]]")
  1998. "[[http://orgmode.org]]\n"))
  1999. ;; 2.2. With a description.
  2000. (should (equal (org-test-parse-and-interpret
  2001. "[[http://orgmode.org][Org mode]]")
  2002. "[[http://orgmode.org][Org mode]]\n"))
  2003. ;; 2.3. Id links.
  2004. (should (equal (org-test-parse-and-interpret "[[id:aaaa]]") "[[id:aaaa]]\n"))
  2005. ;; 2.4. Custom-id links.
  2006. (should (equal (org-test-parse-and-interpret "[[#id]]") "[[#id]]\n"))
  2007. ;; 2.5 Code-ref links.
  2008. (should (equal (org-test-parse-and-interpret "[[(ref)]]") "[[(ref)]]\n"))
  2009. ;; 3. Normalize plain links.
  2010. (should (equal (org-test-parse-and-interpret "http://orgmode.org")
  2011. "[[http://orgmode.org]]\n"))
  2012. ;; 4. Normalize angular links.
  2013. (should (equal (org-test-parse-and-interpret "<http://orgmode.org>")
  2014. "[[http://orgmode.org]]\n")))
  2015. (ert-deftest test-org-element/macro-interpreter ()
  2016. "Test macro interpreter."
  2017. ;; 1. Without argument.
  2018. (should (equal (org-test-parse-and-interpret "{{{test}}}") "{{{test}}}\n"))
  2019. ;; 2. With arguments.
  2020. (should (equal (org-test-parse-and-interpret "{{{test(arg1,arg2)}}}")
  2021. "{{{test(arg1,arg2)}}}\n")))
  2022. (ert-deftest test-org-element/radio-target-interpreter ()
  2023. "Test radio target interpreter."
  2024. (should (equal (org-test-parse-and-interpret "<<<some text>>>")
  2025. "<<<some text>>>\n")))
  2026. (ert-deftest test-org-element/statistics-cookie-interpreter ()
  2027. "Test statistics cookie interpreter."
  2028. ;; 1. Without percent
  2029. (should (equal (org-test-parse-and-interpret "[0/1]") "[0/1]\n"))
  2030. ;; 2. With percent.
  2031. (should (equal (org-test-parse-and-interpret "[66%]") "[66%]\n")))
  2032. (ert-deftest test-org-element/strike-through-interpreter ()
  2033. "Test strike through interpreter."
  2034. (should (equal (org-test-parse-and-interpret "+target+") "+target+\n")))
  2035. (ert-deftest test-org-element/subscript-interpreter ()
  2036. "Test subscript interpreter."
  2037. ;; 1. Without brackets.
  2038. (should (equal (org-test-parse-and-interpret "a_b") "a_b\n"))
  2039. ;; 2. With brackets.
  2040. (should (equal (org-test-parse-and-interpret "a_{b}") "a_{b}\n")))
  2041. (ert-deftest test-org-element/superscript-interpreter ()
  2042. "Test superscript interpreter."
  2043. ;; 1. Without brackets.
  2044. (should (equal (org-test-parse-and-interpret "a^b") "a^b\n"))
  2045. ;; 2. With brackets.
  2046. (should (equal (org-test-parse-and-interpret "a^{b}") "a^{b}\n")))
  2047. (ert-deftest test-org-element/target-interpreter ()
  2048. "Test target interpreter."
  2049. (should (equal (org-test-parse-and-interpret "<<target>>") "<<target>>\n")))
  2050. (ert-deftest test-org-element/underline-interpreter ()
  2051. "Test underline interpreter."
  2052. (should (equal (org-test-parse-and-interpret "_text_") "_text_\n")))
  2053. (ert-deftest test-org-element/verbatim-interpreter ()
  2054. "Test verbatim interpreter."
  2055. (should (equal (org-test-parse-and-interpret "=text=") "=text=\n")))
  2056. ;;; Test Granularity
  2057. (ert-deftest test-org-element/granularity ()
  2058. "Test granularity impact on buffer parsing."
  2059. (org-test-with-temp-text "
  2060. * Head 1
  2061. ** Head 2
  2062. #+BEGIN_CENTER
  2063. Centered paragraph.
  2064. #+END_CENTER
  2065. Paragraph \\alpha."
  2066. ;; 1.1. Granularity set to `headline' should parse every headline
  2067. ;; in buffer, and only them.
  2068. (let ((tree (org-element-parse-buffer 'headline)))
  2069. (should (= 2 (length (org-element-map tree 'headline 'identity))))
  2070. (should-not (org-element-map tree 'paragraph 'identity)))
  2071. ;; 1.2. Granularity set to `greater-element' should not enter
  2072. ;; greater elements excepted headlines and sections.
  2073. (let ((tree (org-element-parse-buffer 'greater-element)))
  2074. (should (= 1 (length (org-element-map tree 'center-block 'identity))))
  2075. (should (= 1 (length (org-element-map tree 'paragraph 'identity))))
  2076. (should-not (org-element-map tree 'entity 'identity)))
  2077. ;; 1.3. Granularity set to `element' should enter every
  2078. ;; greater-element.
  2079. (let ((tree (org-element-parse-buffer 'element)))
  2080. (should (= 2 (length (org-element-map tree 'paragraph 'identity))))
  2081. (should-not (org-element-map tree 'entity 'identity)))
  2082. ;; 1.4. Granularity set to `object' can see everything.
  2083. (let ((tree (org-element-parse-buffer 'object)))
  2084. (should (= 1 (length (org-element-map tree 'entity 'identity)))))))
  2085. (ert-deftest test-org-element/secondary-string-parsing ()
  2086. "Test if granularity correctly toggles secondary strings parsing."
  2087. ;; 1. With a granularity bigger than `object', no secondary string
  2088. ;; should be parsed.
  2089. ;;
  2090. ;; 1.1. Test with `headline' type.
  2091. (org-test-with-temp-text "* Headline"
  2092. (let ((headline
  2093. (org-element-map (org-element-parse-buffer 'headline) 'headline
  2094. 'identity
  2095. nil
  2096. 'first-match)))
  2097. (should (stringp (org-element-property :title headline)))))
  2098. ;; 1.2. Test with `item' type.
  2099. (org-test-with-temp-text "* Headline\n- tag :: item"
  2100. (let ((item (org-element-map (org-element-parse-buffer 'element)
  2101. 'item
  2102. 'identity
  2103. nil
  2104. 'first-match)))
  2105. (should (stringp (org-element-property :tag item)))))
  2106. ;; 1.3. Test with `inlinetask' type, if avalaible.
  2107. (when (featurep 'org-inlinetask)
  2108. (let ((org-inlinetask-min-level 15))
  2109. (org-test-with-temp-text "*************** Inlinetask"
  2110. (let ((inlinetask (org-element-map (org-element-parse-buffer 'element)
  2111. 'inlinetask
  2112. 'identity
  2113. nil
  2114. 'first-match)))
  2115. (should (stringp (org-element-property :title inlinetask)))))))
  2116. ;; 2. With a default granularity, secondary strings should be
  2117. ;; parsed.
  2118. (org-test-with-temp-text "* Headline"
  2119. (let ((headline
  2120. (org-element-map (org-element-parse-buffer) 'headline
  2121. 'identity
  2122. nil
  2123. 'first-match)))
  2124. (should (listp (org-element-property :title headline)))))
  2125. ;; 3. `org-element-at-point' should never parse a secondary string.
  2126. (org-test-with-temp-text "* Headline"
  2127. (should (stringp (org-element-property :title (org-element-at-point))))))
  2128. ;;; Test `:parent' Property
  2129. (ert-deftest test-org-element/parent-property ()
  2130. "Test `:parent' property."
  2131. ;; Elements.
  2132. (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
  2133. (let* ((tree (org-element-parse-buffer))
  2134. (parent (org-element-property
  2135. :parent
  2136. (org-element-map tree 'paragraph 'identity nil t))))
  2137. (should parent)
  2138. (should (eq (org-element-map tree 'center-block 'identity nil t)
  2139. parent))))
  2140. ;; Objects.
  2141. (org-test-with-temp-text "a_{/b/}"
  2142. (let* ((tree (org-element-parse-buffer))
  2143. (parent (org-element-property
  2144. :parent
  2145. (org-element-map tree 'italic 'identity nil t))))
  2146. (should parent)
  2147. (should (eq parent
  2148. (org-element-map tree 'subscript 'identity nil t)))))
  2149. ;; Secondary strings
  2150. (org-test-with-temp-text "* /italic/"
  2151. (let* ((tree (org-element-parse-buffer))
  2152. (parent (org-element-property
  2153. :parent (org-element-map tree 'italic 'identity nil t))))
  2154. (should parent)
  2155. (should (eq parent
  2156. (org-element-map tree 'headline 'identity nil t))))))
  2157. ;;; Test Normalize Contents
  2158. (ert-deftest test-org-element/normalize-contents ()
  2159. "Test `org-element-normalize-contents' specifications."
  2160. ;; 1. Remove maximum common indentation from element's contents.
  2161. (should
  2162. (equal
  2163. (org-element-normalize-contents
  2164. '(paragraph nil " Two spaces\n Three spaces"))
  2165. '(paragraph nil "Two spaces\n Three spaces")))
  2166. ;; 2. Ignore objects within contents when computing maximum common
  2167. ;; indentation.
  2168. (should
  2169. (equal
  2170. (org-element-normalize-contents
  2171. '(paragraph nil " One " (emphasis nil "space") "\n Two spaces"))
  2172. '(paragraph nil "One " (emphasis nil "space") "\n Two spaces")))
  2173. ;; 3. Ignore blank lines.
  2174. (should
  2175. (equal
  2176. (org-element-normalize-contents
  2177. '(paragraph nil " Two spaces\n\n \n Two spaces"))
  2178. '(paragraph nil "Two spaces\n\n \nTwo spaces")))
  2179. ;; 4. Recursively enter objects in order to compute common
  2180. ;; indentation.
  2181. (should
  2182. (equal
  2183. (org-element-normalize-contents
  2184. '(paragraph nil " Two spaces " (bold nil " and\n One space")))
  2185. '(paragraph nil " Two spaces " (bold nil " and\nOne space"))))
  2186. ;; 5. When optional argument is provided, ignore first line
  2187. ;; indentation.
  2188. (should
  2189. (equal
  2190. (org-element-normalize-contents
  2191. '(paragraph nil "No space\n Two spaces\n Three spaces") t)
  2192. '(paragraph nil "No space\nTwo spaces\n Three spaces"))))
  2193. ;;; Test Navigation Tools.
  2194. (ert-deftest test-org-element/at-point ()
  2195. "Test `org-element-at-point' specifications."
  2196. ;; Return closest element containing point.
  2197. (should
  2198. (eq 'paragraph
  2199. (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
  2200. (progn (search-forward "A")
  2201. (org-element-type (org-element-at-point))))))
  2202. ;; Correctly set `:parent' property.
  2203. (should
  2204. (eq 'center-block
  2205. (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
  2206. (progn (search-forward "A")
  2207. (org-element-type
  2208. (org-element-property :parent (org-element-at-point)))))))
  2209. ;; Special case: at the very beginning of a table, return `table'
  2210. ;; object instead of `table-row'.
  2211. (should
  2212. (eq 'table
  2213. (org-test-with-temp-text "| a | b |"
  2214. (org-element-type (org-element-at-point)))))
  2215. ;; Special case: at the very beginning of a list or sub-list, return
  2216. ;; `plain-list' object instead of `item'.
  2217. (should
  2218. (eq 'plain-list
  2219. (org-test-with-temp-text "- item"
  2220. (org-element-type (org-element-at-point)))))
  2221. ;; Special case: at the closing line of a greater element, be sure
  2222. ;; to return it instead of the last element in its contents.
  2223. (should
  2224. (eq 'center-block
  2225. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph\n#+END_CENTER"
  2226. (progn (forward-line 2)
  2227. (org-element-type (org-element-at-point))))))
  2228. ;; Special case: at a blank line between two items, be sure to
  2229. ;; return item above instead of the last element of its contents.
  2230. (should
  2231. (eq 'item
  2232. (org-test-with-temp-text "- Para1\n\n- Para2"
  2233. (progn (forward-line)
  2234. (org-element-type
  2235. (let ((org-empty-line-terminates-plain-lists nil))
  2236. (org-element-at-point)))))))
  2237. ;; Special case: at the last blank line in a plain list, return it
  2238. ;; instead of the last item.
  2239. (should
  2240. (eq 'plain-list
  2241. (org-test-with-temp-text "- Para1\n- Para2\n\nPara3"
  2242. (progn (forward-line 2)
  2243. (org-element-type (org-element-at-point))))))
  2244. ;; With an optional argument, return trail.
  2245. (should
  2246. (equal '(paragraph center-block)
  2247. (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER\nZ"
  2248. (progn (search-forward "Z")
  2249. (mapcar 'org-element-type (org-element-at-point t)))))))
  2250. (ert-deftest test-org-element/context ()
  2251. "Test `org-element-context' specifications."
  2252. ;; Return closest object containing point.
  2253. (should
  2254. (eq 'underline
  2255. (org-test-with-temp-text "Some *text with _underline_ text*"
  2256. (progn (search-forward "under")
  2257. (org-element-type (org-element-context))))))
  2258. ;; Find objects in secondary strings.
  2259. (should
  2260. (eq 'underline
  2261. (org-test-with-temp-text "* Headline _with_ underlining"
  2262. (progn (search-forward "w")
  2263. (org-element-type (org-element-context))))))
  2264. ;; Find objects in objects.
  2265. (should
  2266. (eq 'macro
  2267. (org-test-with-temp-text "| a | {{{macro}}} |"
  2268. (progn (search-forward "{")
  2269. (org-element-type (org-element-context))))))
  2270. (should
  2271. (eq 'table-cell
  2272. (org-test-with-temp-text "| a | b {{{macro}}} |"
  2273. (progn (search-forward "b")
  2274. (org-element-type (org-element-context))))))
  2275. ;; Correctly set `:parent' property.
  2276. (should
  2277. (eq 'paragraph
  2278. (org-test-with-temp-text "Some *bold* text"
  2279. (progn (search-forward "bold")
  2280. (org-element-type
  2281. (org-element-property :parent (org-element-context))))))))
  2282. (provide 'test-org-element)
  2283. ;;; test-org-element.el ends here