test-org-tempo.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ;;; test-org-tempo.el --- Tests for test-org-tempo.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017, 2019 Rasmus Pank Roulund
  3. ;; Author: Rasmus Pank Roulund <emacs at pank dot eu>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'org-tempo)
  17. (unless (featurep 'org-tempo)
  18. (signal 'missing-test-dependency "org-tempo"))
  19. (ert-deftest test-org-tempo/completion ()
  20. "Test that blocks and keywords are expanded correctly by org-tempo."
  21. ;; Tempo completion should recognize snippet keywords and expand with tab
  22. (should
  23. (equal (org-test-with-temp-text "<L<point>"
  24. (org-tempo-setup)
  25. (tempo-complete-tag)
  26. (buffer-string))
  27. "#+latex: "))
  28. ;; Tempo completion should recognize snippet Blocks
  29. (should
  30. (equal (org-test-with-temp-text "<l<point>"
  31. (org-tempo-setup)
  32. (call-interactively 'org-cycle)
  33. (buffer-string))
  34. "#+begin_export latex\n\n#+end_export"))
  35. ;; Tab should work for expansion.
  36. (should
  37. (equal (org-test-with-temp-text "<L<point>"
  38. (org-tempo-setup)
  39. (tempo-complete-tag)
  40. (buffer-string))
  41. (org-test-with-temp-text "<L<point>"
  42. (org-tempo-setup)
  43. (org-cycle)
  44. (buffer-string))))
  45. ;; Tempo should not expand unknown snippets
  46. (equal (org-test-with-temp-text "<k"
  47. (org-tempo-setup)
  48. (call-interactively 'org-cycle)
  49. (buffer-string))
  50. "<k"))
  51. (ert-deftest test-org-tempo/space-first-line ()
  52. "Test space on first line after expansion."
  53. ;; Normal blocks should have no space at the end of the first line.
  54. (should (zerop
  55. (org-test-with-temp-text "<l<point>"
  56. (org-tempo-setup)
  57. (tempo-complete-tag)
  58. (goto-char (point-min))
  59. (end-of-line)
  60. (skip-chars-backward " "))))
  61. ;; src blocks, export blocks and keywords should have one space at
  62. ;; the end of the first line.
  63. (should (cl-every (apply-partially 'eq 1)
  64. (mapcar (lambda (s)
  65. (org-test-with-temp-text (format "<%s<point>" s)
  66. (org-tempo-setup)
  67. (tempo-complete-tag)
  68. (goto-char (point-min))
  69. (end-of-line)
  70. (abs (skip-chars-backward " "))))
  71. '("s" "E" "L")))))
  72. (ert-deftest test-org-tempo/cursor-placement ()
  73. "Test the placement of the cursor after tempo expand"
  74. ;; Normal blocks place point "inside" block.
  75. (should
  76. (eq (org-test-with-temp-text "<l<point>"
  77. (org-tempo-setup)
  78. (tempo-complete-tag)
  79. (point))
  80. (length "#\\+begin_export latex\n")))
  81. ;; Special block stop at end of #+begin line.
  82. (should
  83. (eq (org-test-with-temp-text "<s<point>"
  84. (org-tempo-setup)
  85. (tempo-complete-tag)
  86. (point))
  87. (length "#\\+begin_src "))))
  88. (ert-deftest test-org-tempo/add-new-templates ()
  89. "Test that new structures and keywords are added correctly."
  90. ;; New blocks should be added.
  91. (should
  92. (let ((org-structure-template-alist '(("n" . "new_block"))))
  93. (org-tempo-add-templates)
  94. (assoc "<l" org-tempo-tags)))
  95. ;; New keys should be added.
  96. (should
  97. (let ((org-tempo-keywords-alist '(("N" . "new_keyword"))))
  98. (org-tempo-add-templates)
  99. (assoc "<N" org-tempo-tags))))
  100. (provide 'test-org-tempo)
  101. ;;; test-org-tempo.el end here