Simplify tests.

This commit is contained in:
Israel Chauca Fuentes
2017-01-22 14:10:29 -05:00
parent 50d97fd76e
commit b99ecfa2e3
11 changed files with 443 additions and 438 deletions

View File

@@ -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('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after' let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
set bs=2 set bs=2
set hidden
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
let g:delimitMate_quotes = '" '' ` « |'
ru plugin/delimitMate.vim ru plugin/delimitMate.vim
let runVimTests = expand('<sfile>:p:h').'/build/runVimTests' let runVimTests = expand('<sfile>:p:h').'/build/runVimTests'
if isdirectory(runVimTests) if isdirectory(runVimTests)
@@ -10,3 +25,89 @@ if isdirectory(vimTAP)
let &rtp = vimTAP . ',' . &rtp let &rtp = vimTAP . ',' . &rtp
endif 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("\<Esc>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

View File

@@ -1,51 +0,0 @@
let g:delimitMate_autoclose = 1
"(x" "(x)"
"(\<BS>x" "x"
"()x" "()x"
"((\<C-G>gx" "(())x"
"(x\<Esc>u" ""
"@(x" "@(x)"
"@#\<Left>(x" "@(x)#"
"(\<S-Tab>x" "()x"
let g:delimitMate_autoclose = 0
"(x" "(x"
"()x" "(x)"
"())x" "()x"
"()\<BS>x" "x"
"@()x" "@(x)"
"@#\<Left>()x" "@(x)#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"(\<Space>x" "( x )"
"(\<Space>\<BS>x" "(x)"
let g:delimitMate_autoclose = 0
"()\<Space>\<BS>x" "(x)"
let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"(\<Esc>a\<BS>x" "(x)"
set bs=2
# closing parens removes characters. #133
"(a\<Esc>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(\<BS>" "abc;"
# Expand iabbreviations
unlet b:delimitMate_eol_marker
iabb def ghi
"def(" "ghi()"
iunabb def
"abc а\<Left>(" "abc (а"
"abc ñ\<Left>(" "abc (ñ"
"abc $\<Left>(" "abc ($"
"abc £\<Left>(" "abc (£"
"abc d\<Left>(" "abc (d"
"abc \<C-V>(\<Left>(" "abc (("
"abc .\<Left>(" "abc ()."
"abc \<Left>(" "abc () "

View File

@@ -1,42 +1,78 @@
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::' " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
let lines = readfile(expand('<sfile>:t:r').'.txt') " - 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 vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"''')) call vimtap#Plan(217)
let itemsnumber = len(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'))
call vimtap#Plan(testsnumber * itemsnumber) let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
let tcount = 1 let g:delimitMate_autoclose = 1
let reload = 1 DelimitMateReload
for item in lines call DMTest_pairs('', "(x", "(x)")
if item =~ '^#\|^\s*$' call DMTest_pairs('', "(\<BS>x", "x")
" A comment or empty line. call DMTest_pairs('', "()x", "()x")
continue call DMTest_pairs('', "((\<C-G>gx", "(())x")
endif call DMTest_pairs('', "(x\<Esc>u", "")
if item !~ '^"' call DMTest_pairs('', "@(x", "@(x)")
" A command. call DMTest_pairs('', "@#\<Left>(x", "@(x)#")
exec item call DMTest_pairs('', "(\<S-Tab>x", "()x")
call vimtap#Diag(item) let g:delimitMate_autoclose = 0
let reload = 1 DelimitMateReload
continue call DMTest_pairs('', "(x", "(x")
endif call DMTest_pairs('', "()x", "(x)")
if reload call DMTest_pairs('', "())x", "()x")
DelimitMateReload call DMTest_pairs('', "()\<BS>x", "x")
call vimtap#Diag('DelimitMateReload') call DMTest_pairs('', "@()x", "@(x)")
let reload = 0 call DMTest_pairs('', "@#\<Left>()x", "@(x)#")
endif let g:delimitMate_expand_space = 1
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"') let g:delimitMate_autoclose = 1
for [s:l,s:r] in map(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'), 'split(v:val, ''.\zs:\ze.'')') DelimitMateReload
let input2 = substitute(input, '(', s:l, 'g') call DMTest_pairs('', "(\<Space>x", "( x )")
let input2 = substitute(input2, ')', s:r, 'g') call DMTest_pairs('', "(\<Space>\<BS>x", "(x)")
let output2 = substitute(output, '(', s:l, 'g') let g:delimitMate_autoclose = 0
let output2 = substitute(output2, ')', s:r, 'g') DelimitMateReload
%d call DMTest_pairs('', "()\<Space>\<BS>x", "(x)")
exec 'normal i'.eval(input2)."\<Esc>" let g:delimitMate_autoclose = 1
let line = getline('.') DelimitMateReload
let passed = line == eval(output2) " Handle backspace gracefully.
call vimtap#Is(line, eval(output2), input2) set backspace=
", input2 . ' => ' . string(line) . call DMTest_pairs('', "(\<Esc>a\<BS>x", "(x)")
" \ (passed ? ' =' : ' !') . '= ' . string(eval(output2))) set bs=2
let tcount += 1 " closing parens removes characters. #133
endfor call DMTest_pairs('', "(a\<Esc>i)", "()a)")
endfor
" 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(\<BS>", "abc;")
" Expand iabbreviations
unlet b:delimitMate_eol_marker
DelimitMateReload
iabb def ghi
call DMTest_pairs('', "def(", "ghi()")
iunabb def
call DMTest_pairs('', "abc а\<Left>(", "abc (а")
call DMTest_pairs('', "abc ñ\<Left>(", "abc (ñ")
call DMTest_pairs('', "abc $\<Left>(", "abc ($")
call DMTest_pairs('', "abc £\<Left>(", "abc (£")
call DMTest_pairs('', "abc d\<Left>(", "abc (d")
call DMTest_pairs('', "abc \<C-V>(\<Left>(", "abc ((")
call DMTest_pairs('', "abc .\<Left>(", "abc ().")
call DMTest_pairs('', "abc \<Left>(", "abc () ")
" Play nice with undo.
call DMTest_pairs('', "a\<C-G>u(c)b\<C-O>u", "a")
call vimtest#Quit() call vimtest#Quit()

View File

@@ -1,73 +0,0 @@
let g:delimitMate_autoclose = 1
"'x" "'x'"
"'x\<Esc>u" ""
"''x" "''x"
"'\<BS>x" "x"
"'\<C-G>gx" "''x"
# This will fail for double quote.
"'\"x" "'\"x\"'"
"@'x" "@'x'"
"@#\<Left>'x" "@'x'#"
"'\<S-Tab>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"
"''\<BS>x" "x"
"@''x" "@'x'"
"@#\<Left>''x" "@'x'#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"'\<Space>x" "' x'"
let g:delimitMate_expand_inside_quotes = 1
"'\<Space>x" "' x '"
"'\<Space>\<BS>x" "'x'"
"abc\\''\<Space>x" "abc\\' x'"
let g:delimitMate_autoclose = 0
"''\<Space>\<BS>x" "'x'"
let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"'\<Esc>a\<BS>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\<space>b\<left>'" "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
"}\<Home>'" "''}"
"'\<Del>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
"'\<CR>\<BS>" "''"

View File

@@ -1,47 +1,104 @@
"let g:delimitMate_quotes = '" '' ` ” « |' " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
let g:delimitMate_quotes = '" '' ` « |' " - Runs a single test.
let lines = readfile(expand('<sfile>:t:r').'.txt') " - 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 vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"''')) call vimtap#Plan(230)
let itemsnumber = len(split(g:delimitMate_quotes, ' '))
call vimtap#Plan(testsnumber * itemsnumber) let g:delimitMate_quotes = '" '' ` « |'
let reload = 1 let g:delimitMate_autoclose = 1
let tcount = 1 DelimitMateReload
let linenr = 0 call DMTest_quotes('', "'x", "'x'")
for item in lines call DMTest_quotes('', "'x\<Esc>u", "")
let linenr += 1 call DMTest_quotes('', "''x", "''x")
if item =~ '^#\|^\s*$' call DMTest_quotes('', "'\<BS>x", "x")
" A comment or empty line. call DMTest_quotes('', "'\<C-G>gx", "''x")
continue " This will fail for double quote.
endif call DMTest_quotes('', "'\"x", "'\"x\"'", "a:typed == '\"\"x'")
if item !~ '^"' call DMTest_quotes('', "@'x", "@'x'")
" A command. call DMTest_quotes('', "@#\<Left>'x", "@'x'#")
exec item call DMTest_quotes('', "'\<S-Tab>x", "''x")
call vimtap#Diag(item) call DMTest_quotes('', "abc'", "abc'")
let reload = 1 call DMTest_quotes('', "abc\\'x", "abc\\'x")
continue call DMTest_quotes('', "u'Привет'", "u'Привет'")
endif call DMTest_quotes('', "u'string'", "u'string'")
if reload let g:delimitMate_autoclose = 0
DelimitMateReload DelimitMateReload
call vimtap#Diag('DelimitMateReload') call DMTest_quotes('', "'x", "'x")
let reload = 0 call DMTest_quotes('', "''x", "'x'")
endif call DMTest_quotes('', "'''x", "''x")
let quotes = split(g:delimitMate_quotes, '\s') call DMTest_quotes('', "''\<BS>x", "x")
for quote in quotes call DMTest_quotes('', "@''x", "@'x'")
if vimtap#Skip(1, tcount != 26, "This test is invalid for double quote.") call DMTest_quotes('', "@#\<Left>''x", "@'x'#")
let tcount += 1 let g:delimitMate_expand_space = 1
continue let g:delimitMate_autoclose = 1
endif DelimitMateReload
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"') call DMTest_quotes('', "'\<Space>x", "' x'")
let input_q = substitute(input,"'" , escape(escape(quote, '"'), '\'), 'g') let g:delimitMate_expand_inside_quotes = 1
let output_q = substitute(output,"'" , escape(escape(quote, '"'), '\'), 'g') DelimitMateReload
%d call DMTest_quotes('', "'\<Space>x", "' x '")
exec 'normal i'.eval(input_q)."\<Esc>" call DMTest_quotes('', "'\<Space>\<BS>x", "'x'")
if quote == '”' call DMTest_quotes('', "abc\\''\<Space>x", "abc\\' x'")
call vimtap#Todo(1) let g:delimitMate_autoclose = 0
endif DelimitMateReload
call vimtap#Is(getline('.'), eval(output_q), 'Line '.linenr.': '.eval(substitute(input_q, '\\<', '<','g'))) call DMTest_quotes('', "''\<Space>\<BS>x", "'x'")
let tcount += 1 let g:delimitMate_autoclose = 1
endfor DelimitMateReload
endfor " Handle backspace gracefully.
set backspace=
call DMTest_quotes('', "'\<Esc>a\<BS>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\<space>b\<left>'", "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('', "}\<Home>'", "''}")
call DMTest_quotes('', "'\<Del>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('', "'\<CR>\<BS>", "''")
call vimtest#Quit() call vimtest#Quit()

View File

@@ -1,44 +1,43 @@
let g:delimitMate_expand_cr = 1 " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
let g:delimitMate_eol_marker = ';' " - 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 vimtest#StartTap()
call vimtap#Plan(8) call vimtap#Plan(8)
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
" NOTE: Do not forget to update the plan ^ " NOTE: Do not forget to update the plan ^
let g:delimitMate_insert_eol_marker = 0 let g:delimitMate_insert_eol_marker = 0
DelimitMateReload DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', 'value = 1, case 1') call DMTest_single('', '(', '()')
%d _
exec "normal i(\<CR>x" call DMTest_single('', "(\<CR>x", ['(', 'x', ')'])
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n)$', ' "normal i(\<CR>x", Value = 2, case 2')
let g:delimitMate_insert_eol_marker = 1 let g:delimitMate_insert_eol_marker = 1
DelimitMateReload DelimitMateReload
%d _ call DMTest_single('', '(', '();')
normal i(
call vimtap#Is(getline(1), '();', '"normal i(", value = 1, case 1') call DMTest_single('', "(\<CR>x", ['(', 'x', ');'])
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _
let g:delimitMate_insert_eol_marker = 2 let g:delimitMate_insert_eol_marker = 2
DelimitMateReload DelimitMateReload
normal i( call DMTest_single('', '(', '()')
call vimtap#Is(getline(1), '()', '"normal i(", Value = 2, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _ call DMTest_single('', "(\<CR>x", ['(', 'x', ');'])
exec "normal i{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 3')
%d _ call DMTest_single('', "{(\<CR>x", ['{(', 'x', ')};'])
exec "normal i;\<Esc>I{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"), call DMTest_single('', ";\<Esc>I{(\<CR>x", ['{(', 'x', ')};'])
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 4')
" End: quit vim. " End: quit vim.
call vimtest#Quit() call vimtest#Quit()

View File

@@ -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\<CR>x\<Esc>"
================================================================================
$(document).ready(function() {
x
})
--------------------------------------------------------------------------------
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i(\<CR>test)x"
================================================================================
(
test
)x
--------------------------------------------------------------------------------
# Remove CR expansion on BS
%d
exec "normal i(\<CR>\<BS>x"
================================================================================
(x)
--------------------------------------------------------------------------------
# Consider indentation with BS inside an empty CR expansion.
%d
exec "normal i( \<CR>\<BS>\<BS>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 {\<CR>x"
================================================================================
abc {
x
}
--------------------------------------------------------------------------------
# expand_cr != 2
%d_
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x)
--------------------------------------------------------------------------------
# expand_cr == 2
%d_
let delimitMate_expand_cr = 2
DelimitMateReload
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x
)
--------------------------------------------------------------------------------
# Play nice with smartindent
%d_
set all&
set smartindent
exec "normal $i{\<CR>x"
================================================================================
{
x
}
--------------------------------------------------------------------------------

View File

@@ -1,55 +1,94 @@
let g:delimitMate_expand_cr = 1 " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
"DelimitMateReload " - Runs a single test.
let lines = readfile(expand('<sfile>:t:r').'.txt') " - Add 1 to vimtap#Plan().
call vimtest#StartTap() "
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$''')) " function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]])
call vimtap#Plan(testsnumber) " - Runs one test for every pair.
let tcount = 1 " - Add 7 to vimtap#Plan().
let expect = 0 "
let evaluate = 0 " function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]])
let commands = [] " - Runs one test for every quote.
let header = '' " - Add 5 to vimtap#Plan().
for item in lines
if item =~ '^=\{80}$' call vimtest#StartTap()
let expect = 1 call vimtap#Plan(25)
let expected = []
continue let g:delimitMate_expand_cr = 1
endif 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() {})',
\ "\<Esc>31|i\<CR>x\<Esc>",
\ ["$(document).ready(function() {", " x", "})"])
" Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
call DMTest_single('', "(\<CR>test)x",
\ ['(', 'test', ')x'])
" Remove CR expansion on BS
call DMTest_single('', "(\<CR>\<BS>x",
\ ['(x)'])
" Consider indentation with BS inside an empty CR expansion.
call DMTest_single('', "( \<CR>\<BS>\<BS>x", '(x)')
" Conflict with indentation settings (cindent). Issue #95
se cindent
call DMTest_single(
\ ['sub foo {',
\ ' while (1) {',
\ ' ',
\ ' }',
\ '}'],
\ "\<Esc>3G8|a}x",
\ ['sub foo {',
\ ' while (1) {',
\ ' ',
\ ' }x',
\ '}'])
call DMTest_single('"{bracketed}', "\<Esc>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 {\<CR>x",
\['abc {',
\ ' x',
\ '}'])
" expand_cr != 2
call DMTest_single('abc(def)', "\<Esc>$i\<CR>x",
\ ['abc(def',
\ ' x)'])
" expand_cr == 2
let delimitMate_expand_cr = 2
DelimitMateReload
call DMTest_single('abc(def)', "\<Esc>$i\<CR>x", ['abc(def', ' x', ' )'])
" Play nice with smartindent
set all&
set smartindent
call DMTest_single('', "\<Esc>$i{\<CR>x", ['{', ' x', '}'])
call DMTest_quotes('', "' x", "' x'")
call DMTest_quotes('', "'\<CR>x", ["'", "x'"])
let delimitMate_expand_inside_quotes = 1
DelimitMateReload
call DMTest_quotes('', "'\<CR>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() call vimtest#Quit()

View File

@@ -1,8 +0,0 @@
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i( test)x"
================================================================================
( test )x
--------------------------------------------------------------------------------

View File

@@ -1,42 +1,29 @@
let g:delimitMate_expand_space = 1 " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
"DelimitMateReload " - Runs a single test.
let lines = readfile(expand('<sfile>:t:r').'.txt') " - Add 1 to vimtap#Plan().
call vimtest#StartTap() "
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$''')) " function! DMTest_pairs(setup, typed, expected, [skip_expr[, todo_expr]])
call vimtap#Plan(testsnumber) " - Runs one test for every pair.
let tcount = 1 " - Add 7 to vimtap#Plan().
let expect = 0 "
let evaluate = 0 " function! DMTest_quotes(setup, typed, expected, [skip_expr[, todo_expr]])
for item in lines " - Runs one test for every quote.
if item =~ '^=\{80}$' " - Add 5 to vimtap#Plan().
let expect = 1
let expected = [] call vimtest#StartTap()
continue call vimtap#Plan(12)
endif
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() call vimtest#Quit()

View File

@@ -1,7 +1,21 @@
let g:delimitMate_expand_cr = 1 " function! DMTest_single(setup, typed, expected[, skip_expr[, todo_expr]])
let g:delimitMate_eol_marker = ';' " - 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 vimtest#StartTap()
call vimtap#Plan(1) call vimtap#Plan(1)
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
DelimitMateReload
call vimtap#Like(maparg('(', 'i'), '<Plug>delimitMate(', 'Mappings defined for the first buffer without filetype set.') call vimtap#Like(maparg('(', 'i'), '<Plug>delimitMate(', 'Mappings defined for the first buffer without filetype set.')
call vimtest#Quit() call vimtest#Quit()