Simplify CR expansion mapping. Add Test for it.

This commit is contained in:
Israel Chauca Fuentes
2012-02-24 20:32:42 -05:00
parent f3176a664c
commit bb9b0edcc5
3 changed files with 57 additions and 3 deletions

View File

@@ -406,9 +406,9 @@ function! delimitMate#ExpandReturn() "{{{
" Expand: " Expand:
call delimitMate#FlushBuffer() call delimitMate#FlushBuffer()
let b:delimitMate_lineSuffix = getline('.')[col('.')-1:] " Not sure why I used the previous combos, but I'm sure somebody will tell
call feedkeys("\<Esc>l\"_Do \<CR>\<C-R>\<C-R>=b:delimitMate_lineSuffix\<CR>\<Esc>k$i\<Del>", 't') " me about it.
return '' return "\<Esc>a\<CR>\<Esc>O"
else else
return "\<CR>" return "\<CR>"
endif endif

12
test/expand_cr.txt Normal file
View File

@@ -0,0 +1,12 @@
#
%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
})
--------------------------------------------------------------------------------

42
test/expand_cr.vim Normal file
View File

@@ -0,0 +1,42 @@
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
for item in lines
if item =~ '^=\{80}$'
let expect = 1
let expected = []
continue
endif
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()