123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- (require 'org-test)
- (ert-deftest test-org-src/basic ()
- "Editing regular block works, with point on source block."
- (org-test-with-temp-text
- "
- <point>#+begin_src emacs-lisp
- (message hello)
- #+end_src
- "
- (let ((org-edit-src-content-indentation 2)
- (org-src-preserve-indentation nil))
- (org-edit-special)
- (insert "blah")
- (org-edit-src-exit)
- (should (equal (buffer-string) "
- #+begin_src emacs-lisp
- blah(message hello)
- #+end_src
- "))
- (should (looking-at-p "(message hello)")))))
- (ert-deftest test-org-src/point-outside-block ()
- "Editing with point before/after block signals expected error."
- (org-test-with-temp-text
- "
- #+begin_src emacs-lisp
- (message hello)
- #+end_src
- "
- (goto-line 1)
- (should-error (org-edit-special))
- (goto-char (point-max))
- (should-error (org-edit-special))))
- (ert-deftest test-org-src/empty-block ()
- "Editing empty block."
- (org-test-with-temp-text
- "
- <point>#+begin_src emacs-lisp
- #+end_src
- "
- (let ((org-edit-src-content-indentation 0)
- (org-src-preserve-indentation nil))
- (org-edit-special)
- (insert "blah")
- (org-edit-src-exit)
- (should (equal (buffer-string) "
- #+begin_src emacs-lisp
- blah
- #+end_src
- "))
- (should
- (equal (buffer-substring (line-beginning-position) (point)) "blah")))))
- (ert-deftest test-org-src/blank-line-block ()
- "Editing block with just a blank line."
- (org-test-with-temp-text-in-file
- "
- #+begin_src emacs-lisp
- #+end_src
- "
- (let ((org-edit-src-content-indentation 2)
- (org-src-preserve-indentation nil))
- (goto-line 2)
- (org-edit-special)
- (insert "blah")
- (org-edit-src-exit)
- (should (equal (buffer-string) "
- #+begin_src emacs-lisp
- blah
- #+end_src
- ")))))
- (ert-deftest test-org-src/preserve-tabs ()
- "Editing block preserve tab characters."
-
- (should
- (equal "
- #+begin_src emacs-lisp
- This is a tab:\t.
- #+end_src"
- (org-test-with-temp-text
- "
- #+begin_src emacs-lisp
- <point>This is a tab:\t.
- #+end_src"
- (let ((org-edit-src-content-indentation 2)
- (org-src-preserve-indentation nil))
- (org-edit-special)
- (org-edit-src-exit)
- (buffer-string)))))
-
- (should
- (equal "
- #+begin_src emacs-lisp
- This is a tab:\t.
- #+end_src"
- (org-test-with-temp-text
- "
- #+begin_src emacs-lisp
- <point>This is a tab:\t.
- #+end_src"
- (let ((org-edit-src-content-indentation 2)
- (org-src-preserve-indentation t))
- (org-edit-special)
- (org-edit-src-exit)
- (buffer-string))))))
- (ert-deftest test-org-src/coderef-format ()
- "Test `org-src-coderef-format' specifications."
-
-
- (should
- (equal "foo"
- (let ((org-coderef-label-format "foo"))
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (org-src-coderef-format)))))
- (should
- (equal "foo"
- (let ((org-coderef-label-format "foo"))
- (org-test-with-temp-text "#+BEGIN_EXAMPLE\n0\n#+END_EXAMPLE"
- (org-src-coderef-format)))))
- (should
- (equal "foo"
- (let ((org-coderef-label-format "foo") result)
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (org-edit-special)
- (setq result (org-src-coderef-format))
- (org-edit-src-exit)
- result))))
-
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo"))
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "bar")
- (org-src-coderef-format)))))
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo") result)
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "bar")
- (org-edit-special)
- (setq result (org-src-coderef-format))
- (org-edit-src-exit)
- result))))
-
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo"))
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (org-src-coderef-format)))))
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo") result)
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (org-edit-special)
- (setq result (org-src-coderef-format))
- (org-edit-src-exit)
- result))))
-
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo"))
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "foo")
- (org-src-coderef-format)))))
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo") result)
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "foo")
- (org-edit-special)
- (setq result (org-src-coderef-format))
- (org-edit-src-exit)
- result))))
-
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo")
- (element (org-element-create 'src-block '(:label-fmt "bar"))))
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (org-src-coderef-format element)))))
- (should
- (equal "baz"
- (let ((org-coderef-label-format "foo")
- (element (org-element-create 'src-block '(:label-fmt "baz"))))
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "foo")
- (org-src-coderef-format element)))))
-
-
- (should
- (equal "foo"
- (let ((org-coderef-label-format "foo")
- (element (org-element-create 'src-block)))
- (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n0\n#+END_SRC"
- (org-src-coderef-format element)))))
- (should
- (equal "bar"
- (let ((org-coderef-label-format "foo")
- (element (org-element-create 'src-block)))
- (org-test-with-temp-text
- "#+BEGIN_SRC emacs-lisp -l \"bar\"\n0\n#+END_SRC"
- (setq-local org-coderef-label-format "foo")
- (org-src-coderef-format element))))))
- (ert-deftest test-org-src/coderef-regexp ()
- "Test `org-src-coderef-regexp' specifications."
-
- (should
- (string-match-p (org-src-coderef-regexp "; ref:%s")
- "#+BEGIN_SRC emacs-lisp\n0; ref:label\n#+END_SRC"))
-
- (should
- (string-match-p (org-src-coderef-regexp "; ref:%s")
- "#+BEGIN_SRC emacs-lisp\n0 ; ref:label\n#+END_SRC"))
- (should
- (string-match-p (org-src-coderef-regexp "; ref:%s")
- "#+BEGIN_SRC emacs-lisp\n0 ; ref:label \n#+END_SRC"))
-
- (should-not
- (string-match-p (org-src-coderef-regexp "; ref:%s")
- "#+BEGIN_SRC emacs-lisp\n0; ref:label (+ 1 2)\n#+END_SRC"))
-
- (should-not
- (string-match-p (org-src-coderef-regexp "; ref:%s")
- "#+BEGIN_SRC emacs-lisp\n0; ref:\n#+END_SRC"))
-
- (should
- (string-match-p (org-src-coderef-regexp "; ref:%s" "label")
- "#+BEGIN_SRC emacs-lisp\n0; ref:label\n#+END_SRC"))
- (should-not
- (string-match-p (org-src-coderef-regexp "; ref:%s" "label2")
- "#+BEGIN_SRC emacs-lisp\n0; ref:label\n#+END_SRC")))
- (provide 'test-org-src)
|