test-org-src.el 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;;; test-org-src.el --- tests for org-src.el
  2. ;; Copyright (C) 2012, 2013, 2014 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. #+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. (goto-line 2)
  28. (org-edit-special)
  29. (insert "blah")
  30. (org-edit-src-exit)
  31. (should (equal (buffer-string) "
  32. #+begin_src emacs-lisp
  33. blah(message hello)
  34. #+end_src
  35. "))
  36. (should (equal (word-at-point) "blah")))))
  37. (ert-deftest test-org-src/point-outside-block ()
  38. "Editing with point before/after block signals expected error."
  39. (org-test-with-temp-text
  40. "
  41. #+begin_src emacs-lisp
  42. (message hello)
  43. #+end_src
  44. "
  45. (goto-line 1)
  46. (should-error (org-edit-special))
  47. (goto-char (point-max))
  48. (should-error (org-edit-special))))
  49. (ert-deftest test-org-src/empty-block ()
  50. "Editing empty block."
  51. (org-test-with-temp-text
  52. "
  53. #+begin_src emacs-lisp
  54. #+end_src
  55. "
  56. (let ((org-edit-src-content-indentation 2)
  57. (org-src-preserve-indentation nil))
  58. (goto-line 2)
  59. (org-edit-special)
  60. (insert "blah")
  61. (org-edit-src-exit)
  62. (should (equal (buffer-string) "
  63. #+begin_src emacs-lisp
  64. blah
  65. #+end_src
  66. "))
  67. (should (equal (word-at-point) "blah")))))
  68. (ert-deftest test-org-src/blank-line-block ()
  69. "Editing block with just a blank line."
  70. (org-test-with-temp-text-in-file
  71. "
  72. #+begin_src emacs-lisp
  73. #+end_src
  74. "
  75. (let ((org-edit-src-content-indentation 2)
  76. (org-src-preserve-indentation nil))
  77. (goto-line 2)
  78. (org-edit-special)
  79. (insert "blah")
  80. (org-edit-src-exit)
  81. (should (equal (buffer-string) "
  82. #+begin_src emacs-lisp
  83. blah
  84. #+end_src
  85. ")))))
  86. (provide 'test-org-src)
  87. ;;; test-org-src.el ends here