mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 13:14:35 +08:00
Simplify tests.
This commit is contained in:
101
test/_setup.vim
101
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('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
|
||||
set bs=2
|
||||
set hidden
|
||||
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
|
||||
let g:delimitMate_quotes = '" '' ` « |'
|
||||
ru plugin/delimitMate.vim
|
||||
let runVimTests = expand('<sfile>: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("\<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
|
||||
|
||||
@@ -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 () "
|
||||
@@ -1,42 +1,78 @@
|
||||
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
|
||||
let lines = readfile(expand('<sfile>: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
|
||||
call vimtap#Plan(217)
|
||||
|
||||
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
|
||||
let g:delimitMate_autoclose = 1
|
||||
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)."\<Esc>"
|
||||
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 DMTest_pairs('', "(x", "(x)")
|
||||
call DMTest_pairs('', "(\<BS>x", "x")
|
||||
call DMTest_pairs('', "()x", "()x")
|
||||
call DMTest_pairs('', "((\<C-G>gx", "(())x")
|
||||
call DMTest_pairs('', "(x\<Esc>u", "")
|
||||
call DMTest_pairs('', "@(x", "@(x)")
|
||||
call DMTest_pairs('', "@#\<Left>(x", "@(x)#")
|
||||
call DMTest_pairs('', "(\<S-Tab>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('', "()\<BS>x", "x")
|
||||
call DMTest_pairs('', "@()x", "@(x)")
|
||||
call DMTest_pairs('', "@#\<Left>()x", "@(x)#")
|
||||
let g:delimitMate_expand_space = 1
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "(\<Space>x", "( x )")
|
||||
call DMTest_pairs('', "(\<Space>\<BS>x", "(x)")
|
||||
let g:delimitMate_autoclose = 0
|
||||
DelimitMateReload
|
||||
call DMTest_pairs('', "()\<Space>\<BS>x", "(x)")
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
" Handle backspace gracefully.
|
||||
set backspace=
|
||||
call DMTest_pairs('', "(\<Esc>a\<BS>x", "(x)")
|
||||
set bs=2
|
||||
" closing parens removes characters. #133
|
||||
call DMTest_pairs('', "(a\<Esc>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(\<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()
|
||||
|
||||
@@ -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>" "''"
|
||||
@@ -1,47 +1,104 @@
|
||||
"let g:delimitMate_quotes = '" '' ` ” « |'
|
||||
let g:delimitMate_quotes = '" '' ` « |'
|
||||
let lines = readfile(expand('<sfile>: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
|
||||
call vimtap#Plan(230)
|
||||
|
||||
let g:delimitMate_quotes = '" '' ` « |'
|
||||
let g:delimitMate_autoclose = 1
|
||||
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)."\<Esc>"
|
||||
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 DMTest_quotes('', "'x", "'x'")
|
||||
call DMTest_quotes('', "'x\<Esc>u", "")
|
||||
call DMTest_quotes('', "''x", "''x")
|
||||
call DMTest_quotes('', "'\<BS>x", "x")
|
||||
call DMTest_quotes('', "'\<C-G>gx", "''x")
|
||||
" This will fail for double quote.
|
||||
call DMTest_quotes('', "'\"x", "'\"x\"'", "a:typed == '\"\"x'")
|
||||
call DMTest_quotes('', "@'x", "@'x'")
|
||||
call DMTest_quotes('', "@#\<Left>'x", "@'x'#")
|
||||
call DMTest_quotes('', "'\<S-Tab>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('', "''\<BS>x", "x")
|
||||
call DMTest_quotes('', "@''x", "@'x'")
|
||||
call DMTest_quotes('', "@#\<Left>''x", "@'x'#")
|
||||
let g:delimitMate_expand_space = 1
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
call DMTest_quotes('', "'\<Space>x", "' x'")
|
||||
let g:delimitMate_expand_inside_quotes = 1
|
||||
DelimitMateReload
|
||||
call DMTest_quotes('', "'\<Space>x", "' x '")
|
||||
call DMTest_quotes('', "'\<Space>\<BS>x", "'x'")
|
||||
call DMTest_quotes('', "abc\\''\<Space>x", "abc\\' x'")
|
||||
let g:delimitMate_autoclose = 0
|
||||
DelimitMateReload
|
||||
call DMTest_quotes('', "''\<Space>\<BS>x", "'x'")
|
||||
let g:delimitMate_autoclose = 1
|
||||
DelimitMateReload
|
||||
" 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()
|
||||
|
||||
@@ -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(\<CR>x"
|
||||
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
|
||||
\ '^(\n\s*x\n)$', ' "normal i(\<CR>x", Value = 2, case 2')
|
||||
|
||||
call DMTest_single('', '(', '()')
|
||||
|
||||
call DMTest_single('', "(\<CR>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(\<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('', '(', '();')
|
||||
|
||||
call DMTest_single('', "(\<CR>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(\<CR>x"
|
||||
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
|
||||
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
|
||||
call DMTest_single('', '(', '()')
|
||||
|
||||
%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 3')
|
||||
call DMTest_single('', "(\<CR>x", ['(', 'x', ');'])
|
||||
|
||||
%d _
|
||||
exec "normal i;\<Esc>I{(\<CR>x"
|
||||
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
|
||||
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 4')
|
||||
call DMTest_single('', "{(\<CR>x", ['{(', 'x', ')};'])
|
||||
|
||||
call DMTest_single('', ";\<Esc>I{(\<CR>x", ['{(', 'x', ')};'])
|
||||
|
||||
" End: quit vim.
|
||||
call vimtest#Quit()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -1,55 +1,94 @@
|
||||
let g:delimitMate_expand_cr = 1
|
||||
"DelimitMateReload
|
||||
let lines = readfile(expand('<sfile>: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() {})',
|
||||
\ "\<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()
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
# Issue #95
|
||||
new
|
||||
let b:delimitMate_jump_expansion = 1
|
||||
DelimitMateReload
|
||||
exec "normal i( test)x"
|
||||
================================================================================
|
||||
( test )x
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -1,42 +1,29 @@
|
||||
let g:delimitMate_expand_space = 1
|
||||
"DelimitMateReload
|
||||
let lines = readfile(expand('<sfile>: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()
|
||||
|
||||
@@ -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'), '<Plug>delimitMate(', 'Mappings defined for the first buffer without filetype set.')
|
||||
call vimtest#Quit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user