mirror of
https://github.com/Raimondi/delimitMate.git
synced 2026-02-28 20:42:31 +08:00
Fix Tests() and a couple other fucntions.
This commit is contained in:
@@ -304,13 +304,13 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! delimitMate#BS() " {{{
|
function! delimitMate#BS() " {{{
|
||||||
if delimitMate#WithinEmptyPair()
|
if delimitMate#WithinEmptyPair()
|
||||||
call delimitMate#RmBuffer(1)
|
"call delimitMate#RmBuffer(1)
|
||||||
return "\<BS>\<Del>"
|
return "\<BS>" . delimitMate#Del()
|
||||||
" return "\<Right>\<BS>\<BS>"
|
" return "\<Right>\<BS>\<BS>"
|
||||||
elseif b:delimitMate_expand_cr &&
|
elseif b:delimitMate_expand_cr &&
|
||||||
\ (delimitMate#IsCRExpansion() != 0 || delimitMate#IsSpaceExpansion())
|
\ (delimitMate#IsCRExpansion() != 0 || delimitMate#IsSpaceExpansion())
|
||||||
call delimitMate#RmBuffer(1)
|
"call delimitMate#RmBuffer(1)
|
||||||
return "\<BS>\<Del>"
|
return "\<BS>" . delimitMate#Del
|
||||||
else
|
else
|
||||||
return "\<BS>"
|
return "\<BS>"
|
||||||
endif
|
endif
|
||||||
@@ -534,56 +534,120 @@ function! delimitMate#Tests() " {{{
|
|||||||
DelimitMateReload
|
DelimitMateReload
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! Test(name, input, output, options) " {{{
|
function! Type(name, input, output, options) " {{{
|
||||||
" Set default options:
|
" Set default options:
|
||||||
call SetOptions(a:options)
|
call SetOptions(a:options)
|
||||||
normal ggVG"_d
|
normal ggVG"_d
|
||||||
exec "normal i" . a:input . "|"
|
exec "normal i" . a:input . "|\<Esc>"
|
||||||
call setpos('.', [0, 1, 1, 0])
|
call setpos('.', [0, 1, 1, 0])
|
||||||
|
let result = len(a:output) != line('$')
|
||||||
for line in a:output
|
for line in a:output
|
||||||
if getline('.') == line
|
if getline('.') != line || result == 1
|
||||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed'"
|
let result = 1
|
||||||
else
|
break
|
||||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . getline('.')"
|
|
||||||
endif
|
endif
|
||||||
call setpos('.', [0, line('.') + 1, 1, 0])
|
call setpos('.', [0, line('.') + 1, 1, 0])
|
||||||
endfor
|
endfor
|
||||||
|
let text = getline('.')
|
||||||
|
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") . "'] = 'Passed: ' . text . ' == ' . join(a:output, '<cr>')"
|
||||||
|
else
|
||||||
|
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||||
|
endif
|
||||||
|
endfunction " }}}
|
||||||
|
|
||||||
|
function! RepeatLast(name, output) " {{{
|
||||||
|
normal gg.
|
||||||
|
call setpos('.', [0, 1, 1, 0])
|
||||||
|
let result = len(a:output) != line('$')
|
||||||
|
for line in a:output
|
||||||
|
echom line . " vs " . getline('.')
|
||||||
|
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>')"
|
||||||
|
else
|
||||||
|
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||||
|
endif
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" Test's test
|
" Test's test
|
||||||
"call Test("Test", "(\<Space>", ["( | )"], ["expand_space:1"])
|
call Type("Test 1", "123", ["123|"], [])
|
||||||
|
call RepeatLast("Test 1", ["123|123|"])
|
||||||
|
|
||||||
|
|
||||||
" Auto-closing parens
|
" Auto-closing parens
|
||||||
call Test("Autoclose parens", "(", ["(|)"], [])
|
call Type("Autoclose parens", "(", ["(|)"], [])
|
||||||
|
call RepeatLast("Autoclose_parens", ["(|)(|)"])
|
||||||
|
|
||||||
" Auto-closing quotes
|
" Auto-closing quotes
|
||||||
call Test("Autoclose quotes", '"', ['"|"'], [])
|
call Type("Autoclose quotes", '"', ['"|"'], [])
|
||||||
|
call RepeatLast("Autoclose_quotes", ['"|""|"'])
|
||||||
|
|
||||||
" Deleting parens
|
" Deleting parens
|
||||||
call Test("Delete empty parens", "(\<BS>", ["|"], [])
|
call Type("Delete empty parens", "(\<BS>", ["|"], [])
|
||||||
|
call RepeatLast("Delete empty parens", ["||"])
|
||||||
|
|
||||||
" Deleting quotes
|
" Deleting quotes
|
||||||
call Test("Delete emtpy quotes", "\"\<BS>", ['|'], [])
|
call Type("Delete emtpy quotes", "\"\<BS>", ['|'], [])
|
||||||
|
call RepeatLast("Delete empty quotes", ["||"])
|
||||||
|
|
||||||
" Manual closing parens
|
" Manual closing parens
|
||||||
call Test("Manual closing parens", "()", ["(|)"], ["autoclose:0"])
|
call Type("Manual closing parens", "()", ["(|)"], ["autoclose:0"])
|
||||||
|
call RepeatLast("Manual closing parens", ["(|)(|)"])
|
||||||
|
|
||||||
" Manual closing quotes
|
" Manual closing quotes
|
||||||
call Test("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"])
|
call Type("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"])
|
||||||
|
call RepeatLast("Manual closing quotes", ['"|""|"'])
|
||||||
|
|
||||||
" Jump over paren
|
" Jump over paren
|
||||||
call Test("Jump over paren", "()", ['()|'], [])
|
call Type("Jump over paren", "()", ['()|'], [])
|
||||||
|
call RepeatLast("Jump over paren", ['()|()|'])
|
||||||
|
|
||||||
" Jump over quote
|
" Jump over quote
|
||||||
call Test("Jump over quote", "\"\"", ['""|'], [])
|
call Type("Jump over quote", "\"\"", ['""|'], [])
|
||||||
|
call RepeatLast("Jump over quote", ['""|""|'])
|
||||||
|
|
||||||
|
" Apostrophe
|
||||||
|
call Type("Apostrophe", "test'", ["test'|"], [])
|
||||||
|
call RepeatLast("Apostrophe", ["test'|test'|"])
|
||||||
|
|
||||||
|
" Close quote
|
||||||
|
call Type("Close quote", "'\<Del>\<Esc>a'", ["'|'"], [])
|
||||||
|
|
||||||
|
" <S-Tab>
|
||||||
|
call Type("S Tab", "(\<S-Tab>", ["()|"], [])
|
||||||
|
call RepeatLast("S Tab", ["()|()|"])
|
||||||
|
|
||||||
|
" Space expansion
|
||||||
|
call Type("Space expansion", "(\<Space>)", ['( | )'], ['expand_space:1'])
|
||||||
|
call RepeatLast("Space expansion", ['( | )( | )'])
|
||||||
|
|
||||||
|
" Car return expansion
|
||||||
|
call Type("CR expansion", "(\<CR>", ['(', '|', ')'], ['expand_cr:1'])
|
||||||
|
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'])
|
||||||
|
|
||||||
" Show results:
|
" Show results:
|
||||||
normal ggVG"_d
|
normal ggVG"_d
|
||||||
call append(0, split(string(b:test_results)[1:-2], ', '))
|
call append(0, split(string(b:test_results)[1:-2], ', '))
|
||||||
normal "_ddgg
|
normal "_ddgg
|
||||||
nmap <ESC> :q!<CR>
|
nmap <F1> :q!<CR>
|
||||||
let @/ = "Failed:"
|
let @/ = "Failed:.*!="
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user