Martyn Jago <martyn.j...@btinternet.com> writes: [...] > > (ert-deftest ob-tangle/speed-command-r () > (let ((org-use-speed-commands t)) > (with-temp-buffer > (org-mode) > (insert "* Speed command") > (goto-char (point-at-bol)) > ;; ensure default speed commands return t > (should (org-speed-command-default-hook "r")) > (should (org-speed-command-default-hook "n")) > > ;; ensure non-default speed commands return nil > (should-not (org-speed-command-default-hook "z")) > > ;; ensure default speed commands return nil if not at bol > (forward-char) > (should-not (org-speed-command-default-hook "r")) > > ;; ensure org-metaright promotes heading > (goto-char (point-at-bol)) > (org-metaright 1) > (goto-char (point-at-bol)) > (should (equal "** Speed command" (buffer-string))) > ;; ensure org-metaleft demotes heading > (org-metaleft 1) > (should (equal "* Speed command" (buffer-string))))))
As a minor note, I just added a simple convenience macro named `org-test-with-temp-text' [1] which should somewhat simplify the process of using temporary Org-mode buffers with initial text. Using this the above becomes #+begin_src emacs-lisp (ert-deftest ob-tangle/speed-command-r () (let ((org-use-speed-commands t)) (org-test-with-temp-text "* Speed command" ;; ensure default speed commands return t (should (org-speed-command-default-hook "r")) (should (org-speed-command-default-hook "n")) ;; ensure non-default speed commands return nil (should-not (org-speed-command-default-hook "z")) ;; ensure default speed commands return nil if not at bol (forward-char) (should-not (org-speed-command-default-hook "r")) ;; ensure org-metaright promotes heading (goto-char (point-at-bol)) (org-metaright 1) (goto-char (point-at-bol)) (should (equal "** Speed command" (buffer-string))) ;; ensure org-metaleft demotes heading (org-metaleft 1) (should (equal "* Speed command" (buffer-string)))))) #+end_src Cheers -- Eric Footnotes: [1] ,---- | org-test-with-temp-text is a Lisp macro in `org-test.el'. | | (org-test-with-temp-text TEXT &rest BODY) | | Run body in a temporary buffer with Org-mode as the active | mode holding TEXT. If the string "<point>" appears in TEXT | then remove it and place the point there before running BODY. `---- -- Eric Schulte http://cs.unm.edu/~eschulte/