More changes to Tests.vim.

This commit is contained in:
Israel Chauca Fuentes
2010-05-13 18:00:51 -05:00
parent 03390cfb5f
commit b03d5dce36

View File

@@ -1,4 +1,4 @@
function! delimitMateTests#Main(known) " {{{
function! delimitMateTests#Main() " {{{
if !exists("g:delimitMate_testing")
echoerr "delimitMateTests#Main(): If you really want to use me, you must set delimitMate_testing to any value."
return
@@ -6,6 +6,8 @@ function! delimitMateTests#Main(known) " {{{
nmap <F1> :qall!<CR>
let b:test_results = {}
let b:errors = 0
let b:corrects = 0
let b:ignores = 0
function! SetOptions(list) " {{{
let b:delimitMate_autoclose = 1
@@ -26,11 +28,23 @@ function! delimitMateTests#Main(known) " {{{
DelimitMateReload
endfunction " }}}
function! Type(name, input, output, options) " {{{
" Set default options:
call SetOptions(a:options)
normal ggVG"_d
exec "normal i" . a:input . "|\<Esc>"
function! Type(name, input, output, options, ...) " {{{
if a:0 > 0
let ignore = a:1
else
let ignore = 0
endif
if a:input != "\<Esc>."
" Set default options:
call SetOptions(a:options)
let CapR = ""
normal ggVG"_d
exec "normal i" . a:input . "|\<Esc>"
else
let CapR = "_R"
normal gg.
endif
call setpos('.', [0, 1, 1, 0])
let result = len(a:output) != line('$')
for line in a:output
@@ -46,37 +60,32 @@ function! delimitMateTests#Main(known) " {{{
let text = text . "<cr>" . getline(i)
let i += 1
endwhile
if result == 0
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed: ' . a:input . ' => ' . text . ' == ' . join(a:output, '<cr>')"
if ignore == 1
let label = "Ignored"
let result = "?="
let b:ignores += 1
elseif result == 0
let label = "Passed"
let result = "=="
let b:corrects += 1
else
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . a:input . ' => ' . text . ' != ' . join(a:output, '<cr>')"
let label = "Failed"
let result = "!="
let b:errors += 1
endif
exec "let b:test_results['" .
\ substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . CapR . "'] = '" .
\ label . ": ' . a:input . ' => ' . text . ' " .
\ result . " ' . join(a:output, '<cr>')"
endfunction " }}}
function! RepeatLast(name, output) " {{{
normal gg.
call setpos('.', [0, 1, 1, 0])
let result = len(a:output) != line('$')
for line in a:output
if getline('.') != line || result == 1
let result = 1
break
endif
call setpos('.', [0, line('.') + 1, 1, 0])
endfor
let text = getline('1')
let i = 2
while i <= line('$')
let text = text . "<cr>" . getline(i)
let i += 1
endwhile
if result == 0
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Passed: \".\" => ' . text . ' == ' . join(a:output, '<cr>')"
function! RepeatLast(name, output, ...) " {{{
if a:0 > 0
let arg1 = a:1
else
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Failed: \".\" => ' . text . ' != ' . join(a:output, '<cr>')"
let b:errors += 1
let arg1 = ''
endif
call Type(a:name, "\<Esc>.", a:output, [], arg1)
endfunction " }}}
" Test's test {{{
@@ -139,35 +148,35 @@ function! delimitMateTests#Main(known) " {{{
" Car return expansion
call Type("CR expansion", "(\<CR>", ['(', '|', ')'], ['expand_cr:1'])
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'])
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'], 1)
" BS with car return expansion
call Type("BS with CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
call RepeatLast("BS with CR expansion", ['(|)(|)'])
call RepeatLast("BS with CR expansion", ['(|)(|)'], 1)
" Visual wrapping
call Type("Visual wrapping left paren", "1234\<Esc>v,(", ['123(4)'], ['visual_leader:","'])
cal RepeatLast("Visual wrapping left paren", ['(1)23(4)'])
cal RepeatLast("Visual wrapping left paren", ['(1)23(4)'], 1)
" Visual line wrapping
call Type("Visual line wrapping left paren", "1234\<Esc>V,(", ['(1234)'], ['visual_leader:","'])
cal RepeatLast("Visual line wrapping left paren", ['((1234))'])
cal RepeatLast("Visual line wrapping left paren", ['((1234))'], 1)
" Visual wrapping
call Type("Visual wrapping right paren", "1234\<Esc>v,)", ['123(4)'], ['visual_leader:","'])
cal RepeatLast("Visual wrapping right paren", ['(1)23(4)'])
cal RepeatLast("Visual wrapping right paren", ['(1)23(4)'], 1)
" Visual line wrapping
call Type("Visual line wrapping right paren", "1234\<Esc>V,)", ['(1234)'], ['visual_leader:","'])
cal RepeatLast("Visual line wrapping right paren", ['((1234))'])
cal RepeatLast("Visual line wrapping right paren", ['((1234))'], 1)
" Visual wrapping
call Type("Visual wrapping quote", "1234\<Esc>v,\"", ['123"4"'], ['visual_leader:","'])
cal RepeatLast("Visual wrapping quote", ['"1"23"4"'])
cal RepeatLast("Visual wrapping quote", ['"1"23"4"'], 1)
" Visual line wrapping
call Type("Visual line wrapping quote", "1234\<Esc>V,\"", ['"1234"'], ['visual_leader:","'])
cal RepeatLast("Visual line wrapping quote", ['""1234""'])
cal RepeatLast("Visual line wrapping quote", ['""1234""'], 1)
" Visual line wrapping empty line
call Type("Visual line wrapping paren empty line", "\<Esc>V,(", ['()'], ['visual_leader:","'])
@@ -193,11 +202,10 @@ function! delimitMateTests#Main(known) " {{{
" <Right-arrow> inserts text
call Type("<Right-arrow> inserts text", "(he\<Right>\<Space>th\<Right>\<Right>", ['(he) th|'], [])
call RepeatLast("Backspace inside space expansion", ['(|)(|)'])
" Backspace inside CR expansion
call Type("Backspace inside CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
call RepeatLast("Backspace inside CR expansion", ['(|)(|)'])
call RepeatLast("Backspace inside CR expansion", ['(|)(|)'], 1)
" FileType event
let g:delimitMate_excluded_ft = "vim"
@@ -208,20 +216,19 @@ function! delimitMateTests#Main(known) " {{{
" Duplicated delimiter after CR
call Type("Duplicated delimiter after CR", "(\<CR>", ['(', '|)'], [])
" Deactivate on comments
" Deactivate on comments: The first call to a closing delimiter
" will not work here as expected, but it does in real life tests.
set ft=vim
call Type("Deactivate on comments", "\"()``[]''\"\"", ["\"()``[]''\"\"|"], ["autoclose:0"])
call Type("Deactivate on comments", "\"()``[]''\"\"", ["\"()``[]''\"\"|"], ["autoclose:0"], 1)
set ft=
" Deactivate parens on comments
" Deactivate parens on comments: The first call to a closing delimiter
" will not work here as expected, but it does in real life tests.
set ft=vim
call Type("Deactivate parens on comments", "\"()", ["\"()"], ["autoclose:0"])
call Type("Deactivate parens on comments", "\"()", ["\"()"], ["autoclose:0"], 1)
set ft=
" Autoclose and beginning of line
call Type("Autoclose and beginning of line", "'\<Left>\<Left>\<Esc>i'", ["'|\"'"], ["autoclose:0"])
" Manual close at start of line
call Type("Manual close at start of line", "m)\<Left>\<Left>)", [')|m)'], ["autoclose:0"])
@@ -230,20 +237,23 @@ function! delimitMateTests#Main(known) " {{{
" Show results: {{{
normal ggVG"_d
call append(0, split(string(b:test_results)[1:-2], ', '))
call append(0, "*NEW BROKEN TESTS: " . (b:errors - a:known))
call append(0, "*TESTS REPORT: " . b:errors . " failed, " . b:corrects . " passed and " . b:ignores . " ignored.")
normal "_ddgg
let @/ = ".\\+Failed:.*!="
set nohlsearch
"syntax match failedLine "^.*Failed.*$" contains=ALL
"syn match passedLine ".*Passed.*"
syn match lineIgnored ".*Ignored.*"
syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
syn match resultPassed "\('Passed: \)\@<=.\+\('$\)\@="
syn match resultFailed "\('Failed: \)\@<=.\+\('$\)\@=" contains=resultInequal
syn match resultIgnored "\('Ignored: \)\@<=.\+\('$\)\@="
syn match resultInequal "!="
syn match resultSummary "^\*.\+" contains=resultSummaryNumber
syn match resultSummaryNumber "[1-9][0-9]*" contained
syn match resultSummaryNumber "[1-9][0-9]* failed*" contained
hi def link lineIgnored Ignore
hi def link labelPassed Comment
hi def link labelFailed Special
hi def link resultPassed Ignore