Add tests
This commit is contained in:
parent
402f77feb3
commit
795a13701f
@ -73,32 +73,6 @@ function! neosnippet#handlers#_all_clear_markers() "{{{
|
||||
endtry
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#handlers#_get_in_paren(str) abort "{{{
|
||||
let s = ''
|
||||
let level = 0
|
||||
for c in split(a:str, '\zs')
|
||||
if c == '('
|
||||
let level += 1
|
||||
|
||||
if level == 1
|
||||
continue
|
||||
endif
|
||||
elseif c == ')'
|
||||
if level == 1 && s != ''
|
||||
return s
|
||||
else
|
||||
let level -= 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if level > 0
|
||||
let s .= c
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
endfunction"}}}
|
||||
|
||||
function! s:is_auto_pairs() abort "{{{
|
||||
return get(g:, 'neopairs#enable', 0)
|
||||
endfunction"}}}
|
||||
|
@ -315,34 +315,55 @@ function! neosnippet#parser#_get_completed_snippet(completed_item) "{{{
|
||||
" Make snippet arguments
|
||||
let cnt = 1
|
||||
let snippet = ''
|
||||
if key == '('
|
||||
for arg in split(substitute(neosnippet#handlers#_get_in_paren(abbr),
|
||||
\ '(\zs.\{-}\ze)', '', 'g'), '[^[]\zs\s*,\s*')
|
||||
if arg ==# 'self' && &filetype ==# 'python'
|
||||
" Ignore self argument
|
||||
continue
|
||||
endif
|
||||
for arg in split(substitute(
|
||||
\ neosnippet#parser#_get_in_paren(key, pair, abbr),
|
||||
\ key.'\zs.\{-}\ze'.pair, '', 'g'), '[^[]\zs\s*,\s*')
|
||||
if key ==# '(' && arg ==# 'self' && &filetype ==# 'python'
|
||||
" Ignore self argument
|
||||
continue
|
||||
endif
|
||||
|
||||
if cnt != 1
|
||||
let snippet .= ', '
|
||||
endif
|
||||
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
|
||||
let cnt += 1
|
||||
endfor
|
||||
endif
|
||||
|
||||
if key != '(' && snippet[-1:] ==# key
|
||||
let snippet .= '${' . cnt . '}' . pair
|
||||
if cnt != 1
|
||||
let snippet .= ', '
|
||||
endif
|
||||
let snippet .= printf('${%d:#:%s}', cnt, escape(arg, '{}'))
|
||||
let cnt += 1
|
||||
elseif snippet[-1:] !=# pair
|
||||
let snippet .= pair
|
||||
endif
|
||||
endfor
|
||||
|
||||
let snippet .= pair
|
||||
|
||||
let snippet .= '${' . cnt . '}'
|
||||
|
||||
return snippet
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#parser#_get_in_paren(key, pair, str) abort "{{{
|
||||
let s = ''
|
||||
let level = 0
|
||||
for c in split(a:str, '\zs')
|
||||
if c ==# a:key
|
||||
let level += 1
|
||||
|
||||
if level == 1
|
||||
continue
|
||||
endif
|
||||
elseif c ==# a:pair
|
||||
if level == 1 && s != ''
|
||||
return s
|
||||
else
|
||||
let level -= 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if level > 0
|
||||
let s .= c
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
endfunction"}}}
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
|
@ -2,26 +2,70 @@ let s:suite = themis#suite('toml')
|
||||
let s:assert = themis#helper('assert')
|
||||
|
||||
function! s:suite.get_in_paren()
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ '(foobar)'),
|
||||
\ 'foobar')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ '(foobar, baz)'),
|
||||
\ 'foobar, baz')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ '(foobar, (baz))'),
|
||||
\ 'foobar, (baz)')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ 'foobar('),
|
||||
\ '')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ 'foobar()'),
|
||||
\ '')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ 'foobar(fname)'),
|
||||
\ 'fname')
|
||||
call s:assert.equals(neosnippet#handlers#_get_in_paren(
|
||||
call s:assert.equals(neosnippet#parser#_get_in_paren(
|
||||
\ '(', ')',
|
||||
\ 'wait() wait(long, int)'),
|
||||
\ 'long, int')
|
||||
endfunction
|
||||
|
||||
function! s:suite.get_completed_snippet()
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo(', 'abbr' : 'foo()',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), ')${1}')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge)',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '${1:#:hoge})${2}')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo', 'abbr' : 'foo(hoge)',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo)',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '${1:#:hoge}, ${2:#:piyo})${3}')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo(', 'abbr' : 'foo(hoge, piyo(foobar))',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '${1:#:hoge}, ${2:#:piyo()})${3}')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo{', 'abbr' : 'foo{}',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '}${1}')
|
||||
|
||||
call s:assert.equals(neosnippet#parser#_get_completed_snippet({
|
||||
\ 'word' : 'foo{', 'abbr' : 'foo{piyo}',
|
||||
\ 'menu' : '', 'info' : ''
|
||||
\ }), '${1:#:piyo}}${2}')
|
||||
endfunction
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user