test-org-src.el 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. (require 'org-test)
  15. (ert-deftest test-org-src/basic ()
  16. "Editing regular block works. with point on
  17. #+begin_src line
  18. "
  19. (org-test-with-temp-text
  20. "
  21. #+begin_src emacs-lisp
  22. (message hello)
  23. #+end_src
  24. "
  25. (goto-line 2)
  26. (org-edit-special)
  27. (insert "blah")
  28. (org-edit-src-exit)
  29. (should (equal (buffer-string) "
  30. #+begin_src emacs-lisp
  31. blah(message hello)
  32. #+end_src
  33. "))
  34. (should (equal (word-at-point) "blah"))))
  35. (ert-deftest test-org-src/point-outside-block ()
  36. "Editing with point before/after block signals expected error."
  37. (org-test-with-temp-text
  38. "
  39. #+begin_src emacs-lisp
  40. (message hello)
  41. #+end_src
  42. "
  43. (goto-line 1)
  44. (should-error (org-edit-special))
  45. (goto-char (point-max))
  46. (should-error (org-edit-special))))
  47. (ert-deftest test-org-src/empty-block ()
  48. "Editing empty block."
  49. (org-test-with-temp-text
  50. "
  51. #+begin_src emacs-lisp
  52. #+end_src
  53. "
  54. (goto-line 2)
  55. (org-edit-special)
  56. (insert "blah")
  57. (org-edit-src-exit)
  58. (should (equal (buffer-string) "
  59. #+begin_src emacs-lisp
  60. blah
  61. #+end_src
  62. "))
  63. (should (equal (word-at-point) "blah"))))
  64. (ert-deftest test-org-src/blank-line-block ()
  65. "Editing block with just a blank line."
  66. (org-test-with-temp-text
  67. "
  68. #+begin_src emacs-lisp
  69. #+end_src
  70. "
  71. (goto-line 3)
  72. (org-edit-special)
  73. (insert "blah")
  74. (org-edit-src-exit)
  75. (should (equal (buffer-string) "
  76. #+begin_src emacs-lisp
  77. blah
  78. #+end_src
  79. "))
  80. (should (equal (word-at-point) "blah"))))
  81. (provide 'test-org-src)
  82. ;;; test-org-src.el ends here