mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated plugins
This commit is contained in:
175
sources_non_forked/vim-snipmate/t/jumping.vim
Normal file
175
sources_non_forked/vim-snipmate/t/jumping.vim
Normal file
@ -0,0 +1,175 @@
|
||||
function! Setup(snip)
|
||||
return snipMate#expandSnip(join(a:snip, "\n"), 1)
|
||||
endfunction
|
||||
|
||||
function! s:to_be_file(expected)
|
||||
return a:expected == getline(1,'$')
|
||||
endfunction
|
||||
|
||||
function! s:to_be_in(item, list)
|
||||
return !empty(filter(copy(a:list), 'v:val is a:item'))
|
||||
endfunction
|
||||
|
||||
call vspec#customize_matcher('to_be_file', function('s:to_be_file'))
|
||||
call vspec#customize_matcher('to_be_in', function('s:to_be_in'))
|
||||
|
||||
describe 'snippet state'
|
||||
|
||||
before
|
||||
enew
|
||||
let b:snip_state = snipmate#jumping#state()
|
||||
end
|
||||
|
||||
after
|
||||
bwipeout!
|
||||
end
|
||||
|
||||
describe '.remove()'
|
||||
|
||||
it 'removes the state object'
|
||||
Expect exists('b:snip_state') to_be_true
|
||||
call b:snip_state.remove()
|
||||
Expect exists('b:snip_state') to_be_false
|
||||
end
|
||||
|
||||
it 'removes snippet related autocommands'
|
||||
function! ReadAutocmds()
|
||||
redir => autocmds
|
||||
0verbose au snipmate_changes * <buffer>
|
||||
redir END
|
||||
return split(autocmds, "\n")
|
||||
endfunction
|
||||
aug snipmate_changes
|
||||
au CursorMoved,CursorMovedI <buffer> echo 'event'
|
||||
aug END
|
||||
|
||||
Expect len(ReadAutocmds()) > 1
|
||||
call b:snip_state.remove()
|
||||
Expect len(ReadAutocmds()) == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.find_next_stop()'
|
||||
|
||||
it 'increments/decrements the stop_no'
|
||||
let b:snip_state.stops = { 1 : {}, 2 : {} }
|
||||
let b:snip_state.stop_no = 1
|
||||
let b:snip_state.stop_count = 4
|
||||
|
||||
call b:snip_state.find_next_stop(0)
|
||||
Expect b:snip_state.stop_no == 2
|
||||
call b:snip_state.find_next_stop(1)
|
||||
Expect b:snip_state.stop_no == 1
|
||||
end
|
||||
|
||||
it 'continues iterating if the next/previous stop does not exist'
|
||||
let b:snip_state.stops = { 3 : {} }
|
||||
let b:snip_state.stop_count = 6
|
||||
let b:snip_state.stop_no = 1
|
||||
call b:snip_state.find_next_stop(0)
|
||||
Expect b:snip_state.stop_no == 3
|
||||
let b:snip_state.stop_no = 5
|
||||
call b:snip_state.find_next_stop(1)
|
||||
Expect b:snip_state.stop_no == 3
|
||||
end
|
||||
|
||||
it 'does something at the ends'
|
||||
"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.remove_nested()'
|
||||
|
||||
it 'removes nested mirrors and only nested mirrors'
|
||||
let mirror = { 'line' : 0 }
|
||||
let b:snip_state.stops = { 1 : { 'placeholder' : [[2, mirror]] },
|
||||
\ 2 : { 'mirrors' : [mirror, {}] } }
|
||||
|
||||
call b:snip_state.remove_nested(1)
|
||||
Expect len(b:snip_state.stops[2].mirrors) == 1
|
||||
Expect b:snip_state.stops[2].mirrors[0] isnot mirror
|
||||
end
|
||||
|
||||
it 'removes nested stops'
|
||||
let stop = [2, 'abc']
|
||||
let b:snip_state.stops = { 1 : { 'placeholder' : [stop] },
|
||||
\ 2 : { 'placeholder' : stop[1:1] } }
|
||||
|
||||
call b:snip_state.remove_nested(1)
|
||||
Expect len(b:snip_state.stops) == 1
|
||||
Expect keys(b:snip_state.stops) == ['1']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.find_update_objects()'
|
||||
|
||||
it 'finds mirrors/stops on the same line and after cur_stop'
|
||||
let b:snip_state.stops = {
|
||||
\ 1 : { 'line' : 1, 'col' : 5,
|
||||
\ 'placeholder' : ['x'] },
|
||||
\ 2 : { 'line' : 1, 'col' : 7,
|
||||
\ 'mirrors' : [{ 'line' : 1, 'col' : 7 }] }
|
||||
\ }
|
||||
let stop = b:snip_state.stops[1]
|
||||
|
||||
call b:snip_state.find_update_objects(stop)
|
||||
for obj in stop.update_objects
|
||||
Expect obj to_be_in [ b:snip_state.stops[2],
|
||||
\ b:snip_state.stops[2].mirrors[0] ]
|
||||
endfor
|
||||
end
|
||||
|
||||
it 'finds mirrors/stops on the same line and after cur_stop mirrors'
|
||||
let b:snip_state.stops = {
|
||||
\ 1 : { 'line' : 1, 'col' : 5,
|
||||
\ 'mirrors' : [{ 'line' : 2, 'col' : 5 }],
|
||||
\ 'placeholder' : ['x'] },
|
||||
\ 2 : { 'line' : 2, 'col' : 7,
|
||||
\ 'mirrors' : [{ 'line' : 2, 'col' : 7 }] }
|
||||
\ }
|
||||
let stop = b:snip_state.stops[1]
|
||||
|
||||
call b:snip_state.find_update_objects(stop)
|
||||
for obj in stop.update_objects
|
||||
Expect obj to_be_in [ b:snip_state.stops[2],
|
||||
\ b:snip_state.stops[2].mirrors[0] ]
|
||||
endfor
|
||||
end
|
||||
|
||||
it 'ignores mirrors/stops on other lines'
|
||||
let b:snip_state.stops = {
|
||||
\ 1 : { 'line' : 2, 'col' : 5,
|
||||
\ 'placeholder' : ['x'] },
|
||||
\ 2 : { 'line' : 1, 'col' : 7,
|
||||
\ 'mirrors' : [{ 'line' : 1, 'col' : 7 }] },
|
||||
\ 3 : { 'line' : 3, 'col' : 7,
|
||||
\ 'mirrors' : [{ 'line' : 3, 'col' : 7 }] }
|
||||
\ }
|
||||
let stop = b:snip_state.stops[1]
|
||||
|
||||
call b:snip_state.find_update_objects(stop)
|
||||
Expect empty(stop.update_objects) to_be_true
|
||||
end
|
||||
|
||||
it 'ignores mirrors/stops on the same line but before cur_stop/mirrors'
|
||||
let b:snip_state.stops = {
|
||||
\ 1 : { 'line' : 1, 'col' : 5,
|
||||
\ 'mirrors' : [{ 'line' : 2, 'col' : 5 }],
|
||||
\ 'placeholder' : ['x'] },
|
||||
\ 2 : { 'line' : 1, 'col' : 1,
|
||||
\ 'mirrors' : [{ 'line' : 2, 'col' : 1 }] },
|
||||
\ 3 : { 'line' : 2, 'col' : 3,
|
||||
\ 'mirrors' : [{ 'line' : 1, 'col' : 3 }] },
|
||||
\ }
|
||||
let stop = b:snip_state.stops[1]
|
||||
|
||||
call b:snip_state.find_update_objects(stop)
|
||||
Expect empty(stop.update_objects) to_be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
116
sources_non_forked/vim-snipmate/t/parser.vim
Normal file
116
sources_non_forked/vim-snipmate/t/parser.vim
Normal file
@ -0,0 +1,116 @@
|
||||
describe 'snippet parser'
|
||||
|
||||
before
|
||||
function! Parse(snippet, ...)
|
||||
let [snip, stops] = snipmate#parse#snippet(a:snippet)
|
||||
return a:0 ? [snip, stops] : snip
|
||||
endfunction
|
||||
let b:snipmate_visual = 'testvisual'
|
||||
end
|
||||
|
||||
it 'parses numeric $id and ${id} vars as [id] lists'
|
||||
let expect = [[1234567890]]
|
||||
Expect Parse('$1234567890') == expect
|
||||
Expect Parse('${1234567890}') == expect
|
||||
end
|
||||
|
||||
it 'disregards $ or ${ followed by a non-id'
|
||||
Expect Parse('$x1') == ['x1']
|
||||
Expect Parse('${x}1') == ['x}1']
|
||||
Expect Parse('$VISUA1') == ['VISUA1']
|
||||
Expect Parse('${VISUA}1') == ['VISUA}1']
|
||||
end
|
||||
|
||||
it 'gathers references to each instance of each stop id'
|
||||
let [snip, b:stops] = Parse('x$1x${2:x$1x}x$1x${1/a/b}x$VISUALx', 1)
|
||||
function! InstanceFound(list)
|
||||
return !empty(filter(copy(b:stops[a:list[0]].instances),
|
||||
\ 'v:val is a:list'))
|
||||
endfunction
|
||||
function! CheckList(list)
|
||||
for item in a:list
|
||||
if type(item) == type([])
|
||||
Expect InstanceFound(item) to_be_true
|
||||
call CheckList(item)
|
||||
endif
|
||||
unlet item " E732
|
||||
endfor
|
||||
endfunction
|
||||
call CheckList(snip)
|
||||
end
|
||||
|
||||
it 'parses mirror substitutions ${n/pat/sub} as [n, {...}]'
|
||||
let expect = [[1, { 'pat' : 'abc', 'sub' : 'def' }]]
|
||||
Expect Parse('${1/abc/def}') == expect
|
||||
let expect[0][1].flags = ''
|
||||
Expect Parse('${1/abc/def/}') == expect
|
||||
let expect[0][1].flags = 'g'
|
||||
Expect Parse('${1/abc/def/g}') == expect
|
||||
end
|
||||
|
||||
it 'parses vars with placeholders as [id, placeholder] lists'
|
||||
Expect Parse('${1:abc}') == [[1, 'abc']]
|
||||
end
|
||||
|
||||
it 'evaluates backtick expressions'
|
||||
Expect Parse('`fnamemodify("x.y", ":r")`') == ['x']
|
||||
end
|
||||
|
||||
it 'parses placeholders for vars and other specials'
|
||||
let text = 'a `fnamemodify("x.y", ":r")` ${2:(${3/a/b})}'
|
||||
let expect = ['a x ', [2, '(', [3, { 'pat' : 'a', 'sub' : 'b' }], ')']]
|
||||
Expect Parse(text) == expect
|
||||
Expect Parse(printf('${1:%s}', text)) == [[1] + expect]
|
||||
end
|
||||
|
||||
it 'converts tabs according to &et, &sts, &sw'
|
||||
" &noet -> leave tabs alone
|
||||
setl noet
|
||||
Expect Parse("abc\tdef\n\t\tghi") == ["abc\tdef", "\t\tghi"]
|
||||
|
||||
" &et -> &sts or &sw
|
||||
setl et sts=2 sw=3
|
||||
Expect Parse("abc\tdef\n\t\tghi") == ["abc def", " ghi"]
|
||||
|
||||
setl et sts=0 sw=3
|
||||
Expect Parse("abc\tdef\n\t\tghi") == ["abc def", " ghi"]
|
||||
|
||||
setl et sts=-1 sw=3
|
||||
Expect Parse("abc\tdef\n\t\tghi") == ["abc def", " ghi"]
|
||||
end
|
||||
|
||||
it 'parses backslashes as escaping the next character or joining lines'
|
||||
Expect Parse('x\x') == ['xx']
|
||||
Expect Parse('x\\x') == ['x\x']
|
||||
Expect Parse("x\\\nx") == ['xx']
|
||||
Expect Parse('x\$1') == ['x$1']
|
||||
Expect Parse('${1:\}}') == [[1, '}']]
|
||||
Expect Parse('${1/\//\}}') == [[1, { 'pat' : '/', 'sub' : '}' }]]
|
||||
Expect Parse('`fnamemodify("\`.x", ":r")`') == ['`']
|
||||
Expect Parse('\`x\`') == ['`x`']
|
||||
end
|
||||
|
||||
it 'splits text at newlines'
|
||||
Expect Parse("x\nx") == ['x', 'x']
|
||||
end
|
||||
|
||||
it 'joins evaluated expressions to surrounding text on the same line'
|
||||
let g:foo = 'bar'
|
||||
Expect Parse("x`g:foo`x") == ['xbarx']
|
||||
Expect Parse("x`g:foo`\nx") == ['xbar', 'x']
|
||||
Expect Parse("x\n`g:foo`x") == ['x', 'barx']
|
||||
end
|
||||
|
||||
it 'adds empty strings before/after vars if at the start/end of a line'
|
||||
Expect Parse("x$1\nx") == ['x', [1], '', 'x']
|
||||
Expect Parse("x\n$1x") == ['x', '', [1], 'x']
|
||||
end
|
||||
|
||||
it 'expands $VISUAL placeholders with any indents'
|
||||
Expect Parse("x$VISUALx") == ['xtestvisualx']
|
||||
let b:snipmate_visual = " foo\nbar\n baz"
|
||||
setl noet
|
||||
Expect Parse("\tx\n\t$VISUAL\nx") == ["\tx", "\t foo", "\tbar", "\t baz", "x"]
|
||||
end
|
||||
|
||||
end
|
20
sources_non_forked/vim-snipmate/t/tests.sh
Normal file
20
sources_non_forked/vim-snipmate/t/tests.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
tmp="$(mktemp || tmpfile)"
|
||||
vim -Es $tmp <<- EOF
|
||||
source ~/.vimrc
|
||||
%delete _
|
||||
call append(0, split(&rtp, ','))
|
||||
delete _
|
||||
wq
|
||||
EOF
|
||||
|
||||
rtp="$(grep -iE 'vspec|snipmate|tlib|mw-utils' < $tmp | grep -v after)"
|
||||
vspec="$(grep -iE 'vspec' < $tmp | grep -v after)"
|
||||
test_files="${*:-parser jumping}"
|
||||
|
||||
for test in $test_files; do
|
||||
$vspec/bin/vspec $rtp ${test%%.vim}.vim
|
||||
done
|
||||
|
||||
rm $tmp
|
Reference in New Issue
Block a user