<?xml version="1.0" encoding="windows-1252"?>
<node id="566364" title="Toggling test plans with vim" created="2006-08-09 05:13:57" updated="2006-08-09 01:13:57">
<type id="120">
perlmeditation</type>
<author id="17000">
Ovid</author>
<data>
<field name="doctext">
&lt;P&gt;Posted to the Perl QA list, but I figure some of you might want this.&lt;/p&gt;

&lt;p&gt;For some strange reason, many folks seems to hate updating test plans.  I don't know why this seems like so much work, given what a tiny task it is compared to the bulk of the code, but basically, here's how it works.  You change this:&lt;/p&gt;

&lt;code&gt;    use Test::More tests =&gt; 13;&lt;/code&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;code&gt;    use Test::More tests =&gt; 'no_plan'; # tests =&gt; 13&lt;/code&gt;

&lt;p&gt;And when you're done, you change it back and update the test count.  Some people think this is too much work, so based upon some vim code [chromatic] had, I wrote the following plugin.  This could use a lot of work, but you might want to save this as &lt;tt&gt;~/.vim/plugin/ToggleTestPlan.vim&lt;/tt&gt;.&lt;/p&gt;

&lt;code&gt;    if exists( "toggle_test_plan" )
        finish
    endif
    let toggle_test_plan = 1

    map ,tp :call ToggleTestPlan()&lt;cr&gt;

    function ToggleTestPlan()
        call SavePosition()
        let curr_line = 1
        while curr_line &lt;= line("$")
            if match(getline(curr_line), 'More\s*tests') &gt; -1
                %s/More tests =&gt;/More 'no_plan'; # tests =&gt;/
                call RestorePosition()
            elseif match(getline(curr_line), 'More\s*''no_plan') &gt; -1
                %s/More 'no_plan';\s*# /More /
            endif
            let curr_line = curr_line + 1
        endwhile
    endfunction

    function SavePosition()
        let s:curLine = winline()
        let s:curColumn = wincol()
    endfunction

    function RestorePosition()
        exe s:curLine
        exe "normal! ".s:curColumn."|"
    endfunction&lt;/code&gt;

&lt;p&gt;Basically, that maps &lt;tt&gt;,tp&lt;/tt&gt; to &lt;tt&gt;ToggleTestPlan()&lt;/tt&gt; and toggles your test plan back and forth.  If you switch to &lt;tt&gt;'no_plan'&lt;/tt&gt;, it leaves your cursor where it is. If you switch to &lt;tt&gt;tests =&amp;gt; $num_tests&lt;/tt&gt;, it puts your cursor on the right line to change the test number.  I could add more, but since I'm such a vim scripting newbie, I figure others are better placed to fix other issues.  For example, the stuff for saving and restoring position were originally called like this (ganked from another plugin):&lt;/p&gt;

&lt;code&gt;    call &lt;SID&gt;SaveCursorPosition()&lt;/code&gt;

&lt;p&gt;And defined like this:&lt;/p&gt;

&lt;code&gt;  " SaveCursorPosition
  function! &lt;SID&gt;SaveCursorPosition()
    let s:curLine = winline()
    let s:curColumn = wincol()
  endfunction&lt;/code&gt;

&lt;p&gt;Why were they defined like that?  Who knows?  Any explanations and improvements appreciated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I now know why they were defined like that.  After I get home tonight, I'll do some more work and have a much better version of this code available.&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-17000"&gt;
&lt;p&gt;Cheers,&lt;br /&gt;
&lt;a href="/index.pl?node=Ovid&amp;lastnode_id=1072"&gt;Ovid&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;small&gt;New address of &lt;a href="http://users.easystreet.com/ovid/cgi_course/"&gt;my CGI Course&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
