test-ob-lua.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ;;; test-ob-lua.el --- tests for ob-lua.el
  2. ;; Copyright (c) 2016 Thibault Marin
  3. ;; Authors: Thibault Marin
  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 <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (unless (featurep 'ob-lua)
  17. (signal 'missing-test-dependency "Support for Lua code blocks"))
  18. (ert-deftest test-ob-lua/simple-value ()
  19. "Test associative array return by value."
  20. (should
  21. (= 2
  22. (org-test-with-temp-text
  23. "#+name: eg
  24. | a | 1 |
  25. | b | 2 |
  26. #+header: :results value
  27. #+header: :var x = eg
  28. #+begin_src lua
  29. return x['b']
  30. #+end_src"
  31. (org-babel-next-src-block)
  32. (org-babel-execute-src-block)))))
  33. (ert-deftest test-ob-lua/simple-output ()
  34. "Test text output from table."
  35. (should
  36. (equal "result: c\n"
  37. (org-test-with-temp-text
  38. "#+name: eg
  39. | a | b | c | d |
  40. #+header: :results output
  41. #+header: :var x = eg
  42. #+begin_src lua
  43. print('result: ' .. x[1][3])
  44. #+end_src"
  45. (org-babel-next-src-block)
  46. (org-babel-execute-src-block)))))
  47. (ert-deftest test-ob-lua/colnames-yes-header-argument ()
  48. "Test table passing with `colnames' header."
  49. (should
  50. (equal "a"
  51. (org-test-with-temp-text
  52. "#+name: eg
  53. | col |
  54. |-----|
  55. | a |
  56. | b |
  57. #+header: :colnames yes
  58. #+header: :var x = eg
  59. #+begin_src lua
  60. return x[1]
  61. #+end_src"
  62. (org-babel-next-src-block)
  63. (org-babel-execute-src-block)))))
  64. (ert-deftest test-ob-lua/colnames-yes-header-argument-pp ()
  65. "Test table passing with `colnames' header and pp option."
  66. (should
  67. (equal "a = 12\nb = 13\n"
  68. (org-test-with-temp-text
  69. "#+name: eg
  70. | col | val |
  71. |-----+-----|
  72. | a | 12 |
  73. | b | 13 |
  74. #+header: :results value pp
  75. #+header: :colnames yes
  76. #+header: :var x = eg
  77. #+begin_src lua
  78. return x
  79. #+end_src"
  80. (org-babel-next-src-block)
  81. (org-babel-execute-src-block)))))
  82. (ert-deftest test-ob-lua/colnames-nil-header-argument ()
  83. "Test table with `colnames' set to `nil'."
  84. (should
  85. (equal "1 = a\n2 = b\n"
  86. (org-test-with-temp-text
  87. "#+name: eg
  88. | col |
  89. |-----|
  90. | a |
  91. | b |
  92. #+header: :colnames nil
  93. #+header: :var x = eg
  94. #+header: :results value pp
  95. #+begin_src lua
  96. return x
  97. #+end_src"
  98. (org-babel-next-src-block)
  99. (org-babel-execute-src-block)))))
  100. (ert-deftest test-ob-lua/colnames-no-header-argument ()
  101. "Test table passing without `colnames'."
  102. (should
  103. (equal "1 = col\n2 = a\n3 = b\n"
  104. (org-test-with-temp-text
  105. "#+name: eg
  106. | col |
  107. |-----|
  108. | a |
  109. | b |
  110. #+header: :colnames no
  111. #+header: :var x = eg
  112. #+header: :results value pp
  113. #+begin_src lua
  114. return x
  115. #+end_src"
  116. (org-babel-next-src-block)
  117. (org-babel-execute-src-block)))))
  118. (provide 'test-ob-lua)
  119. ;;; test-ob-lua.el ends here