test-ox-texinfo.el 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. ;;; test-ox-texinfo.el --- Tests for ox-texinfo.el
  2. ;; Copyright (C) 2022 Rudolf Adamkovič
  3. ;; Author: Rudolf Adamkovič <salutis@me.com>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'cl-lib)
  17. (require 'ox-texinfo)
  18. (unless (featurep 'ox-texinfo)
  19. (signal 'missing-test-dependency "org-export-texinfo"))
  20. ;;; TeX fragments
  21. (ert-deftest test-ox-texinfo/tex-fragment-inline ()
  22. "Test inline TeX fragment."
  23. (should
  24. (equal "@math{a^2 = b}"
  25. (let ((org-texinfo-with-latex t))
  26. (org-texinfo-latex-fragment
  27. (org-element-create 'latex-fragment
  28. '(:value "$a^2 = b$"))
  29. nil
  30. '(:with-latex t))))))
  31. (ert-deftest test-ox-texinfo/tex-fragment-inline-padded ()
  32. "Test inline TeX fragment padded with whitespace."
  33. (should
  34. (equal "@math{a^2 = b}"
  35. (let ((org-texinfo-with-latex t))
  36. (org-texinfo-latex-fragment
  37. (org-element-create 'latex-fragment
  38. '(:value "$ a^2 = b $"))
  39. nil
  40. '(:with-latex t))))))
  41. (ert-deftest test-ox-texinfo/tex-fragment-displayed ()
  42. "Test displayed TeX fragment."
  43. (should
  44. (equal (string-join
  45. (list ""
  46. "@displaymath"
  47. "a ^ 2 = b"
  48. "@end displaymath"
  49. "")
  50. "\n")
  51. (let ((org-texinfo-with-latex t))
  52. (org-texinfo-latex-fragment
  53. (org-element-create 'latex-fragment
  54. (list :value "$$a ^ 2 = b$$"))
  55. nil
  56. '(:with-latex t))))))
  57. (ert-deftest test-ox-texinfo/tex-fragment-displayed-padded ()
  58. "Test displayed TeX fragment padded with whitespace."
  59. (should
  60. (equal (string-join
  61. (list ""
  62. "@displaymath"
  63. "a ^ 2 = b"
  64. "@end displaymath"
  65. "")
  66. "\n")
  67. (let ((org-texinfo-with-latex t))
  68. (org-texinfo-latex-fragment
  69. (org-element-create 'latex-fragment
  70. (list :value "$$ a ^ 2 = b $$"))
  71. nil
  72. '(:with-latex t))))))
  73. (ert-deftest test-ox-texinfo/tex-fragment-displayed-multi-line ()
  74. "Test displayed TeX fragment with multiple lines."
  75. (should
  76. (equal (string-join
  77. (list ""
  78. "@displaymath"
  79. "a ^ 2 = b"
  80. "b ^ 2 = c"
  81. "@end displaymath"
  82. "")
  83. "\n")
  84. (let ((org-texinfo-with-latex t))
  85. (org-texinfo-latex-fragment
  86. (org-element-create 'latex-fragment
  87. (list :value
  88. (string-join
  89. (list "$$"
  90. "a ^ 2 = b"
  91. "b ^ 2 = c"
  92. "$$")
  93. "\n")))
  94. nil
  95. '(:with-latex t))))))
  96. (ert-deftest test-ox-texinfo/tex-fragment-displayed-indented ()
  97. "Test displayed TeX fragment with indentation."
  98. (should
  99. (equal (string-join
  100. (list ""
  101. "@displaymath"
  102. "a ^ 2 = b"
  103. "b ^ 2 = c"
  104. "@end displaymath"
  105. "")
  106. "\n")
  107. (let ((org-texinfo-with-latex t))
  108. (org-texinfo-latex-fragment
  109. (org-element-create 'latex-fragment
  110. (list :value
  111. (string-join
  112. (list " $$"
  113. " a ^ 2 = b"
  114. " b ^ 2 = c"
  115. " $$")
  116. "\n")))
  117. nil
  118. '(:with-latex t))))))
  119. ;;; LaTeX fragments
  120. (ert-deftest test-ox-texinfo/latex-fragment-inline ()
  121. "Test inline LaTeX fragment."
  122. (should
  123. (equal "@math{a^2 = b}"
  124. (let ((org-texinfo-with-latex t))
  125. (org-texinfo-latex-fragment
  126. (org-element-create 'latex-fragment
  127. '(:value "\\(a^2 = b\\)"))
  128. nil
  129. '(:with-latex t))))))
  130. (ert-deftest test-ox-texinfo/latex-fragment-inline-padded ()
  131. "Test inline LaTeX fragment padded with whitespace."
  132. (should
  133. (equal "@math{a^2 = b}"
  134. (let ((org-texinfo-with-latex t))
  135. (org-texinfo-latex-fragment
  136. (org-element-create 'latex-fragment
  137. '(:value "\\( a^2 = b \\)"))
  138. nil
  139. '(:with-latex t))))))
  140. (ert-deftest test-ox-texinfo/latex-fragment-displayed ()
  141. "Test displayed LaTeX fragment."
  142. (should
  143. (equal (string-join
  144. (list ""
  145. "@displaymath"
  146. "a ^ 2 = b"
  147. "@end displaymath"
  148. "")
  149. "\n")
  150. (let ((org-texinfo-with-latex t))
  151. (org-texinfo-latex-fragment
  152. (org-element-create 'latex-fragment
  153. (list :value "\\[a ^ 2 = b\\]"))
  154. nil
  155. '(:with-latex t))))))
  156. (ert-deftest test-ox-texinfo/latex-fragment-displayed-padded ()
  157. "Test displayed LaTeX fragment with multiple lines."
  158. (should
  159. (equal (string-join
  160. (list ""
  161. "@displaymath"
  162. "a ^ 2 = b"
  163. "@end displaymath"
  164. "")
  165. "\n")
  166. (let ((org-texinfo-with-latex t))
  167. (org-texinfo-latex-fragment
  168. (org-element-create 'latex-fragment
  169. (list :value "\\[ a ^ 2 = b \\]"))
  170. nil
  171. '(:with-latex t))))))
  172. (ert-deftest test-ox-texinfo/latex-fragment-displayed-multi-line ()
  173. "Test displayed LaTeX fragment with multiple lines."
  174. (should
  175. (equal (string-join
  176. (list ""
  177. "@displaymath"
  178. "a ^ 2 = b"
  179. "b ^ 2 = c"
  180. "@end displaymath"
  181. "")
  182. "\n")
  183. (let ((org-texinfo-with-latex t))
  184. (org-texinfo-latex-fragment
  185. (org-element-create 'latex-fragment
  186. (list :value
  187. (string-join
  188. (list "\\["
  189. "a ^ 2 = b"
  190. "b ^ 2 = c"
  191. "\\]")
  192. "\n")))
  193. nil
  194. '(:with-latex t))))))
  195. (ert-deftest test-ox-texinfo/latex-fragment-displayed-indented ()
  196. "Test displayed LaTeX fragment with indentation."
  197. (should
  198. (equal (string-join
  199. (list ""
  200. "@displaymath"
  201. "a ^ 2 = b"
  202. "b ^ 2 = c"
  203. "@end displaymath"
  204. "")
  205. "\n")
  206. (let ((org-texinfo-with-latex t))
  207. (org-texinfo-latex-fragment
  208. (org-element-create 'latex-fragment
  209. (list :value
  210. (string-join
  211. (list " \\["
  212. " a ^ 2 = b"
  213. " b ^ 2 = c"
  214. " \\]")
  215. "\n")))
  216. nil
  217. '(:with-latex t))))))
  218. ;;; LaTeX environments
  219. (ert-deftest test-ox-texinfo/latex-environment ()
  220. "Test LaTeX environment."
  221. (should
  222. (equal (string-join
  223. (list "@displaymath"
  224. "\\begin{equation}"
  225. "a ^ 2 = b"
  226. "b ^ 2 = c"
  227. "\\end{equation}"
  228. "@end displaymath")
  229. "\n")
  230. (let ((org-texinfo-with-latex t))
  231. (org-texinfo-latex-environment
  232. (org-element-create 'latex-environment
  233. (list :value
  234. (string-join
  235. (list "\\begin{equation}"
  236. "a ^ 2 = b"
  237. "b ^ 2 = c"
  238. "\\end{equation}")
  239. "\n")))
  240. nil
  241. '(:with-latex t))))))
  242. (ert-deftest test-ox-texinfo/latex-environment-indented ()
  243. "Test LaTeX environment with indentation."
  244. (should
  245. (equal (string-join
  246. (list "@displaymath"
  247. "\\begin{equation}"
  248. "a ^ 2 = b"
  249. "b ^ 2 = c"
  250. "\\end{equation}"
  251. "@end displaymath")
  252. "\n")
  253. (let ((org-texinfo-with-latex t))
  254. (org-texinfo-latex-environment
  255. (org-element-create 'latex-environment
  256. (list :value
  257. (string-join
  258. (list " \\begin{equation}"
  259. " a ^ 2 = b"
  260. " b ^ 2 = c"
  261. " \\end{equation}")
  262. "\n")))
  263. nil
  264. '(:with-latex t))))))
  265. (provide 'test-ox-texinfo)
  266. ;;; test-ox-texinfo.el end here