diff --git a/test/_setup.vim b/test/_setup.vim index 7d0a31f..8ebfc4b 100644 --- a/test/_setup.vim +++ b/test/_setup.vim @@ -1,5 +1,20 @@ +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + let &rtp = expand(':p:h:h') . ',' . &rtp . ',' . expand(':p:h:h') . '/after' set bs=2 +set hidden +let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::' +let g:delimitMate_quotes = '" '' ` « |' ru plugin/delimitMate.vim let runVimTests = expand(':p:h').'/build/runVimTests' if isdirectory(runVimTests) @@ -10,3 +25,89 @@ if isdirectory(vimTAP) let &rtp = vimTAP . ',' . &rtp endif +function! s:setup_buffer(buf_content) + "silent DelimitMateReload "call delimitMate#setup() + silent %d_ + if !empty(a:buf_content) + call setline(1, a:buf_content) + call feedkeys("\gg0", 'ntx') + endif +endfunction + +"function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" Runs a single test (add 1 to vimtap#Plan()) +function! DMTest_single(setup, typed, expected, ...) + if type(a:setup) == v:t_list + let setup = copy(a:setup) + else + let setup = [a:setup] + endif + if type(a:expected) == v:t_list + let expected = copy(a:expected) + else + let expected = [a:expected] + endif + let skip_expr = a:0 && !empty(a:1) ? a:1 : 0 + let todo_expr = a:0 > 1 && !empty(a:2) ? a:2 : 0 + if vimtap#Skip(1, !eval(skip_expr), skip_expr) + return + elseif eval(todo_expr) + call vimtap#Todo(1) + endif + call s:setup_buffer(setup) + call feedkeys('i', 'nt') + call feedkeys(a:typed, 'mt') + call feedkeys('', 'ntx') + call vimtap#Is(getline(1,'$'), expected, strtrans(a:typed)) +endfunction + +function! s:do_set(pat, sub, set, setup, typed, expected, ...) + let skip_expr = get(a:, '1', '') + let todo_expr = get(a:, '2', '') + let escaped = '\.*^$' + for elem in a:set + if type(a:setup) == v:t_list + let setup = copy(a:setup) + else + let setup = [a:setup] + endif + if type(a:expected) == v:t_list + let expected = copy(a:expected) + else + let expected = [a:expected] + endif + if len(split(elem, '\zs')) > 1 + let [left, right] = map(split(elem, '\zs'), 'escape(v:val, escaped)') + let sub = a:sub + else + let quote = escape(elem, escaped) + let sub = eval(a:sub) + endif + call map(setup, "substitute(v:val, a:pat, sub, 'g')") + let typed = substitute(a:typed, a:pat, sub, 'g') + call map(expected, "substitute(v:val, a:pat, sub, 'g')") + call DMTest_single(setup, typed, expected, skip_expr, todo_expr) + endfor +endfunction + +"function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" Runs one test for every pair (add 7 to vimtap#Plan()) +function! DMTest_pairs(setup, typed, expected, ...) + let skip_expr = get(a:, '1', '') + let todo_expr = get(a:, '2', '') + let pairs = ['()','{}','[]','<>','¿?','¡!',',:'] "delimitMate#options('pairs') + let pat = '[()]' + let sub = '\=submatch(0) == "(" ? left : right' + return s:do_set(pat, sub, pairs, a:setup, a:typed, a:expected, skip_expr, todo_expr) +endfunction + +"function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" Runs one test for every quote (add 5 to vimtap#Plan()) +function! DMTest_quotes(setup, typed, expected, ...) + let skip_expr = get(a:, '1', '') + let todo_expr = get(a:, '2', '') + let quotes = ['"', "'", '`', '«', '|'] "delimitMate#options('quotes') + let pat = "'" + let sub = 'quote' + return s:do_set(pat, sub, quotes, a:setup, a:typed, a:expected, skip_expr, todo_expr) +endfunction diff --git a/test/autoclose_matchpairs.txt b/test/autoclose_matchpairs.txt deleted file mode 100644 index df5f61b..0000000 --- a/test/autoclose_matchpairs.txt +++ /dev/null @@ -1,51 +0,0 @@ -let g:delimitMate_autoclose = 1 -"(x" "(x)" -"(\x" "x" -"()x" "()x" -"((\gx" "(())x" -"(x\u" "" -"@(x" "@(x)" -"@#\(x" "@(x)#" -"(\x" "()x" -let g:delimitMate_autoclose = 0 -"(x" "(x" -"()x" "(x)" -"())x" "()x" -"()\x" "x" -"@()x" "@(x)" -"@#\()x" "@(x)#" -let g:delimitMate_expand_space = 1 -let g:delimitMate_autoclose = 1 -"(\x" "( x )" -"(\\x" "(x)" -let g:delimitMate_autoclose = 0 -"()\\x" "(x)" -let g:delimitMate_autoclose = 1 -# Handle backspace gracefully. -set backspace= -"(\a\x" "(x)" -set bs=2 -# closing parens removes characters. #133 -"(a\i)" "()a)" - -# Add semicolon next to the closing paren. Issue #77. -new -let b:delimitMate_eol_marker = ';' -"abc(x" "abc(x);" -%d -# BS should behave accordingly. -"abc(\" "abc;" -# Expand iabbreviations -unlet b:delimitMate_eol_marker -iabb def ghi -"def(" "ghi()" -iunabb def - -"abc а\(" "abc (а" -"abc ñ\(" "abc (ñ" -"abc $\(" "abc ($" -"abc £\(" "abc (£" -"abc d\(" "abc (d" -"abc \(\(" "abc ((" -"abc .\(" "abc ()." -"abc \(" "abc () " diff --git a/test/autoclose_matchpairs.vim b/test/autoclose_matchpairs.vim index faa69a9..e94ce02 100644 --- a/test/autoclose_matchpairs.vim +++ b/test/autoclose_matchpairs.vim @@ -1,42 +1,78 @@ -let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::' -let lines = readfile(expand(':t:r').'.txt') +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + call vimtest#StartTap() -let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"''')) -let itemsnumber = len(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.')) -call vimtap#Plan(testsnumber * itemsnumber) -let tcount = 1 -let reload = 1 -for item in lines - if item =~ '^#\|^\s*$' - " A comment or empty line. - continue - endif - if item !~ '^"' - " A command. - exec item - call vimtap#Diag(item) - let reload = 1 - continue - endif - if reload - DelimitMateReload - call vimtap#Diag('DelimitMateReload') - let reload = 0 - endif - let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"') - for [s:l,s:r] in map(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'), 'split(v:val, ''.\zs:\ze.'')') - let input2 = substitute(input, '(', s:l, 'g') - let input2 = substitute(input2, ')', s:r, 'g') - let output2 = substitute(output, '(', s:l, 'g') - let output2 = substitute(output2, ')', s:r, 'g') - %d - exec 'normal i'.eval(input2)."\" - let line = getline('.') - let passed = line == eval(output2) - call vimtap#Is(line, eval(output2), input2) - ", input2 . ' => ' . string(line) . - " \ (passed ? ' =' : ' !') . '= ' . string(eval(output2))) - let tcount += 1 - endfor -endfor +call vimtap#Plan(217) + +let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::' +let g:delimitMate_autoclose = 1 +DelimitMateReload +call DMTest_pairs('', "(x", "(x)") +call DMTest_pairs('', "(\x", "x") +call DMTest_pairs('', "()x", "()x") +call DMTest_pairs('', "((\gx", "(())x") +call DMTest_pairs('', "(x\u", "") +call DMTest_pairs('', "@(x", "@(x)") +call DMTest_pairs('', "@#\(x", "@(x)#") +call DMTest_pairs('', "(\x", "()x") +let g:delimitMate_autoclose = 0 +DelimitMateReload +call DMTest_pairs('', "(x", "(x") +call DMTest_pairs('', "()x", "(x)") +call DMTest_pairs('', "())x", "()x") +call DMTest_pairs('', "()\x", "x") +call DMTest_pairs('', "@()x", "@(x)") +call DMTest_pairs('', "@#\()x", "@(x)#") +let g:delimitMate_expand_space = 1 +let g:delimitMate_autoclose = 1 +DelimitMateReload +call DMTest_pairs('', "(\x", "( x )") +call DMTest_pairs('', "(\\x", "(x)") +let g:delimitMate_autoclose = 0 +DelimitMateReload +call DMTest_pairs('', "()\\x", "(x)") +let g:delimitMate_autoclose = 1 +DelimitMateReload +" Handle backspace gracefully. +set backspace= +call DMTest_pairs('', "(\a\x", "(x)") +set bs=2 +" closing parens removes characters. #133 +call DMTest_pairs('', "(a\i)", "()a)") + +" Add semicolon next to the closing paren. Issue #77. +new +let b:delimitMate_eol_marker = ';' +DelimitMateReload +call DMTest_pairs('', "abc(x", "abc(x);") +" BS should behave accordingly. +call DMTest_pairs('', "abc(\", "abc;") +" Expand iabbreviations +unlet b:delimitMate_eol_marker +DelimitMateReload +iabb def ghi +call DMTest_pairs('', "def(", "ghi()") +iunabb def + +call DMTest_pairs('', "abc а\(", "abc (а") +call DMTest_pairs('', "abc ñ\(", "abc (ñ") +call DMTest_pairs('', "abc $\(", "abc ($") +call DMTest_pairs('', "abc £\(", "abc (£") +call DMTest_pairs('', "abc d\(", "abc (d") +call DMTest_pairs('', "abc \(\(", "abc ((") +call DMTest_pairs('', "abc .\(", "abc ().") +call DMTest_pairs('', "abc \(", "abc () ") + +" Play nice with undo. +call DMTest_pairs('', "a\u(c)b\u", "a") + call vimtest#Quit() diff --git a/test/autoclose_quotes.txt b/test/autoclose_quotes.txt deleted file mode 100644 index 02c002b..0000000 --- a/test/autoclose_quotes.txt +++ /dev/null @@ -1,73 +0,0 @@ -let g:delimitMate_autoclose = 1 -"'x" "'x'" -"'x\u" "" -"''x" "''x" -"'\x" "x" -"'\gx" "''x" -# This will fail for double quote. -"'\"x" "'\"x\"'" -"@'x" "@'x'" -"@#\'x" "@'x'#" -"'\x" "''x" -"abc'" "abc'" -"abc\\'x" "abc\\'x" -"u'Привет'" "u'Привет'" -"u'string'" "u'string'" -let g:delimitMate_autoclose = 0 -"'x" "'x" -"''x" "'x'" -"'''x" "''x" -"''\x" "x" -"@''x" "@'x'" -"@#\''x" "@'x'#" -let g:delimitMate_expand_space = 1 -let g:delimitMate_autoclose = 1 -"'\x" "' x'" -let g:delimitMate_expand_inside_quotes = 1 -"'\x" "' x '" -"'\\x" "'x'" -"abc\\''\x" "abc\\' x'" -let g:delimitMate_autoclose = 0 -"''\\x" "'x'" -let g:delimitMate_autoclose = 1 -# Handle backspace gracefully. -set backspace= -"'\a\x" "'x'" -set backspace=2 -set cpo=ces$ -"'x" "'x'" -# Make sure smart quote works beyond first column. -" 'x" " 'x'" -# smart quote, check fo char on the right. -"a\b\'" "a 'b" -# Make sure we jump over a quote on the right. #89. -"('test'x" "('test'x)" -# Duplicate whole line when inserting quote at bol #105 -"}\'" "''}" -"'\abc '" "'abc '" -"''abc '" "''abc ''" -# Nesting quotes: -let g:delimitMate_nesting_quotes = split(g:delimitMate_quotes, '\s\+') -"'''x" "'''x'''" -"''''x" "''''x''''" -"''x" "''x" -"'x" "'x'" -unlet g:delimitMate_nesting_quotes -# expand iabbreviations -iabb def ghi -"def'" "ghi'" -let g:delimitMate_smart_quotes = '\w\%#\_.' -"xyz'x" "xyz'x" -"xyz 'x" "xyz 'x'" -let g:delimitMate_smart_quotes = '\s\%#\_.' -"abc'x" "abc'x'" -"abc 'x" "abc 'x" -# let's try the negated form -let g:delimitMate_smart_quotes = '!\w\%#\_.' -"cba'x" "cba'x'" -"cba 'x" "cba 'x" -let g:delimitMate_smart_quotes = '!\s\%#\_.' -"zyx'x" "zyx'x" -"zyx 'x" "zyx 'x'" -unlet g:delimitMate_smart_quotes -"'\\" "''" diff --git a/test/autoclose_quotes.vim b/test/autoclose_quotes.vim index e80c60c..69ef615 100644 --- a/test/autoclose_quotes.vim +++ b/test/autoclose_quotes.vim @@ -1,47 +1,104 @@ -"let g:delimitMate_quotes = '" '' ` ” « |' -let g:delimitMate_quotes = '" '' ` « |' -let lines = readfile(expand(':t:r').'.txt') +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + call vimtest#StartTap() -let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"''')) -let itemsnumber = len(split(g:delimitMate_quotes, ' ')) -call vimtap#Plan(testsnumber * itemsnumber) -let reload = 1 -let tcount = 1 -let linenr = 0 -for item in lines - let linenr += 1 - if item =~ '^#\|^\s*$' - " A comment or empty line. - continue - endif - if item !~ '^"' - " A command. - exec item - call vimtap#Diag(item) - let reload = 1 - continue - endif - if reload - DelimitMateReload - call vimtap#Diag('DelimitMateReload') - let reload = 0 - endif - let quotes = split(g:delimitMate_quotes, '\s') - for quote in quotes - if vimtap#Skip(1, tcount != 26, "This test is invalid for double quote.") - let tcount += 1 - continue - endif - let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"') - let input_q = substitute(input,"'" , escape(escape(quote, '"'), '\'), 'g') - let output_q = substitute(output,"'" , escape(escape(quote, '"'), '\'), 'g') - %d - exec 'normal i'.eval(input_q)."\" - if quote == '”' - call vimtap#Todo(1) - endif - call vimtap#Is(getline('.'), eval(output_q), 'Line '.linenr.': '.eval(substitute(input_q, '\\<', '<','g'))) - let tcount += 1 - endfor -endfor +call vimtap#Plan(230) + +let g:delimitMate_quotes = '" '' ` « |' +let g:delimitMate_autoclose = 1 +DelimitMateReload +call DMTest_quotes('', "'x", "'x'") +call DMTest_quotes('', "'x\u", "") +call DMTest_quotes('', "''x", "''x") +call DMTest_quotes('', "'\x", "x") +call DMTest_quotes('', "'\gx", "''x") +" This will fail for double quote. +call DMTest_quotes('', "'\"x", "'\"x\"'", "a:typed == '\"\"x'") +call DMTest_quotes('', "@'x", "@'x'") +call DMTest_quotes('', "@#\'x", "@'x'#") +call DMTest_quotes('', "'\x", "''x") +call DMTest_quotes('', "abc'", "abc'") +call DMTest_quotes('', "abc\\'x", "abc\\'x") +call DMTest_quotes('', "u'Привет'", "u'Привет'") +call DMTest_quotes('', "u'string'", "u'string'") +let g:delimitMate_autoclose = 0 +DelimitMateReload +call DMTest_quotes('', "'x", "'x") +call DMTest_quotes('', "''x", "'x'") +call DMTest_quotes('', "'''x", "''x") +call DMTest_quotes('', "''\x", "x") +call DMTest_quotes('', "@''x", "@'x'") +call DMTest_quotes('', "@#\''x", "@'x'#") +let g:delimitMate_expand_space = 1 +let g:delimitMate_autoclose = 1 +DelimitMateReload +call DMTest_quotes('', "'\x", "' x'") +let g:delimitMate_expand_inside_quotes = 1 +DelimitMateReload +call DMTest_quotes('', "'\x", "' x '") +call DMTest_quotes('', "'\\x", "'x'") +call DMTest_quotes('', "abc\\''\x", "abc\\' x'") +let g:delimitMate_autoclose = 0 +DelimitMateReload +call DMTest_quotes('', "''\\x", "'x'") +let g:delimitMate_autoclose = 1 +DelimitMateReload +" Handle backspace gracefully. +set backspace= +call DMTest_quotes('', "'\a\x", "'x'") +set backspace=2 +set cpo=ces$ +call DMTest_quotes('', "'x", "'x'") +" Make sure smart quote works beyond first column. +call DMTest_quotes('', " 'x", " 'x'") +" smart quote, check fo char on the right. +call DMTest_quotes('', "a\b\'", "a 'b") +" Make sure we jump over a quote on the right. #89. +call DMTest_quotes('', "('test'x", "('test'x)") +" Duplicate whole line when inserting quote at bol #105 +call DMTest_quotes('', "}\'", "''}") +call DMTest_quotes('', "'\abc '", "'abc '") +call DMTest_quotes('', "''abc '", "''abc ''") +" Nesting quotes: +let g:delimitMate_nesting_quotes = split(g:delimitMate_quotes, '\s\+') +DelimitMateReload +call DMTest_quotes('', "'''x", "'''x'''") +call DMTest_quotes('', "''''x", "''''x''''") +call DMTest_quotes('', "''x", "''x") +call DMTest_quotes('', "'x", "'x'") +unlet g:delimitMate_nesting_quotes +DelimitMateReload +" expand iabbreviations +iabb def ghi +call DMTest_quotes('', "def'", "ghi'") +let g:delimitMate_smart_quotes = '\w\%#\_.' +DelimitMateReload +call DMTest_quotes('', "xyz'x", "xyz'x") +call DMTest_quotes('', "xyz 'x", "xyz 'x'") +let g:delimitMate_smart_quotes = '\s\%#\_.' +DelimitMateReload +call DMTest_quotes('', "abc'x", "abc'x'") +call DMTest_quotes('', "abc 'x", "abc 'x") +" let's try the negated form +let g:delimitMate_smart_quotes = '!\w\%#\_.' +DelimitMateReload +call DMTest_quotes('', "cba'x", "cba'x'") +call DMTest_quotes('', "cba 'x", "cba 'x") +let g:delimitMate_smart_quotes = '!\s\%#\_.' +DelimitMateReload +call DMTest_quotes('', "zyx'x", "zyx'x") +call DMTest_quotes('', "zyx 'x", "zyx 'x'") +unlet g:delimitMate_smart_quotes +DelimitMateReload +call DMTest_quotes('', "'\\", "''") + call vimtest#Quit() diff --git a/test/eol_marker.vim b/test/eol_marker.vim index d414355..276e8ea 100644 --- a/test/eol_marker.vim +++ b/test/eol_marker.vim @@ -1,44 +1,43 @@ -let g:delimitMate_expand_cr = 1 -let g:delimitMate_eol_marker = ';' +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + call vimtest#StartTap() call vimtap#Plan(8) + +let g:delimitMate_expand_cr = 1 +let g:delimitMate_eol_marker = ';' " NOTE: Do not forget to update the plan ^ let g:delimitMate_insert_eol_marker = 0 DelimitMateReload -normal i( -call vimtap#Is(getline(1), '()', 'value = 1, case 1') -%d _ -exec "normal i(\x" -call vimtap#Like(join(getline(1,line('$')), "\"), - \ '^(\n\s*x\n)$', ' "normal i(\x", Value = 2, case 2') + +call DMTest_single('', '(', '()') + +call DMTest_single('', "(\x", ['(', 'x', ')']) + let g:delimitMate_insert_eol_marker = 1 DelimitMateReload -%d _ -normal i( -call vimtap#Is(getline(1), '();', '"normal i(", value = 1, case 1') -%d _ -exec "normal i(\x" -call vimtap#Like(join(getline(1,line('$')), "\"), - \ '^(\n\s*x\n);$', '"normal i(\x", Value = 2, case 2') -%d _ +call DMTest_single('', '(', '();') + +call DMTest_single('', "(\x", ['(', 'x', ');']) + let g:delimitMate_insert_eol_marker = 2 DelimitMateReload -normal i( -call vimtap#Is(getline(1), '()', '"normal i(", Value = 2, case 1') -%d _ -exec "normal i(\x" -call vimtap#Like(join(getline(1,line('$')), "\"), - \ '^(\n\s*x\n);$', '"normal i(\x", Value = 2, case 2') +call DMTest_single('', '(', '()') -%d _ -exec "normal i{(\x" -call vimtap#Like(join(getline(1,line('$')), "\"), - \ '^{(\n\s*x\n)};$', ' "normal i{(\x", Value = 2, case 3') +call DMTest_single('', "(\x", ['(', 'x', ');']) -%d _ -exec "normal i;\I{(\x" -call vimtap#Like(join(getline(1,line('$')), "\"), - \ '^{(\n\s*x\n)};$', ' "normal i{(\x", Value = 2, case 4') +call DMTest_single('', "{(\x", ['{(', 'x', ')};']) + +call DMTest_single('', ";\I{(\x", ['{(', 'x', ')};']) " End: quit vim. call vimtest#Quit() diff --git a/test/expand_cr.txt b/test/expand_cr.txt deleted file mode 100644 index b7aa982..0000000 --- a/test/expand_cr.txt +++ /dev/null @@ -1,96 +0,0 @@ -# -%d -filetype indent on -set bs=2 et sts=4 sw=4 ft=javascript -call setline(1, '$(document).ready(function() {})') -DelimitMateReload -exec "normal 31|i\x\" -================================================================================ -$(document).ready(function() { - x -}) --------------------------------------------------------------------------------- -# Issue #95 -new -let b:delimitMate_jump_expansion = 1 -DelimitMateReload -exec "normal i(\test)x" -================================================================================ -( -test -)x --------------------------------------------------------------------------------- -# Remove CR expansion on BS -%d -exec "normal i(\\x" -================================================================================ -(x) --------------------------------------------------------------------------------- -# Consider indentation with BS inside an empty CR expansion. -%d -exec "normal i( \\\x" -================================================================================ -(x) --------------------------------------------------------------------------------- -# Conflict with indentation settings (cindent). Issue #95 -se cindent -call setline(1, ['sub foo {',' while (1) {', ' ', ' }', '}']) -call cursor(3, 8) -normal a}x -================================================================================ -sub foo { - while (1) { - - }x -} --------------------------------------------------------------------------------- -%d -call setline(1, '"{bracketed}') -normal A"x -================================================================================ -"{bracketed}"x --------------------------------------------------------------------------------- -# Syntax folding enabled by autocmd breaks expansion. But ti can't be tested -# with :normal -new -autocmd InsertEnter * let w:fdm=&foldmethod | setl foldmethod=manual -autocmd InsertLeave * let &foldmethod = w:fdm -set foldmethod=marker -set foldmarker={,} -set foldlevel=0 -set backspace=2 -exec "normal iabc {\x" -================================================================================ -abc { - x -} --------------------------------------------------------------------------------- -# expand_cr != 2 -%d_ -call setline(1, 'abc(def)') -exec "normal $i\x" -================================================================================ -abc(def - x) --------------------------------------------------------------------------------- -# expand_cr == 2 -%d_ -let delimitMate_expand_cr = 2 -DelimitMateReload -call setline(1, 'abc(def)') -exec "normal $i\x" -================================================================================ -abc(def - x - ) --------------------------------------------------------------------------------- -# Play nice with smartindent -%d_ -set all& -set smartindent -exec "normal $i{\x" -================================================================================ -{ - x -} --------------------------------------------------------------------------------- diff --git a/test/expand_cr.vim b/test/expand_cr.vim index bd4e32a..14748b5 100644 --- a/test/expand_cr.vim +++ b/test/expand_cr.vim @@ -1,55 +1,94 @@ -let g:delimitMate_expand_cr = 1 -"DelimitMateReload -let lines = readfile(expand(':t:r').'.txt') -call vimtest#StartTap() -let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$''')) -call vimtap#Plan(testsnumber) -let tcount = 1 -let expect = 0 -let evaluate = 0 -let commands = [] -let header = '' -for item in lines - if item =~ '^=\{80}$' - let expect = 1 - let expected = [] - continue - endif +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + +call vimtest#StartTap() +call vimtap#Plan(25) + +let g:delimitMate_expand_cr = 1 +DelimitMateReload +"let g:delimitMate_eol_marker = ';' +filetype indent on +set bs=2 et sts=4 sw=4 ft=javascript +call DMTest_single('$(document).ready(function() {})', + \ "\31|i\x\", + \ ["$(document).ready(function() {", " x", "})"]) + +" Issue #95 +new +let b:delimitMate_jump_expansion = 1 +DelimitMateReload +call DMTest_single('', "(\test)x", + \ ['(', 'test', ')x']) + +" Remove CR expansion on BS +call DMTest_single('', "(\\x", + \ ['(x)']) + +" Consider indentation with BS inside an empty CR expansion. +call DMTest_single('', "( \\\x", '(x)') + +" Conflict with indentation settings (cindent). Issue #95 +se cindent +call DMTest_single( + \ ['sub foo {', + \ ' while (1) {', + \ ' ', + \ ' }', + \ '}'], + \ "\3G8|a}x", + \ ['sub foo {', + \ ' while (1) {', + \ ' ', + \ ' }x', + \ '}']) + +call DMTest_single('"{bracketed}', "\A\"x", '"{bracketed}"x') + +" Syntax folding enabled by autocmd breaks expansion. But ti can't be tested +" with :normal +new +autocmd InsertEnter * let w:fdm=&foldmethod | setl foldmethod=manual +autocmd InsertLeave * let &foldmethod = w:fdm +set foldmethod=marker +set foldmarker={,} +set foldlevel=0 +set backspace=2 +call DMTest_single('', "abc {\x", + \['abc {', + \ ' x', + \ '}']) + +" expand_cr != 2 +call DMTest_single('abc(def)', "\$i\x", + \ ['abc(def', + \ ' x)']) + +" expand_cr == 2 +let delimitMate_expand_cr = 2 +DelimitMateReload +call DMTest_single('abc(def)', "\$i\x", ['abc(def', ' x', ' )']) + +" Play nice with smartindent +set all& +set smartindent +call DMTest_single('', "\$i{\x", ['{', ' x', '}']) + +call DMTest_quotes('', "' x", "' x'") + +call DMTest_quotes('', "'\x", ["'", "x'"]) + +let delimitMate_expand_inside_quotes = 1 +DelimitMateReload + +call DMTest_quotes('', "'\x", ["'", "x", "'"]) - if item =~ '^#' && expect == 0 - " A comment. - let header = empty(header) ? item[1:] : 'Lines should match.' - continue - endif - if item =~ '^\s*$' && expect == 0 - " An empty line. - continue - endif - if ! expect - " A command. - call add(commands, item) - exec item - "call vimtap#Diag(item) - continue - endif - if item =~ '^-\{80}$' - let expect = 0 - endif - if expect - call add(expected, item) - continue - endif - let lines = getline(1, line('$')) - let passed = lines == expected - echom string(lines) - echom string(expected) - call vimtap#Is(lines, expected, header) - echom string(commands) - for cmd in commands - call vimtap#Diag(cmd) - endfor - let commands = [] - let header = '' - let tcount += 1 -endfor call vimtest#Quit() diff --git a/test/expand_space.txt b/test/expand_space.txt deleted file mode 100644 index 39f8748..0000000 --- a/test/expand_space.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Issue #95 -new -let b:delimitMate_jump_expansion = 1 -DelimitMateReload -exec "normal i( test)x" -================================================================================ -( test )x --------------------------------------------------------------------------------- diff --git a/test/expand_space.vim b/test/expand_space.vim index d306721..0bf5e9b 100644 --- a/test/expand_space.vim +++ b/test/expand_space.vim @@ -1,42 +1,29 @@ -let g:delimitMate_expand_space = 1 -"DelimitMateReload -let lines = readfile(expand(':t:r').'.txt') -call vimtest#StartTap() -let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$''')) -call vimtap#Plan(testsnumber) -let tcount = 1 -let expect = 0 -let evaluate = 0 -for item in lines - if item =~ '^=\{80}$' - let expect = 1 - let expected = [] - continue - endif +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + +call vimtest#StartTap() +call vimtap#Plan(12) + +let g:delimitMate_expand_space = 1 +DelimitMateReload + +" Issue #95 +let b:delimitMate_jump_expansion = 1 +DelimitMateReload +call DMTest_pairs('', "( test)x", '( test )x') + +let delimitMate_expand_inside_quotes = 1 +DelimitMateReload + +call DMTest_quotes('', "' x", "' x '") - if item =~ '^#\|^\s*$' && expect == 0 - " A comment or empty line. - continue - endif - if ! expect - " A command. - exec item - call vimtap#Diag(item) - continue - endif - if item =~ '^-\{80}$' - let expect = 0 - endif - if expect - call add(expected, item) - continue - endif - let lines = getline(1, line('$')) - let passed = lines == expected - echom string(lines) - echom string(expected) - call vimtap#Ok(passed, string(expected) . - \ (passed ? ' =' : ' !') . '= ' . string(lines)) - let tcount += 1 -endfor call vimtest#Quit() diff --git a/test/first_buffer_no_ft.vim b/test/first_buffer_no_ft.vim index dc5225c..c646692 100644 --- a/test/first_buffer_no_ft.vim +++ b/test/first_buffer_no_ft.vim @@ -1,7 +1,21 @@ -let g:delimitMate_expand_cr = 1 -let g:delimitMate_eol_marker = ';' +" function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]]) +" - Runs a single test. +" - Add 1 to vimtap#Plan(). +" +" function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every pair. +" - Add 7 to vimtap#Plan(). +" +" function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]]) +" - Runs one test for every quote. +" - Add 5 to vimtap#Plan(). + call vimtest#StartTap() call vimtap#Plan(1) + +let g:delimitMate_expand_cr = 1 +let g:delimitMate_eol_marker = ';' +DelimitMateReload call vimtap#Like(maparg('(', 'i'), 'delimitMate(', 'Mappings defined for the first buffer without filetype set.') call vimtest#Quit()