All pastes #2569 Raw Edit

Vim Snippet to Keep Track of the Number of Tests in a Perl Test File

public text v1 · immutable
#2569 ·published 2004-12-02 11:30 UTC
rendered paste body
function! Perl_Tests_Count()
    " Position the cursor at the beginning of the file
    call cursor(1,1)
    " Count the number of lines which indicate a test
    let mycount = 0
    while (search("# \\+TEST", "W") > 0)
        let num_tests_to_add = 1
        let line_contents = getline(line("."))
        let multipliers = substitute(line_contents, "^.*# \\+TEST", "", "")
        let star_m = matchstr(multipliers, "^\\*\\d\\+")
        while (star_m != "")
            let multipliers = substitute(multipliers, "^\\*\\d\\+", "", "")
            let mult = substitute(star_m, "^\\*", "", "")
            let num_tests_to_add = num_tests_to_add * mult
            let star_m = matchstr(multipliers, "^\\*\\d\\+")
        endwhile
        
        let mycount = mycount + num_tests_to_add
    endwhile
    call cursor(1,1)
    call search("^use \\(Test::More\\|CondTestMore\\)","W")
    let line_contents = getline(line("."))
    let new_line_contents = substitute(line_contents, "\\d\\+", mycount, "")
    call setline(".", new_line_contents)
    " call setline(".", mycount)
endfunction