test-org-src.el 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; test-org-src.el --- tests for org-src.el
  2. ;; Copyright (C) 2012 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
  19. #+begin_src line
  20. "
  21. (org-test-with-temp-text
  22. "
  23. #+begin_src emacs-lisp
  24. (message hello)
  25. #+end_src
  26. "
  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. (goto-line 2)
  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 (equal (word-at-point) "blah"))))
  66. (ert-deftest test-org-src/blank-line-block ()
  67. "Editing block with just a blank line."
  68. (org-test-with-temp-text-in-file
  69. "
  70. #+begin_src emacs-lisp
  71. #+end_src
  72. "
  73. (goto-line 2)
  74. (org-edit-special)
  75. (insert "blah")
  76. (org-edit-src-exit)
  77. (should (equal (buffer-string) "
  78. #+begin_src emacs-lisp
  79. blah
  80. #+end_src
  81. "))))
  82. (provide 'test-org-src)
  83. ;;; test-org-src.el ends here