emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sebastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
To: emacs-orgmode-mXXj517/zsQ@public.gmane.org
Subject: Re: [babel] Trying to add ERT test cases
Date: Mon, 19 Sep 2011 21:43:03 +0200	[thread overview]
Message-ID: <80aaa0wc6w.fsf@somewhere.org> (raw)
In-Reply-To: m2pqiwo7r2.fsf@btinternet.com

Hi Martyn,

Martyn Jago wrote:
> "Sebastien Vauban"
> <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>
>> * Test
>>
>> #+begin_src emacs-lisp
>> (ert-deftest ob-tangle/speed-command-r ()
>>   "Test that speed command `r' does demote the headline."
>>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>>     (goto-char (point-at-bol))
>>     (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
>>     (goto-char (point-at-bol))
>>     (should (looking-at "\\*\\* Speed command"))
>>     (delete-char 1)))
>> #+end_src
>>
>> Problems:
>>
>> - I want to simulate the user pressing `r', but `insert' does insert a literal
>>   `r', instead of executing what's associated to it.
>>
>>   Of course, I don't want to replace the key press on `r' but a call to
>>   `org-shiftright', that's the whole point of the test.
>>
>>   So, how can I insert a `r' character to be contextually interpreted?
>>
>> - when `should' is failing, the `delete-char' does not take place. This is
>>   still mysterious to me, at this point in time.
>>
>> Any hints for me to go further?
>
> My solution doesn't simulate pressing `r' as such (which looks like it
> will require some substantial setup), so I approached the test slightly
> differently...
>
>  - 1) Ensure =org-speed-command-default-hook= returns t when valid
>        (default) speed command and bol
>  - 2) Ensure actual speed command promotes correctly
>  - 3) Use a test-buffer (with org-mode enabled) to avoid messing with
>        test example
>
> There may be a better solution however.
>
> Best, Martyn
>
> (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))))))

Thanks a lot for teaching me such tricks.

However, I have the impression it's not entirely what I'd like to test for:
that the user pressing `r' makes the headline being demoted.

Here, if I understand you and the code correctly, you test that:

- `r', in the valid context, is a key bound to some speed command, but not
  especially the headline demotion;

- ...

- demotion and promotion do work, when called via their well-known command.

Of course, as you say, what I'm asking for is maybe just to complex to test.

And it does not remove anything from the need for the above test you just
wrote. Thanks a lot.

Best regards,
  Seb

-- 
Sebastien Vauban

      parent reply	other threads:[~2011-09-19 19:43 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
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 [this message]

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=80aaa0wc6w.fsf@somewhere.org \
    --to=wxhgmqzgwmuf-genee64ty+gs+fvcfc7uqw@public.gmane.org \
    --cc=emacs-orgmode-mXXj517/zsQ@public.gmane.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).