emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: emacs-orgmode@gnu.org
Subject: Re: [babel] Trying to add ERT test cases
Date: Tue, 20 Sep 2011 09:03:30 +0100	[thread overview]
Message-ID: <m27h53k5d9.fsf@btinternet.com> (raw)
In-Reply-To: 87ipoov7q3.fsf@gmail.com

Hi Eric 

Eric Schulte <schulte.eric@gmail.com> writes:

> Martyn Jago <martyn.jago@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.
> `----

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

  reply	other threads:[~2011-09-20  8:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19 11:20 [babel] Trying to add ERT test cases Sebastien Vauban
2011-09-19 14:35 ` Eric Schulte
2011-09-19 19:35   ` Sebastien Vauban
2011-09-19 21:32     ` Eric Schulte
2011-09-20  7:22       ` Sebastien Vauban
2011-09-19 15:46 ` Martyn Jago
2011-09-19 16:04   ` Eric Schulte
2011-09-20  8:03     ` Martyn Jago [this message]
2011-09-20 15:01       ` Eric Schulte
2011-09-21  4:18         ` Martyn Jago
2011-09-21 12:20           ` Eric Schulte
2011-09-19 19:43   ` Sebastien Vauban

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m27h53k5d9.fsf@btinternet.com \
    --to=martyn.jago@btinternet.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).