org-tempo.el: New file for expansion of templates
[org-mode.git] / testing / lisp / test-org-tempo.el
blob060a7da88dc0f2ec8c247825a8e3f3d0b4c1dab6
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-temp)
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/add-new-templates ()
63 "Test that new structures and keywords are added correctly."
64 ;; Check that deleted keys are not kept
65 (should
66 (let ((org-structure-template-alist '((?n . "new_block"))))
67 (org-tempo-add-templates)
68 (assoc "<n" org-tempo-tags)))
69 (should
70 (let ((org-tempo-keywords-alist '((?N . "new_keyword"))))
71 (org-tempo-add-templates)
72 (assoc "<N" org-tempo-tags))))
74 (provide 'test-org-tempo)
75 ;;; test-org-tempo.el end here