org-duration: Fix copyright
[org-mode/org-tableheadings.git] / testing / lisp / test-ob-lua.el
blobd0c1302162d3462c3fe8166d33f0cd3c7b5f8869
1 ;;; test-ob-lua.el --- tests for ob-lua.el
3 ;; Copyright (c) 2016 Thibault Marin
4 ;; Authors: Thibault Marin
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Code:
22 (unless (featurep 'ob-lua)
23 (signal 'missing-test-dependency "Support for Lua code blocks"))
25 (ert-deftest test-ob-lua/simple-value ()
26 "Test associative array return by value."
27 (should
28 (= 2
29 (org-test-with-temp-text
30 "#+name: eg
31 | a | 1 |
32 | b | 2 |
34 #+header: :results value
35 #+header: :var x = eg
36 #+begin_src lua
37 return x['b']
38 #+end_src"
39 (org-babel-next-src-block)
40 (org-babel-execute-src-block)))))
42 (ert-deftest test-ob-lua/simple-output ()
43 "Test text output from table."
44 (should
45 (equal "result: c\n"
46 (org-test-with-temp-text
47 "#+name: eg
48 | a | b | c | d |
50 #+header: :results output
51 #+header: :var x = eg
52 #+begin_src lua
53 print('result: ' .. x[1][3])
54 #+end_src"
55 (org-babel-next-src-block)
56 (org-babel-execute-src-block)))))
59 (ert-deftest test-ob-lua/colnames-yes-header-argument ()
60 "Test table passing with `colnames' header."
61 (should
62 (equal "a"
63 (org-test-with-temp-text
64 "#+name: eg
65 | col |
66 |-----|
67 | a |
68 | b |
70 #+header: :colnames yes
71 #+header: :var x = eg
72 #+begin_src lua
73 return x[1]
74 #+end_src"
75 (org-babel-next-src-block)
76 (org-babel-execute-src-block)))))
79 (ert-deftest test-ob-lua/colnames-yes-header-argument-pp ()
80 "Test table passing with `colnames' header and pp option."
81 (should
82 (equal "a = 12\nb = 13\n"
83 (org-test-with-temp-text
84 "#+name: eg
85 | col | val |
86 |-----+-----|
87 | a | 12 |
88 | b | 13 |
90 #+header: :results value pp
91 #+header: :colnames yes
92 #+header: :var x = eg
93 #+begin_src lua
94 return x
95 #+end_src"
96 (org-babel-next-src-block)
97 (org-babel-execute-src-block)))))
99 (ert-deftest test-ob-lua/colnames-nil-header-argument ()
100 "Test table with `colnames' set to `nil'."
101 (should
102 (equal "1 = a\n2 = b\n"
103 (org-test-with-temp-text
104 "#+name: eg
105 | col |
106 |-----|
107 | a |
108 | b |
110 #+header: :colnames nil
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)))))
119 (ert-deftest test-ob-lua/colnames-no-header-argument ()
120 "Test table passing without `colnames'."
121 (should
122 (equal "1 = col\n2 = a\n3 = b\n"
123 (org-test-with-temp-text
124 "#+name: eg
125 | col |
126 |-----|
127 | a |
128 | b |
130 #+header: :colnames no
131 #+header: :var x = eg
132 #+header: :results value pp
133 #+begin_src lua
134 return x
135 #+end_src"
136 (org-babel-next-src-block)
137 (org-babel-execute-src-block)))))
139 (provide 'test-ob-lua)
141 ;;; test-ob-lua.el ends here