PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/test/Tests/Readers/Org/Inline.hs

https://github.com/jgm/pandoc
Haskell | 393 lines | 310 code | 71 blank | 12 comment | 5 complexity | 4bd49c712b1a23b763971d110895d975 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. {-# LANGUAGE OverloadedStrings #-}
  2. {- |
  3. Module : Tests.Readers.Org.Inline
  4. Copyright : © 2014-2022 Albert Krewinkel
  5. License : GNU GPL, version 2 or above
  6. Maintainer : Albert Krewinkel <albert@zeitkraut.de>
  7. Stability : alpha
  8. Portability : portable
  9. Tests parsing of org inlines.
  10. -}
  11. module Tests.Readers.Org.Inline (tests) where
  12. import Data.List (intersperse)
  13. import Test.Tasty (TestTree, testGroup)
  14. import Tests.Helpers ((=?>))
  15. import Tests.Readers.Org.Shared ((=:), spcSep)
  16. import Text.Pandoc.Builder
  17. import qualified Data.Text as T
  18. import qualified Tests.Readers.Org.Inline.Citation as Citation
  19. import qualified Tests.Readers.Org.Inline.Note as Note
  20. import qualified Tests.Readers.Org.Inline.Smart as Smart
  21. tests :: [TestTree]
  22. tests =
  23. [ "Plain String" =:
  24. "Hello, World" =?>
  25. para (spcSep [ "Hello,", "World" ])
  26. , "Emphasis" =:
  27. "/Planet Punk/" =?>
  28. para (emph . spcSep $ ["Planet", "Punk"])
  29. , "Strong" =:
  30. "*Cider*" =?>
  31. para (strong "Cider")
  32. , "Strong Emphasis" =:
  33. "/*strength*/" =?>
  34. para (emph . strong $ "strength")
  35. , "Emphasized Strong preceded by space" =:
  36. " */super/*" =?>
  37. para (strong . emph $ "super")
  38. , "Underline" =:
  39. "_underline_" =?>
  40. para (underline "underline")
  41. , "Strikeout" =:
  42. "+Kill Bill+" =?>
  43. para (strikeout . spcSep $ [ "Kill", "Bill" ])
  44. , "Verbatim" =:
  45. "=Robot.rock()=" =?>
  46. para (codeWith ("", ["verbatim"], []) "Robot.rock()")
  47. , "Code" =:
  48. "~word for word~" =?>
  49. para (code "word for word")
  50. , "Math $..$" =:
  51. "$E=mc^2$" =?>
  52. para (math "E=mc^2")
  53. , "Math $$..$$" =:
  54. "$$E=mc^2$$" =?>
  55. para (displayMath "E=mc^2")
  56. , "Math \\[..\\]" =:
  57. "\\[E=ℎν\\]" =?>
  58. para (displayMath "E=ℎν")
  59. , "Math \\(..\\)" =:
  60. "\\(σ_x σ_p ≥ \\frac{ℏ}{2}\\)" =?>
  61. para (math "σ_x σ_p ≥ \\frac{ℏ}{2}")
  62. , "Symbol" =:
  63. "A * symbol" =?>
  64. para (str "A" <> space <> str "*" <> space <> "symbol")
  65. , "Superscript simple expression" =:
  66. "2^-λ" =?>
  67. para (str "2" <> superscript "-λ")
  68. , "Superscript multi char" =:
  69. "2^{n-1}" =?>
  70. para (str "2" <> superscript "n-1")
  71. , "Subscript simple expression" =:
  72. "a_n" =?>
  73. para (str "a" <> subscript "n")
  74. , "Subscript multi char" =:
  75. "a_{n+1}" =?>
  76. para (str "a" <> subscript "n+1")
  77. , "Linebreak" =:
  78. "line \\\\ \nbreak" =?>
  79. para ("line" <> linebreak <> "break")
  80. , "Inline note" =:
  81. "[fn::Schreib mir eine E-Mail]" =?>
  82. para (note $ para "Schreib mir eine E-Mail")
  83. , "Markup-chars not occurring on word break are symbols" =:
  84. T.unlines [ "this+that+ +so+on"
  85. , "seven*eight* nine*"
  86. , "+not+funny+"
  87. ] =?>
  88. para ("this+that+ +so+on" <> softbreak <>
  89. "seven*eight* nine*" <> softbreak <>
  90. strikeout "not+funny")
  91. , "No empty markup" =:
  92. "// ** __ <> == ~~ $$" =?>
  93. para (spcSep [ "//", "**", "__", "<>", "==", "~~", "$$" ])
  94. , "Adherence to Org's rules for markup borders" =:
  95. "/t/& a/ / ./r/ (*l*) /e/! /b/." =?>
  96. para (spcSep [ emph $ "t/&" <> space <> "a"
  97. , "/"
  98. , "./r/"
  99. , "(" <> strong "l" <> ")"
  100. , emph "e" <> "!"
  101. , emph "b" <> "."
  102. ])
  103. , "Quotes are allowed border chars" =:
  104. "/'yep/ *sure\"*" =?>
  105. para (emph "'yep" <> space <> strong "sure\"")
  106. , "Spaces are forbidden border chars" =:
  107. "/nada /" =?>
  108. para "/nada /"
  109. , "Markup should work properly after a blank line" =:
  110. T.unlines ["foo", "", "/bar/"] =?>
  111. para (text "foo") <>
  112. para (emph $ text "bar")
  113. , "Inline math must stay within three lines" =:
  114. T.unlines [ "$a", "b", "c$", "$d", "e", "f", "g$" ] =?>
  115. para (math "a\nb\nc" <> softbreak <>
  116. "$d" <> softbreak <> "e" <> softbreak <>
  117. "f" <> softbreak <> "g$")
  118. , "Single-character math" =:
  119. "$a$ $b$! $c$?" =?>
  120. para (spcSep [ math "a"
  121. , "$b$!"
  122. , math "c" <> "?"
  123. ])
  124. , "Markup may not span more than two lines" =:
  125. "/this *is +totally\nnice+ not*\nemph/" =?>
  126. para ("/this" <> space <>
  127. strong ("is" <> space <>
  128. strikeout ("totally" <>
  129. softbreak <> "nice") <>
  130. space <> "not") <>
  131. softbreak <> "emph/")
  132. , "Sub- and superscript expressions" =:
  133. T.unlines [ "a_(a(b)(c)d)"
  134. , "e^(f(g)h)"
  135. , "i_(jk)l)"
  136. , "m^()n"
  137. , "o_{p{q{}r}}"
  138. , "s^{t{u}v}"
  139. , "w_{xy}z}"
  140. , "1^{}2"
  141. , "3_{{}}"
  142. , "4^(a(*b(c*)d))"
  143. ] =?>
  144. para (mconcat $ intersperse softbreak
  145. [ "a" <> subscript "(a(b)(c)d)"
  146. , "e" <> superscript "(f(g)h)"
  147. , "i" <> subscript "(jk)" <> "l)"
  148. , "m" <> superscript "()" <> "n"
  149. , "o" <> subscript "p{q{}r}"
  150. , "s" <> superscript "t{u}v"
  151. , "w" <> subscript "xy" <> "z}"
  152. , "1" <> superscript "" <> "2"
  153. , "3" <> subscript "{}"
  154. , "4" <> superscript ("(a(" <> strong "b(c" <> ")d))")
  155. ])
  156. , "Verbatim text can contain equal signes (=)" =:
  157. "=is_subst = True=" =?>
  158. para (codeWith ("", ["verbatim"], []) "is_subst = True")
  159. , testGroup "Images"
  160. [ "Image" =:
  161. "[[./sunset.jpg]]" =?>
  162. para (image "./sunset.jpg" "" "")
  163. , "Image with explicit file: prefix" =:
  164. "[[file:sunrise.jpg]]" =?>
  165. para (image "sunrise.jpg" "" "")
  166. , "Multiple images within a paragraph" =:
  167. T.unlines [ "[[file:sunrise.jpg]]"
  168. , "[[file:sunset.jpg]]"
  169. ] =?>
  170. para (image "sunrise.jpg" "" ""
  171. <> softbreak
  172. <> image "sunset.jpg" "" "")
  173. , "Image with html attributes" =:
  174. T.unlines [ "#+attr_html: :width 50%"
  175. , "[[file:guinea-pig.gif]]"
  176. ] =?>
  177. para (imageWith ("", [], [("width", "50%")]) "guinea-pig.gif" "" "")
  178. , "HTML attributes can have trailing spaces" =:
  179. T.unlines [ "#+attr_html: :width 100% :height 360px "
  180. , "[[file:fireworks.jpg]]"
  181. ] =?>
  182. let kv = [("width", "100%"), ("height", "360px")]
  183. in para (imageWith (mempty, mempty, kv) "fireworks.jpg" mempty mempty)
  184. , "Uppercase extension" =:
  185. "[[file:test.PNG]]" =?>
  186. para (image "test.PNG" "" "")
  187. ]
  188. , "Explicit link" =:
  189. "[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>
  190. para (link "http://zeitlens.com/" ""
  191. ("pseudo-random" <> space <> emph "nonsense"))
  192. , "Self-link" =:
  193. "[[http://zeitlens.com/]]" =?>
  194. para (link "http://zeitlens.com/" "" "http://zeitlens.com/")
  195. , "Internal self-link (reference)" =:
  196. "[[#rabbit]]" =?>
  197. para (link "#rabbit" "" "#rabbit")
  198. , "Absolute file link" =:
  199. "[[/url][hi]]" =?>
  200. para (link "file:///url" "" "hi")
  201. , "Link to file in parent directory" =:
  202. "[[../file.txt][moin]]" =?>
  203. para (link "../file.txt" "" "moin")
  204. , "Empty link (for gitit interop)" =:
  205. "[[][New Link]]" =?>
  206. para (link "" "" "New Link")
  207. , "Image link" =:
  208. "[[sunset.png][file:dusk.svg]]" =?>
  209. para (link "sunset.png" "" (image "dusk.svg" "" ""))
  210. , "Image link with non-image target" =:
  211. "[[http://example.com][./logo.png]]" =?>
  212. para (link "http://example.com" "" (image "./logo.png" "" ""))
  213. , "Link to image" =:
  214. "[[https://example.com/image.jpg][Look!]]" =?>
  215. para (link "https://example.com/image.jpg" "" (str "Look!"))
  216. , "Plain link" =:
  217. "Posts on http://zeitlens.com/ can be funny at times." =?>
  218. para (spcSep [ "Posts", "on"
  219. , link "http://zeitlens.com/" "" "http://zeitlens.com/"
  220. , "can", "be", "funny", "at", "times."
  221. ])
  222. , "Angle link" =:
  223. "Look at <http://moltkeplatz.de> for fnords." =?>
  224. para (spcSep [ "Look", "at"
  225. , link "http://moltkeplatz.de" "" "http://moltkeplatz.de"
  226. , "for", "fnords."
  227. ])
  228. , "Absolute file link" =:
  229. "[[file:///etc/passwd][passwd]]" =?>
  230. para (link "file:///etc/passwd" "" "passwd")
  231. , "File link" =:
  232. "[[file:target][title]]" =?>
  233. para (link "target" "" "title")
  234. , "Anchor" =:
  235. "<<anchor>> Link here later." =?>
  236. para (spanWith ("anchor", [], []) mempty <>
  237. "Link" <> space <> "here" <> space <> "later.")
  238. , "Inline code block" =:
  239. "src_emacs-lisp{(message \"Hello\")}" =?>
  240. para (codeWith ( ""
  241. , [ "commonlisp" ]
  242. , [ ("org-language", "emacs-lisp") ])
  243. "(message \"Hello\")")
  244. , "Inline code block with arguments" =:
  245. "src_sh[:export both :results output]{echo 'Hello, World'}" =?>
  246. para (codeWith ( ""
  247. , [ "bash" ]
  248. , [ ("org-language", "sh")
  249. , ("export", "both")
  250. , ("results", "output")
  251. ]
  252. )
  253. "echo 'Hello, World'")
  254. , "Inline code block with a blank argument array" =:
  255. "src_sh[]{echo 'Hello, World'}" =?>
  256. para (codeWith ( ""
  257. , [ "bash" ]
  258. , [ ("org-language", "sh") ])
  259. "echo 'Hello, World'")
  260. , "Inline code block with toggle" =:
  261. "src_sh[:toggle]{echo $HOME}" =?>
  262. para (codeWith ( ""
  263. , [ "bash" ]
  264. , [ ("org-language", "sh")
  265. , ("toggle", "yes")
  266. ]
  267. )
  268. "echo $HOME")
  269. , "Inline LaTeX symbol" =:
  270. "\\dots" =?>
  271. para "…"
  272. , "Inline LaTeX command" =:
  273. "\\textit{Emphasised}" =?>
  274. para (emph "Emphasised")
  275. , "Inline LaTeX command with spaces" =:
  276. "\\emph{Emphasis mine}" =?>
  277. para (emph "Emphasis mine")
  278. , "Inline math symbols" =:
  279. "\\tau \\oplus \\alpha" =?>
  280. para "τ ⊕ α"
  281. , "Inline LaTeX math command" =:
  282. "\\crarr" =?>
  283. para "↵"
  284. , "Unknown inline LaTeX command" =:
  285. "\\notacommand{foo}" =?>
  286. para (rawInline "latex" "\\notacommand{foo}")
  287. , "Export snippet" =:
  288. "@@html:<kbd>M-x org-agenda</kbd>@@" =?>
  289. para (rawInline "html" "<kbd>M-x org-agenda</kbd>")
  290. , "MathML symbol in LaTeX-style" =:
  291. "There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: '\\nbsp')." =?>
  292. para "There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: ' ')."
  293. , "MathML symbol in LaTeX-style, including braces" =:
  294. "\\Aacute{}stor" =?>
  295. para "Ástor"
  296. , "MathML copy sign" =:
  297. "\\copy" =?>
  298. para "©"
  299. , "MathML symbols, space separated" =:
  300. "\\ForAll \\Auml" =?>
  301. para "∀ Ä"
  302. , "Macro" =:
  303. T.unlines [ "#+MACRO: HELLO /Hello, $1/"
  304. , "{{{HELLO(World)}}}"
  305. ] =?>
  306. para (emph "Hello, World")
  307. , "Macro duplicating its argument" =:
  308. T.unlines [ "#+MACRO: HELLO $1$1"
  309. , "{{{HELLO(moin)}}}"
  310. ] =?>
  311. para "moinmoin"
  312. , "Macro called with too few arguments" =:
  313. T.unlines [ "#+MACRO: HELLO Foo $1 $2 Bar"
  314. , "{{{HELLO()}}}"
  315. ] =?>
  316. para "Foo Bar"
  317. , testGroup "Citations" Citation.tests
  318. , testGroup "Footnotes" Note.tests
  319. , testGroup "Smart punctuation" Smart.tests
  320. ]