From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: Re: [babel] Trying to add ERT test cases Date: Tue, 20 Sep 2011 09:03:30 +0100 Message-ID: References: <80sjnswzh5.fsf@somewhere.org> <87ipoov7q3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:46366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5vKH-0001UE-DT for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 04:05:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5vKF-0006E1-OV for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 04:05:09 -0400 Received: from lo.gmane.org ([80.91.229.12]:49030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5vKF-0006DA-Bx for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 04:05:07 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R5vKE-00065g-Hq for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 10:05:06 +0200 Received: from 88-96-171-142.dsl.zen.co.uk ([88.96.171.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 20 Sep 2011 10:05:06 +0200 Received: from martyn.jago by 88-96-171-142.dsl.zen.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 20 Sep 2011 10:05:06 +0200 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: emacs-orgmode@gnu.org Hi Eric Eric Schulte writes: > 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. > `---- 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