Merge branch 'maint'
[org-mode/org-tableheadings.git] / testing / lisp / test-org-src.el
blob4fd581bbe921aecefef94fd4e9186bb0b925cf84
1 ;;; test-org-src.el --- tests for org-src.el
3 ;; Copyright (C) 2012-2015 Le Wang
5 ;; Author: Le Wang <l26wang at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Code:
24 (require 'org-test)
28 (ert-deftest test-org-src/basic ()
29 "Editing regular block works, with point on source block."
30 (org-test-with-temp-text
32 <point>#+begin_src emacs-lisp
33 (message hello)
34 #+end_src
36 (let ((org-edit-src-content-indentation 2)
37 (org-src-preserve-indentation nil))
38 (org-edit-special)
39 (insert "blah")
40 (org-edit-src-exit)
41 (should (equal (buffer-string) "
42 #+begin_src emacs-lisp
43 blah(message hello)
44 #+end_src
45 "))
46 (should (looking-at-p "(message hello)")))))
48 (ert-deftest test-org-src/point-outside-block ()
49 "Editing with point before/after block signals expected error."
50 (org-test-with-temp-text
52 #+begin_src emacs-lisp
53 (message hello)
54 #+end_src
56 (goto-line 1)
57 (should-error (org-edit-special))
58 (goto-char (point-max))
59 (should-error (org-edit-special))))
61 (ert-deftest test-org-src/empty-block ()
62 "Editing empty block."
63 (org-test-with-temp-text
65 <point>#+begin_src emacs-lisp
66 #+end_src
68 (let ((org-edit-src-content-indentation 0)
69 (org-src-preserve-indentation nil))
70 (org-edit-special)
71 (insert "blah")
72 (org-edit-src-exit)
73 (should (equal (buffer-string) "
74 #+begin_src emacs-lisp
75 blah
76 #+end_src
77 "))
78 (should
79 (equal (buffer-substring (line-beginning-position) (point)) "blah")))))
81 (ert-deftest test-org-src/blank-line-block ()
82 "Editing block with just a blank line."
83 (org-test-with-temp-text-in-file
85 #+begin_src emacs-lisp
87 #+end_src
89 (let ((org-edit-src-content-indentation 2)
90 (org-src-preserve-indentation nil))
91 (goto-line 2)
92 (org-edit-special)
93 (insert "blah")
94 (org-edit-src-exit)
95 (should (equal (buffer-string) "
96 #+begin_src emacs-lisp
97 blah
98 #+end_src
99 ")))))
101 (ert-deftest test-org-src/preserve-tabs ()
102 "Editing block preserve tab characters."
103 ;; With `org-src-preserve-indentation' set to nil.
104 (should
105 (equal "
106 #+begin_src emacs-lisp
107 This is a tab: .
108 #+end_src"
109 (org-test-with-temp-text
111 #+begin_src emacs-lisp
112 <point>This is a tab: .
113 #+end_src"
114 (let ((org-edit-src-content-indentation 2)
115 (org-src-preserve-indentation nil))
116 (org-edit-special)
117 (org-edit-src-exit)
118 (buffer-string)))))
119 ;; With `org-src-preserve-indentation' set to t.
120 (should
121 (equal "
122 #+begin_src emacs-lisp
123 This is a tab: .
124 #+end_src"
125 (org-test-with-temp-text
127 #+begin_src emacs-lisp
128 <point>This is a tab: .
129 #+end_src"
130 (let ((org-edit-src-content-indentation 2)
131 (org-src-preserve-indentation t))
132 (org-edit-special)
133 (org-edit-src-exit)
134 (buffer-string))))))
136 (provide 'test-org-src)
137 ;;; test-org-src.el ends here