From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] Trying to add ERT test cases Date: Mon, 19 Sep 2011 10:04:52 -0600 Message-ID: <87ipoov7q3.fsf@gmail.com> References: <80sjnswzh5.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:34628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5gL7-0003xc-EQ for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 12:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5gL5-0003nX-T3 for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 12:05:01 -0400 Received: from mail-yx0-f169.google.com ([209.85.213.169]:63168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5gL5-0003nR-Nh for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 12:04:59 -0400 Received: by yxi19 with SMTP id 19so4979408yxi.0 for ; Mon, 19 Sep 2011 09:04:59 -0700 (PDT) In-Reply-To: (Martyn Jago's message of "Mon, 19 Sep 2011 16:46:09 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Martyn Jago Cc: emacs-orgmode@gnu.org Martyn Jago 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 "" appears in TEXT | then remove it and place the point there before running BODY. `---- -- Eric Schulte http://cs.unm.edu/~eschulte/