lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / testing / lisp / test-ob-emacs-lisp.el
blob24a373f862519a4fe53814a308aca409c5ed2fa6
1 ;;; test-ob-emacs-lisp.el
3 ;; Copyright (c) 2012-2019 Free Software Foundation, Inc.
4 ;; Authors: Eric Schulte, Martyn Jago
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 ;;; Comments:
23 ;; Org tests for ob-emacs-lisp.el live here
25 ;;; Code:
26 (ert-deftest ob-emacs-lisp/commented-last-block-line-no-var ()
27 (org-test-with-temp-text-in-file "
28 #+begin_src emacs-lisp
30 #+end_src"
31 (org-babel-next-src-block)
32 (org-babel-execute-maybe)
33 (should (re-search-forward "results:" nil t))
34 (forward-line)
35 (should
36 (string=
38 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
39 (org-test-with-temp-text-in-file "
40 #+begin_src emacs-lisp
41 \"some text\";;
42 #+end_src"
44 (org-babel-next-src-block)
45 (org-babel-execute-maybe)
46 (should (re-search-forward "results:" nil t))
47 (forward-line)
48 (should
49 (string=
50 ": some text"
51 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
53 (ert-deftest ob-emacs-lisp/commented-last-block-line-with-var ()
54 (org-test-with-temp-text-in-file "
55 #+begin_src emacs-lisp :var a=1
57 #+end_src"
58 (org-babel-next-src-block)
59 (org-babel-execute-maybe)
60 (re-search-forward "results" nil t)
61 (forward-line)
62 (should (string=
64 (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
66 (ert-deftest ob-emacs-lisp/commented-last-block-line ()
67 (should
68 (string= ": 2"
69 (org-test-with-temp-text-in-file "
70 #+begin_src emacs-lisp :var a=2
71 2;;
72 #+end_src"
73 (org-babel-next-src-block)
74 (org-babel-execute-maybe)
75 (re-search-forward "results" nil t)
76 (buffer-substring-no-properties (line-beginning-position 2)
77 (line-end-position 2))))))
79 (ert-deftest ob-emacs-lisp/dynamic-lexical-execute ()
80 (cl-flet ((execute (text)
81 (org-test-with-temp-text-in-file text
82 (org-babel-next-src-block)
83 (org-babel-execute-maybe)
84 (re-search-forward "results" nil t)
85 (re-search-forward ": " nil t)
86 (buffer-substring-no-properties (point) (point-at-eol)))))
88 (should (string= "dynamic" (execute "
89 #+begin_src emacs-lisp :lexical no :results verbatim
90 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
91 #+end_src")))
93 (should (string= "lexical" (execute "
94 #+begin_src emacs-lisp :lexical yes :results verbatim
95 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
96 #+end_src")))
98 (should (string= "dynamic" (let ((x 'dynamic)) (execute "
99 #+begin_src emacs-lisp :lexical no :results verbatim
101 #+end_src"))))
103 (should (string= "lexical" (let ((x 'dynamic)) (execute "
104 #+begin_src emacs-lisp :lexical '((x . lexical)) :results verbatim
106 #+end_src"))))
108 ;; Src block execution uses `eval'. As of 2019-02-26, `eval' does
109 ;; not dynamically bind `lexical-binding' to the value of its
110 ;; LEXICAL parameter. Hence, (eval 'lexical-binding LEXICAL)
111 ;; evaluates to the same value that just `lexical-binding'
112 ;; evaluates to, even if LEXICAL is different. So tests like the
113 ;; following do not work here:
115 ;; (should (string= "t" (execute "
116 ;; #+begin_src emacs-lisp :lexical yes :results verbatim
117 ;; lexical-binding
118 ;; #+end_src")))
120 ;; However, the corresponding test in
121 ;; `ob-emacs-lisp/dynamic-lexical-edit' does work.
124 (ert-deftest ob-emacs-lisp/dynamic-lexical-edit ()
125 (cl-flet ((execute (text)
126 (org-test-with-temp-text-in-file text
127 (org-babel-next-src-block)
128 (org-edit-src-code)
129 (goto-char (point-max))
130 (prog1 (eval-last-sexp 0)
131 (org-edit-src-exit)))))
133 (should (eq 'dynamic (execute "
134 #+begin_src emacs-lisp :lexical no :results verbatim
135 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
136 #+end_src")))
138 (should (eq 'lexical (execute "
139 #+begin_src emacs-lisp :lexical yes :results verbatim
140 (let ((x 'dynamic)) (funcall (let ((x 'lexical)) (lambda () x))))
141 #+end_src")))
143 (should (eq 'dynamic (let ((x 'dynamic)) (execute "
144 #+begin_src emacs-lisp :lexical no :results verbatim
146 #+end_src"))))
148 (should (eq 'lexical (let ((x 'dynamic)) (execute "
149 #+begin_src emacs-lisp :lexical '((x . lexical)) :results verbatim
151 #+end_src"))))
153 (should (equal nil (execute "
154 #+begin_src emacs-lisp :lexical no :results verbatim
155 lexical-binding
156 #+end_src")))
158 (should (equal t (execute "
159 #+begin_src emacs-lisp :lexical yes :results verbatim
160 lexical-binding
161 #+end_src")))
163 (should (equal '((x . 0)) (execute "
164 #+begin_src emacs-lisp :lexical '((x . 0)) :results verbatim
165 lexical-binding
166 #+end_src")))))
168 (provide 'test-ob-emacs-lisp)
170 ;;; test-ob-emacs-lisp.el ends here