From d478e751781d6f2fe2cb09ddfb27260f84e5a7bb Mon Sep 17 00:00:00 2001 From: Israel Chauca Fuentes Date: Wed, 5 May 2010 11:55:05 -0500 Subject: [PATCH] Fix Tests() and a couple other fucntions. --- autoload/delimitMate.vim | 108 +++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 22 deletions(-) diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 2a857db..d540008 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -304,13 +304,13 @@ endfunction "}}} function! delimitMate#BS() " {{{ if delimitMate#WithinEmptyPair() - call delimitMate#RmBuffer(1) - return "\\" + "call delimitMate#RmBuffer(1) + return "\" . delimitMate#Del() " return "\\\" elseif b:delimitMate_expand_cr && \ (delimitMate#IsCRExpansion() != 0 || delimitMate#IsSpaceExpansion()) - call delimitMate#RmBuffer(1) - return "\\" + "call delimitMate#RmBuffer(1) + return "\" . delimitMate#Del else return "\" endif @@ -534,56 +534,120 @@ function! delimitMate#Tests() " {{{ DelimitMateReload endfunction " }}} - function! Test(name, input, output, options) " {{{ + function! Type(name, input, output, options) " {{{ " Set default options: call SetOptions(a:options) normal ggVG"_d - exec "normal i" . a:input . "|" + exec "normal i" . a:input . "|\" call setpos('.', [0, 1, 1, 0]) + let result = len(a:output) != line('$') for line in a:output - if getline('.') == line - exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed'" - else - exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . getline('.')" + if getline('.') != line || result == 1 + let result = 1 + break endif call setpos('.', [0, line('.') + 1, 1, 0]) endfor + let text = getline('.') + let i = 2 + while i <= line('$') + let text = text . "" . 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, '')" + else + exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . text . ' != ' . join(a:output, '')" + 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 . "" . 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, '')" + else + exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Failed: ' . text . ' != ' . join(a:output, '')" + endif + endfunction " }}} + " Test's test - "call Test("Test", "(\", ["( | )"], ["expand_space:1"]) + call Type("Test 1", "123", ["123|"], []) + call RepeatLast("Test 1", ["123|123|"]) + " Auto-closing parens - call Test("Autoclose parens", "(", ["(|)"], []) + call Type("Autoclose parens", "(", ["(|)"], []) + call RepeatLast("Autoclose_parens", ["(|)(|)"]) " Auto-closing quotes - call Test("Autoclose quotes", '"', ['"|"'], []) + call Type("Autoclose quotes", '"', ['"|"'], []) + call RepeatLast("Autoclose_quotes", ['"|""|"']) " Deleting parens - call Test("Delete empty parens", "(\", ["|"], []) + call Type("Delete empty parens", "(\", ["|"], []) + call RepeatLast("Delete empty parens", ["||"]) " Deleting quotes - call Test("Delete emtpy quotes", "\"\", ['|'], []) + call Type("Delete emtpy quotes", "\"\", ['|'], []) + call RepeatLast("Delete empty quotes", ["||"]) " 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 - call Test("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"]) + call Type("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"]) + call RepeatLast("Manual closing quotes", ['"|""|"']) " Jump over paren - call Test("Jump over paren", "()", ['()|'], []) + call Type("Jump over paren", "()", ['()|'], []) + call RepeatLast("Jump over paren", ['()|()|']) " 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", "'\\a'", ["'|'"], []) + + " + call Type("S Tab", "(\", ["()|"], []) + call RepeatLast("S Tab", ["()|()|"]) + + " Space expansion + call Type("Space expansion", "(\)", ['( | )'], ['expand_space:1']) + call RepeatLast("Space expansion", ['( | )( | )']) + + " Car return expansion + call Type("CR expansion", "(\", ['(', '|', ')'], ['expand_cr:1']) + call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')']) " Show results: normal ggVG"_d call append(0, split(string(b:test_results)[1:-2], ', ')) normal "_ddgg - nmap :q! - let @/ = "Failed:" + nmap :q! + let @/ = "Failed:.*!=" endfunction " }}} "}}}