test-org-src.el 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; test-org-src.el --- tests for org-src.el
  2. ;; Copyright (C) 2012-2015 Le Wang
  3. ;; Author: Le Wang <l26wang at gmail dot com>
  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 <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'org-test)
  17. (ert-deftest test-org-src/basic ()
  18. "Editing regular block works, with point on source block."
  19. (org-test-with-temp-text
  20. "
  21. <point>#+begin_src emacs-lisp
  22. (message hello)
  23. #+end_src
  24. "
  25. (let ((org-edit-src-content-indentation 2)
  26. (org-src-preserve-indentation nil))
  27. (org-edit-special)
  28. (insert "blah")
  29. (org-edit-src-exit)
  30. (should (equal (buffer-string) "
  31. #+begin_src emacs-lisp
  32. blah(message hello)
  33. #+end_src
  34. "))
  35. (should (org-looking-at-p "(message hello)")))))
  36. (ert-deftest test-org-src/point-outside-block ()
  37. "Editing with point before/after block signals expected error."
  38. (org-test-with-temp-text
  39. "
  40. #+begin_src emacs-lisp
  41. (message hello)
  42. #+end_src
  43. "
  44. (goto-line 1)
  45. (should-error (org-edit-special))
  46. (goto-char (point-max))
  47. (should-error (org-edit-special))))
  48. (ert-deftest test-org-src/empty-block ()
  49. "Editing empty block."
  50. (org-test-with-temp-text
  51. "
  52. <point>#+begin_src emacs-lisp
  53. #+end_src
  54. "
  55. (let ((org-edit-src-content-indentation 0)
  56. (org-src-preserve-indentation nil))
  57. (org-edit-special)
  58. (insert "blah")
  59. (org-edit-src-exit)
  60. (should (equal (buffer-string) "
  61. #+begin_src emacs-lisp
  62. blah
  63. #+end_src
  64. "))
  65. (should
  66. (equal (buffer-substring (line-beginning-position) (point)) "blah")))))
  67. (ert-deftest test-org-src/blank-line-block ()
  68. "Editing block with just a blank line."
  69. (org-test-with-temp-text-in-file
  70. "
  71. #+begin_src emacs-lisp
  72. #+end_src
  73. "
  74. (let ((org-edit-src-content-indentation 2)
  75. (org-src-preserve-indentation nil))
  76. (goto-line 2)
  77. (org-edit-special)
  78. (insert "blah")
  79. (org-edit-src-exit)
  80. (should (equal (buffer-string) "
  81. #+begin_src emacs-lisp
  82. blah
  83. #+end_src
  84. ")))))
  85. (provide 'test-org-src)
  86. ;;; test-org-src.el ends here