[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [babel] Trying to add ERT test cases
From: |
Martyn Jago |
Subject: |
Re: [O] [babel] Trying to add ERT test cases |
Date: |
Tue, 20 Sep 2011 09:03:30 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (darwin) |
Hi Eric
Eric Schulte <address@hidden> writes:
> Martyn Jago <address@hidden> 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.
> `----
This looks useful, however I hit problems when refactoring my tests to
use it. Would it be easy for your macro to accept string variables in
addition to strings?
Regards
Martyn
Re: [O] [babel] Trying to add ERT test cases, Sebastien Vauban, 2011/09/19