ob-core: Add document and test for "graphics" format
[org-mode/org-tableheadings.git] / testing / lisp / test-org-tempo.el
blob1840b35bcfa187c0500f717b479019470b522c3c
1 ;;; test-org-tempo.el --- Tests for test-org-tempo.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017 Rasmus Pank Roulund
5 ;; Author: Rasmus Pank Roulund <emacs at pank dot eu>
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-tempo)
26 (unless (featurep 'org-tempo)
27 (signal 'missing-test-dependency "org-tempo"))
29 (ert-deftest test-org-tempo/completion ()
30 "Test that blocks and keywords are expanded correctly by org-tempo."
31 ;; Tempo completion should recognize snippet keywords and expand with tab
32 (should
33 (equal (org-test-with-temp-text "<L<point>"
34 (org-tempo-setup)
35 (tempo-complete-tag)
36 (buffer-string))
37 "#+latex: "))
38 ;; Tempo completion should recognize snippet Blocks
39 (should
40 (equal (org-test-with-temp-text "<l<point>"
41 (org-tempo-setup)
42 (call-interactively 'org-cycle)
43 (buffer-string))
44 "#+begin_export latex\n\n#+end_export"))
45 ;; Tab should work for expansion.
46 (should
47 (equal (org-test-with-temp-text "<L<point>"
48 (org-tempo-setup)
49 (tempo-complete-tag)
50 (buffer-string))
51 (org-test-with-temp-text "<L<point>"
52 (org-tempo-setup)
53 (org-cycle)
54 (buffer-string))))
55 ;; Tempo should not expand unknown snippets
56 (equal (org-test-with-temp-text "<k"
57 (org-tempo-setup)
58 (call-interactively 'org-cycle)
59 (buffer-string))
60 "<k"))
62 (ert-deftest test-org-tempo/space-first-line ()
63 "Test space on first line after expansion."
64 ;; Normal blocks should have no space at the end of the first line.
65 (should (zerop
66 (org-test-with-temp-text "<l<point>"
67 (org-tempo-setup)
68 (tempo-complete-tag)
69 (goto-char (point-min))
70 (end-of-line)
71 (skip-chars-backward " "))))
72 ;; src blocks, export blocks and keywords should have one space at
73 ;; the end of the first line.
74 (should (cl-every (apply-partially 'eq 1)
75 (mapcar (lambda (s)
76 (org-test-with-temp-text (format "<%s<point>" s)
77 (org-tempo-setup)
78 (tempo-complete-tag)
79 (goto-char (point-min))
80 (end-of-line)
81 (abs (skip-chars-backward " "))))
82 '("s" "E" "L")))))
84 (ert-deftest test-org-tempo/cursor-placement ()
85 "Test the placement of the cursor after tempo expand"
86 ;; Normal blocks place point "inside" block.
87 (should
88 (eq (org-test-with-temp-text "<l<point>"
89 (org-tempo-setup)
90 (tempo-complete-tag)
91 (point))
92 (length "#\\+begin_export latex\n")))
93 ;; Special block stop at end of #+begin line.
94 (should
95 (eq (org-test-with-temp-text "<s<point>"
96 (org-tempo-setup)
97 (tempo-complete-tag)
98 (point))
99 (length "#\\+begin_src "))))
101 (ert-deftest test-org-tempo/add-new-templates ()
102 "Test that new structures and keywords are added correctly."
103 ;; New blocks should be added.
104 (should
105 (let ((org-structure-template-alist '(("n" . "new_block"))))
106 (org-tempo-add-templates)
107 (assoc "<l" org-tempo-tags)))
108 ;; New keys should be added.
109 (should
110 (let ((org-tempo-keywords-alist '(("N" . "new_keyword"))))
111 (org-tempo-add-templates)
112 (assoc "<N" org-tempo-tags))))
114 (provide 'test-org-tempo)
115 ;;; test-org-tempo.el end here