Regenerate nvim config
This commit is contained in:
65
config/neovim/store/lazy-plugins/vim-sandwich/test/.themisrc
Normal file
65
config/neovim/store/lazy-plugins/vim-sandwich/test/.themisrc
Normal file
@ -0,0 +1,65 @@
|
||||
set encoding=utf-8
|
||||
execute 'set runtimepath+=' . expand('<sfile>:p:h:h')
|
||||
runtime! plugin/*.vim
|
||||
runtime! plugin/**/*.vim
|
||||
set noswapfile
|
||||
let g:operator_sandwich_no_visualrepeat = 1
|
||||
|
||||
let g:assert = themis#helper('assert')
|
||||
|
||||
function! TextobjCoord(l1, c1, l2, c2) abort
|
||||
normal! v
|
||||
call cursor(a:l1, a:c1)
|
||||
normal! o
|
||||
call cursor(a:l2, a:c2)
|
||||
endfunction
|
||||
|
||||
function! TextobjFail() abort
|
||||
endfunction
|
||||
|
||||
function! TestIndent() abort
|
||||
" always the indent of the previous nonbland line + shiftwidth()
|
||||
return indent(prevnonblank(v:lnum)) + shiftwidth()
|
||||
endfunction
|
||||
|
||||
function! SandwichExprCancel() abort
|
||||
throw 'OperatorSandwichCancel'
|
||||
endfunction
|
||||
|
||||
function! SandwichExprEmpty() abort
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! SandwichExprBuns(is_head) abort
|
||||
if a:is_head
|
||||
return 'head'
|
||||
else
|
||||
return 'tail'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SandwichListexprEmpty(which) abort
|
||||
if a:which ==# 'former'
|
||||
return ['', 'bar']
|
||||
elseif a:which ==# 'latter'
|
||||
return ['foo', '']
|
||||
else
|
||||
return ['', '']
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SandwichListexprBuns(cancel) abort
|
||||
if a:cancel
|
||||
throw 'OperatorSandwichCancel'
|
||||
else
|
||||
return ['foo', 'baz']
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SandwichSkipIntermediate(is_head, pos, ...) abort
|
||||
if a:is_head
|
||||
return !(a:pos[2] == 1)
|
||||
else
|
||||
return !(a:pos[2] == col([a:pos[1], '$'])-1)
|
||||
endif
|
||||
endfunction
|
||||
@ -0,0 +1,6 @@
|
||||
Use themis.vim (https://github.com/thinca/vim-themis)
|
||||
|
||||
1. git clone https://github.com/thinca/vim-themis.git
|
||||
2. cd path/to/vim-sandwich
|
||||
3. path/to/vim-themis/bin/themis (Linux)
|
||||
path/to/vim-themis/bin/themis.bat (Windows)
|
||||
@ -0,0 +1,11 @@
|
||||
@echo off
|
||||
set VIM=vim
|
||||
if defined THEMIS_VIM set VIM=%THEMIS_VIM%
|
||||
|
||||
%VIM% -u NONE -i NONE -N -n -e -s -S %~dp0\test_dot.vim
|
||||
if %errorlevel% neq 0 goto ERROR
|
||||
echo Succeeded.
|
||||
exit /b 0
|
||||
|
||||
:ERROR
|
||||
exit /b 1
|
||||
@ -0,0 +1,15 @@
|
||||
#! /bin/sh
|
||||
|
||||
SCRIPT_HOME=$0
|
||||
if [ -n "`readlink $SCRIPT_HOME`" ] ; then
|
||||
SCRIPT_HOME="`readlink $SCRIPT_HOME`"
|
||||
fi
|
||||
SCRIPT_HOME="`dirname $SCRIPT_HOME`"
|
||||
|
||||
VIM=vim
|
||||
if [ -n "$THEMIS_VIM" ] ; then
|
||||
VIM="$THEMIS_VIM"
|
||||
fi
|
||||
|
||||
$VIM -u NONE -i NONE -N -n -e -s -S $SCRIPT_HOME/test_dot.vim || exit 1
|
||||
echo "Succeeded."
|
||||
@ -0,0 +1,751 @@
|
||||
if has('win16') || has('win32') || has('win64') || has('win95')
|
||||
set shellslash
|
||||
endif
|
||||
execute 'set runtimepath+=' . expand('<sfile>:p:h:h:h')
|
||||
source <sfile>:p:h:h:h/plugin/operator/sandwich.vim
|
||||
source <sfile>:p:h:h:h/plugin/textobj/sandwich.vim
|
||||
source <sfile>:p:h:h:h/plugin/sandwich.vim
|
||||
nnoremap <Plug>(test-dot) .
|
||||
let g:operator_sandwich_no_visualrepeat = 1
|
||||
|
||||
function! s:assert(a1, a2, kind) abort
|
||||
if type(a:a1) == type(a:a2) && string(a:a1) ==# string(a:a2)
|
||||
return
|
||||
endif
|
||||
|
||||
%delete
|
||||
call append(0, ['Got:', string(a:a1)])
|
||||
call append(0, [printf('Failured at "%s"', a:kind), '', 'Expect:', string(a:a2)])
|
||||
$delete
|
||||
1,$print
|
||||
cquit
|
||||
endfunction
|
||||
|
||||
function! s:quit_by_error() abort
|
||||
%delete
|
||||
call append(0, [printf('Catched the following error at %s.', v:throwpoint), v:exception])
|
||||
$delete
|
||||
1,$print
|
||||
cquit
|
||||
endfunction
|
||||
|
||||
function! Count(...) abort
|
||||
let s:count += 1
|
||||
return s:count
|
||||
endfunction
|
||||
|
||||
function! ListCount(...) abort
|
||||
let s:count += 1
|
||||
return [s:count, s:count]
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
try
|
||||
|
||||
""" operator-add
|
||||
" normal use
|
||||
call setline('.', 'foo')
|
||||
normal saiw(
|
||||
normal .
|
||||
call s:assert(getline('.'), '((foo))', 'operator-add:normal use #1')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-add:normal use #2')
|
||||
|
||||
normal saiw[
|
||||
normal .
|
||||
call s:assert(getline('.'), '(([[foo]]))', 'operator-add:normal use #3')
|
||||
call s:assert(getpos('.'), [0, 1, 5, 0], 'operator-add:normal use #4')
|
||||
|
||||
%delete
|
||||
|
||||
" blockwise-visual
|
||||
call append(0, ['foo', 'bar', 'baz'])
|
||||
$delete
|
||||
execute "normal gg\<C-v>2j2lsa("
|
||||
normal .
|
||||
call s:assert(getline(1), '((foo))', 'operator-add:blockwise-visual #1')
|
||||
call s:assert(getline(2), '((bar))', 'operator-add:blockwise-visual #2')
|
||||
call s:assert(getline(3), '((baz))', 'operator-add:blockwise-visual #3')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-add:blockwise-visual #4')
|
||||
|
||||
normal j.
|
||||
call s:assert(getline(1), '((foo))', 'operator-add:blockwise-visual #5')
|
||||
call s:assert(getline(2), '(((bar)))', 'operator-add:blockwise-visual #6')
|
||||
call s:assert(getline(3), '(((baz)))', 'operator-add:blockwise-visual #7')
|
||||
call s:assert(getpos('.'), [0, 2, 4, 0], 'operator-add:blockwise-visual #8')
|
||||
|
||||
normal j.
|
||||
call s:assert(getline(1), '((foo))', 'operator-add:blockwise-visual #9')
|
||||
call s:assert(getline(2), '(((bar)))', 'operator-add:blockwise-visual #10')
|
||||
call s:assert(getline(3), '((((baz))))', 'operator-add:blockwise-visual #11')
|
||||
call s:assert(getpos('.'), [0, 3, 5, 0], 'operator-add:blockwise-visual #12')
|
||||
|
||||
%delete
|
||||
|
||||
" count
|
||||
call setline('.', 'foo')
|
||||
normal 2saiw((
|
||||
normal .
|
||||
call s:assert(getline('.'), '((((foo))))', 'operator-add:count #1')
|
||||
call s:assert(getpos('.'), [0, 1, 5, 0], 'operator-add:count #2')
|
||||
|
||||
call setline('.', 'foo')
|
||||
normal saiw(
|
||||
call setline('.', 'foo bar')
|
||||
normal 3.
|
||||
call s:assert(getline('.'), '(foo bar)', 'operator-add:count #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-add:count #4')
|
||||
|
||||
%delete
|
||||
|
||||
" expr
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 1, 'input': ['c']}]
|
||||
call setline('.', 'foo')
|
||||
let s:count = 0
|
||||
normal saiwc
|
||||
normal .
|
||||
call s:assert(getline('.'), '11foo22', 'operator-add:expr #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-add:expr #2')
|
||||
|
||||
let g:operator#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 2, 'input': ['c']}]
|
||||
call setline('.', 'foo')
|
||||
let s:count = 0
|
||||
normal saiwc
|
||||
normal .
|
||||
call s:assert(getline('.'), '31foo24', 'operator-add:expr #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-add:expr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" listexpr
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 1, 'input': ['c']}]
|
||||
call setline('.', 'foo')
|
||||
let s:count = 0
|
||||
normal saiwc
|
||||
normal .
|
||||
call s:assert(getline('.'), '11foo11', 'operator-add:listexpr #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-add:listexpr #2')
|
||||
|
||||
let g:operator#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 2, 'input': ['c']}]
|
||||
call setline('.', 'foo')
|
||||
let s:count = 0
|
||||
normal saiwc
|
||||
normal .
|
||||
call s:assert(getline('.'), '21foo12', 'operator-add:listexpr #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-add:listexpr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" cursor option 'keep'
|
||||
call operator#sandwich#set('add', 'all', 'cursor', 'keep')
|
||||
nmap . <Plug>(operator-sandwich-dot)
|
||||
call setline('.', 'foo')
|
||||
normal 0lsaiw(
|
||||
normal .
|
||||
call s:assert(getline('.'), '((foo))', 'operator-add:cursor keep #1')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-add:cursor keep #2')
|
||||
|
||||
call setline('.', 'foo')
|
||||
normal 0lsaiw(
|
||||
call setline('.', 'foo bar')
|
||||
normal 0l3.
|
||||
call s:assert(getline('.'), '(foo bar)', 'operator-add:cursor keep #3')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-add:cursor keep #4')
|
||||
|
||||
nmap . <Plug>(operator-sandwich-predot)<Plug>(test-dot)
|
||||
call setline('.', 'foo')
|
||||
normal 0lsaiw(
|
||||
normal .
|
||||
call s:assert(getline('.'), '((foo))', 'operator-add:cursor keep #5')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-add:cursor keep #6')
|
||||
|
||||
call setline('.', 'foo')
|
||||
normal 0lsaiw(
|
||||
call setline('.', 'foo bar')
|
||||
normal 0l3.
|
||||
call s:assert(getline('.'), '(foo bar)', 'operator-add:cursor keep #7')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-add:cursor keep #8')
|
||||
|
||||
call operator#sandwich#set_default()
|
||||
nunmap .
|
||||
%delete
|
||||
|
||||
|
||||
|
||||
""" operator-delete
|
||||
nmap sd <Plug>(operator-sandwich-delete)
|
||||
xmap sd <Plug>(operator-sandwich-delete)
|
||||
" normal use
|
||||
call setline('.', '((foo))')
|
||||
normal sda(
|
||||
normal .
|
||||
call s:assert(getline('.'), 'foo', 'operator-delete:normal use #1')
|
||||
call s:assert(getpos('.'), [0, 1, 1, 0], 'operator-delete:normal use #2')
|
||||
|
||||
call setline('.', '[[foo]]')
|
||||
normal sda[
|
||||
normal .
|
||||
call s:assert(getline('.'), 'foo', 'operator-delete:normal use #3')
|
||||
call s:assert(getpos('.'), [0, 1, 1, 0], 'operator-delete:normal use #4')
|
||||
|
||||
%delete
|
||||
|
||||
" blockwise-visual
|
||||
call append(0, ['(((((foo)))))', '(((((bar)))))', '(((((baz)))))'])
|
||||
$delete
|
||||
execute "normal ggffh\<C-v>2j4lsd"
|
||||
normal h.
|
||||
call s:assert(getline(1), '(((foo)))', 'operator-delete:blockwise-visual #1')
|
||||
call s:assert(getline(2), '(((bar)))', 'operator-delete:blockwise-visual #2')
|
||||
call s:assert(getline(3), '(((baz)))', 'operator-delete:blockwise-visual #3')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-delete:blockwise-visual #4')
|
||||
|
||||
normal jh.
|
||||
call s:assert(getline(1), '(((foo)))', 'operator-delete:blockwise-visual #5')
|
||||
call s:assert(getline(2), '((bar))', 'operator-delete:blockwise-visual #6')
|
||||
call s:assert(getline(3), '((baz))', 'operator-delete:blockwise-visual #7')
|
||||
call s:assert(getpos('.'), [0, 2, 3, 0], 'operator-delete:blockwise-visual #8')
|
||||
|
||||
normal jh.
|
||||
call s:assert(getline(1), '(((foo)))', 'operator-delete:blockwise-visual #9')
|
||||
call s:assert(getline(2), '((bar))', 'operator-delete:blockwise-visual #10')
|
||||
call s:assert(getline(3), '(baz)', 'operator-delete:blockwise-visual #11')
|
||||
call s:assert(getpos('.'), [0, 3, 2, 0], 'operator-delete:blockwise-visual #12')
|
||||
|
||||
%delete
|
||||
|
||||
" count
|
||||
call setline('.', '((((foo))))')
|
||||
normal 02sda(
|
||||
normal .
|
||||
call s:assert(getline('.'), 'foo', 'operator-delete:count #1')
|
||||
call s:assert(getpos('.'), [0, 1, 1, 0], 'operator-delete:count #2')
|
||||
|
||||
call setline('.', '[([[foo]])]')
|
||||
normal ffsda[
|
||||
normal 2.
|
||||
call s:assert(getline('.'), '([foo])', 'operator-delete:count #3')
|
||||
call s:assert(getpos('.'), [0, 1, 1, 0], 'operator-delete:count #4')
|
||||
|
||||
%delete
|
||||
|
||||
" external textobjct
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'external': ['it', 'at'], 'noremap': 1}]
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
normal ggsdat
|
||||
normal j.
|
||||
call s:assert(getline(1), 'fooo', 'operator-delete:external textobject #1')
|
||||
call s:assert(getline(2), 'bar', 'operator-delete:external textobject #2')
|
||||
call s:assert(getpos('.'), [0, 2, 1, 0], 'operator-delete:external textobject #3')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" cursor option 'keep'
|
||||
call operator#sandwich#set('delete', 'all', 'cursor', 'keep')
|
||||
nmap . <Plug>(operator-sandwich-dot)
|
||||
call setline('.', '((foo))')
|
||||
normal 03lsda(
|
||||
normal .
|
||||
call s:assert(getline('.'), 'foo', 'operator-delete:cursor keep #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-delete:cursor keep #2')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal 0sda(
|
||||
call setline('.', '((foo) bar)')
|
||||
normal 03l2.
|
||||
call s:assert(getline('.'), '(foo) bar', 'operator-delete:cursor keep #3')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-delete:cursor keep #4')
|
||||
|
||||
nmap . <Plug>(operator-sandwich-predot)<Plug>(test-dot)
|
||||
call setline('.', '((foo))')
|
||||
normal 03lsda(
|
||||
normal .
|
||||
call s:assert(getline('.'), 'foo', 'operator-delete:cursor keep #5')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-delete:cursor keep #6')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal 0sda(
|
||||
call setline('.', '((foo) bar)')
|
||||
normal 03l2.
|
||||
call s:assert(getline('.'), '(foo) bar', 'operator-delete:cursor keep #7')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-delete:cursor keep #8')
|
||||
|
||||
call operator#sandwich#set_default()
|
||||
nunmap .
|
||||
%delete
|
||||
|
||||
|
||||
|
||||
""" operator-replace
|
||||
nmap sr <Plug>(operator-sandwich-replace)
|
||||
xmap sr <Plug>(operator-sandwich-replace)
|
||||
" normal use
|
||||
call setline('.', '((foo))')
|
||||
normal 0ffsra([
|
||||
normal .
|
||||
call s:assert(getline('.'), '[[foo]]', 'operator-replace:normal use #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:normal use #2')
|
||||
|
||||
normal 0ffsra[(
|
||||
normal .
|
||||
call s:assert(getline('.'), '((foo))', 'operator-replace:normal use #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:normal use #4')
|
||||
|
||||
%delete
|
||||
|
||||
" blockwise-visual
|
||||
call append(0, ['(foo)', '(bar)', '(baz)'])
|
||||
$delete
|
||||
execute "normal gg\<C-v>2j4lsr["
|
||||
call setline(1, '(foo)')
|
||||
call setline(2, '(bar)')
|
||||
call setline(3, '(baz)')
|
||||
normal h.
|
||||
call s:assert(getline(1), '[foo]', 'operator-replace:blockwise-visual #1')
|
||||
call s:assert(getline(2), '[bar]', 'operator-replace:blockwise-visual #2')
|
||||
call s:assert(getline(3), '[baz]', 'operator-replace:blockwise-visual #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:blockwise-visual #4')
|
||||
|
||||
call setline(1, '(foo)')
|
||||
call setline(2, '(bar)')
|
||||
call setline(3, '(baz)')
|
||||
normal jh.
|
||||
call s:assert(getline(1), '(foo)', 'operator-replace:blockwise-visual #5')
|
||||
call s:assert(getline(2), '[bar]', 'operator-replace:blockwise-visual #6')
|
||||
call s:assert(getline(3), '[baz]', 'operator-replace:blockwise-visual #7')
|
||||
call s:assert(getpos('.'), [0, 2, 2, 0], 'operator-replace:blockwise-visual #8')
|
||||
|
||||
call setline(1, '(foo)')
|
||||
call setline(2, '(bar)')
|
||||
call setline(3, '(baz)')
|
||||
normal jh.
|
||||
call s:assert(getline(1), '(foo)', 'operator-replace:blockwise-visual #9')
|
||||
call s:assert(getline(2), '(bar)', 'operator-replace:blockwise-visual #10')
|
||||
call s:assert(getline(3), '[baz]', 'operator-replace:blockwise-visual #11')
|
||||
call s:assert(getpos('.'), [0, 3, 2, 0], 'operator-replace:blockwise-visual #12')
|
||||
|
||||
%delete
|
||||
|
||||
" count
|
||||
call setline('.', '((((foo))))')
|
||||
normal 0ff2sr2a([[
|
||||
normal .
|
||||
call s:assert(getline('.'), '[[[[foo]]]]', 'operator-replace:count #1')
|
||||
call s:assert(getpos('.'), [0, 1, 3, 0], 'operator-replace:count #2')
|
||||
|
||||
call setline('.', '[([[foo]])]')
|
||||
normal 0ffsra[(
|
||||
normal 2.
|
||||
call s:assert(getline('.'), '(([(foo)]))', 'operator-replace:count #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:count #2')
|
||||
|
||||
%delete
|
||||
|
||||
" expr
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 1, 'input': ['c']}, {'buns': ['(', ')']}]
|
||||
call setline('.', '((foo))')
|
||||
let s:count = 0
|
||||
normal ffsra(c
|
||||
normal .
|
||||
call s:assert(getline('.'), '11foo22', 'operator-replace:expr #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:expr #2')
|
||||
|
||||
let g:operator#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 2, 'input': ['c']}, {'buns': ['(', ')']}]
|
||||
call setline('.', '((foo))')
|
||||
let s:count = 0
|
||||
normal ffsra(c
|
||||
normal .
|
||||
call s:assert(getline('.'), '31foo24', 'operator-replace:expr #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:expr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" listexpr
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 1, 'input': ['c']}, {'buns': ['(', ')']}]
|
||||
call setline('.', '((foo))')
|
||||
let s:count = 0
|
||||
normal ffsra(c
|
||||
normal .
|
||||
call s:assert(getline('.'), '11foo11', 'operator-replace:listexpr #1')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:listexpr #2')
|
||||
|
||||
let g:operator#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 2, 'input': ['c']}, {'buns': ['(', ')']}]
|
||||
call setline('.', '((foo))')
|
||||
let s:count = 0
|
||||
normal ffsra(c
|
||||
normal .
|
||||
call s:assert(getline('.'), '21foo12', 'operator-replace:listexpr #3')
|
||||
call s:assert(getpos('.'), [0, 1, 2, 0], 'operator-replace:listexpr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" external textobjct
|
||||
let g:sandwich#recipes = []
|
||||
let g:operator#sandwich#recipes = [{'external': ['it', 'at'], 'noremap': 1}, {'buns': ['(', ')']}]
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
normal ggsrat(
|
||||
normal j.
|
||||
call s:assert(getline(1), '(fooo)', 'operator-replace:external textobject #1')
|
||||
call s:assert(getline(2), '(bar)', 'operator-replace:external textobject #2')
|
||||
call s:assert(getpos('.'), [0, 2, 2, 0], 'operator-replace:external textobject #3')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:operator#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" cursor option 'keep'
|
||||
call operator#sandwich#set('replace', 'all', 'cursor', 'keep')
|
||||
nmap . <Plug>(operator-sandwich-dot)
|
||||
call setline('.', '((foo))')
|
||||
normal 03lsra([
|
||||
normal .
|
||||
call s:assert(getline('.'), '[[foo]]', 'operator-delete:cursor keep #1')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-delete:cursor keep #2')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal 0sra([
|
||||
call setline('.', '((foo) bar)')
|
||||
normal 03l2.
|
||||
call s:assert(getline('.'), '[(foo) bar]', 'operator-delete:cursor keep #3')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-delete:cursor keep #4')
|
||||
|
||||
nmap . <Plug>(operator-sandwich-predot)<Plug>(test-dot)
|
||||
call setline('.', '((foo))')
|
||||
normal 03lsra([
|
||||
normal .
|
||||
call s:assert(getline('.'), '[[foo]]', 'operator-delete:cursor keep #5')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-delete:cursor keep #6')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal 0sra([
|
||||
call setline('.', '((foo) bar)')
|
||||
normal 03l2.
|
||||
call s:assert(getline('.'), '[(foo) bar]', 'operator-delete:cursor keep #7')
|
||||
call s:assert(getpos('.'), [0, 1, 4, 0], 'operator-delete:cursor keep #8')
|
||||
|
||||
call operator#sandwich#set_default()
|
||||
nunmap .
|
||||
%delete
|
||||
|
||||
|
||||
|
||||
""" textobj-query
|
||||
" normal use
|
||||
call setline('.', '(foo)')
|
||||
normal dis(
|
||||
call setline('.', '(foo)')
|
||||
normal .
|
||||
call s:assert(getline('.'), '()', 'textobj-query:normal use #1')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal das(
|
||||
call setline('.', '(foo)')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:normal use #2')
|
||||
|
||||
%delete
|
||||
|
||||
" count
|
||||
call setline('.', '((foo))((bar))')
|
||||
normal 0ffdis(
|
||||
normal 0fb2.
|
||||
call s:assert(getline('.'), '(())()', 'textobj-query:count #1')
|
||||
|
||||
call setline('.', '((foo))((bar))')
|
||||
normal 0ffdas(
|
||||
normal 0fb2.
|
||||
call s:assert(getline('.'), '()', 'textobj-query:count #2')
|
||||
|
||||
%delete
|
||||
|
||||
" expr
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 1, 'input': ['c']}]
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal disc
|
||||
call setline('.', '1foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '12', 'textobj-query:expr #1')
|
||||
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dasc
|
||||
call setline('.', '1foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:expr #2')
|
||||
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 2, 'input': ['c']}]
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal disc
|
||||
call setline('.', '3foo4')
|
||||
normal .
|
||||
call s:assert(getline('.'), '34', 'textobj-query:expr #3')
|
||||
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dasc
|
||||
call setline('.', '3foo4')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:expr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" listexpr
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 1, 'input': ['c']}]
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal disc
|
||||
call setline('.', '1foo1')
|
||||
normal .
|
||||
call s:assert(getline('.'), '11', 'textobj-query:listexpr #1')
|
||||
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dasc
|
||||
call setline('.', '1foo1')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:listexpr #2')
|
||||
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 2, 'input': ['c']}]
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal disc
|
||||
call setline('.', '2foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '22', 'textobj-query:listexpr #3')
|
||||
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dasc
|
||||
call setline('.', '2foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:listexpr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" external textobjct
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'external': ['it', 'at'], 'noremap': 1, 'input': ['t']}]
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
$delete
|
||||
normal ggdist
|
||||
normal j.
|
||||
call s:assert(getline(1), '<title></title>', 'textobj-query:external textobject #1')
|
||||
call s:assert(getline(2), '<body></body>', 'textobj-query:external textobject #2')
|
||||
|
||||
%delete
|
||||
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
$delete
|
||||
normal ggdast
|
||||
normal j.
|
||||
call s:assert(getline(1), '', 'textobj-query:external textobject #3')
|
||||
call s:assert(getline(2), '', 'textobj-query:external textobject #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" synchro option
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['foo', 'baz'], 'synchro': 1, 'input': ['f']}]
|
||||
call append(0, ['foo bar baz', ' foo baaaaar baz'])
|
||||
$delete
|
||||
normal ggdisf
|
||||
normal jl.
|
||||
call s:assert(getline(1), 'foobaz', 'textobj-query: synchro option #1')
|
||||
call s:assert(getline(2), ' foobaz', 'textobj-query: synchro option #2')
|
||||
|
||||
%delete
|
||||
|
||||
call append(0, ['foo bar baz', ' foo baaaaar baz'])
|
||||
$delete
|
||||
normal ggdasf
|
||||
normal jl.
|
||||
call s:assert(getline(1), '', 'textobj-query: synchro option #3')
|
||||
call s:assert(getline(2), ' ', 'textobj-query: synchro option #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
|
||||
|
||||
""" textobj-auto
|
||||
" normal use
|
||||
call setline('.', '(foo)')
|
||||
normal dib
|
||||
call setline('.', '(foo)')
|
||||
normal .
|
||||
call s:assert(getline('.'), '()', 'textobj-auto:normal use #1')
|
||||
|
||||
call setline('.', '(foo)')
|
||||
normal dab
|
||||
call setline('.', '(foo)')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-auto:normal use #2')
|
||||
|
||||
%delete
|
||||
|
||||
" count
|
||||
call setline('.', '((foo))((bar))')
|
||||
normal 0ffdib
|
||||
normal 0fb2.
|
||||
call s:assert(getline('.'), '(())()', 'textobj-auto:count #1')
|
||||
|
||||
call setline('.', '((foo))((bar))')
|
||||
normal 0ffdab
|
||||
normal 0fb2.
|
||||
call s:assert(getline('.'), '()', 'textobj-auto:count #2')
|
||||
|
||||
%delete
|
||||
|
||||
" expr
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 1, 'input': ['c']}]
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dib
|
||||
call setline('.', '1foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '12', 'textobj-auto:expr #1')
|
||||
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dab
|
||||
call setline('.', '1foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-auto:expr #2')
|
||||
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['Count()', 'Count()'], 'expr': 2, 'input': ['c']}]
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dib
|
||||
call setline('.', '3foo4')
|
||||
normal .
|
||||
call s:assert(getline('.'), '34', 'textobj-auto:expr #3')
|
||||
|
||||
call setline('.', '1foo2')
|
||||
let s:count = 0
|
||||
normal dab
|
||||
call setline('.', '3foo4')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-auto:expr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" listexpr
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 1, 'input': ['c']}]
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dib
|
||||
call setline('.', '1foo1')
|
||||
normal .
|
||||
call s:assert(getline('.'), '11', 'textobj-query:listexpr #1')
|
||||
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dab
|
||||
call setline('.', '1foo1')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:listexpr #2')
|
||||
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': 'ListCount()', 'listexpr': 2, 'input': ['c']}]
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dib
|
||||
call setline('.', '2foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '22', 'textobj-query:listexpr #3')
|
||||
|
||||
call setline('.', '1foo1')
|
||||
let s:count = 0
|
||||
normal dab
|
||||
call setline('.', '2foo2')
|
||||
normal .
|
||||
call s:assert(getline('.'), '', 'textobj-query:listexpr #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" external textobjct
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'external': ['it', 'at'], 'noremap': 1, 'input': ['t']}]
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
$delete
|
||||
normal ggdib
|
||||
normal j.
|
||||
call s:assert(getline(1), '<title></title>', 'textobj-auto:external textobject #1')
|
||||
call s:assert(getline(2), '<body></body>', 'textobj-auto:external textobject #2')
|
||||
|
||||
%delete
|
||||
|
||||
call append(0, ['<title>fooo</title>', '<body>bar</body>'])
|
||||
$delete
|
||||
normal ggdab
|
||||
normal j.
|
||||
call s:assert(getline(1), '', 'textobj-auto:external textobject #3')
|
||||
call s:assert(getline(2), '', 'textobj-auto:external textobject #4')
|
||||
|
||||
unlet g:sandwich#recipes
|
||||
unlet g:textobj#sandwich#recipes
|
||||
%delete
|
||||
|
||||
" synchro option
|
||||
let g:sandwich#recipes = []
|
||||
let g:textobj#sandwich#recipes = [{'buns': ['foo', 'baz'], 'synchro': 1, 'input': ['f']}]
|
||||
call append(0, ['foo bar baz', ' foo baaaaar baz'])
|
||||
$delete
|
||||
normal ggdib
|
||||
normal jl.
|
||||
call s:assert(getline(1), 'foobaz', 'textobj-auto: synchro option #1')
|
||||
call s:assert(getline(2), ' foobaz', 'textobj-auto: synchro option #2')
|
||||
|
||||
%delete
|
||||
|
||||
call append(0, ['foo bar baz', ' foo baaaaar baz'])
|
||||
$delete
|
||||
normal ggdab
|
||||
normal jl.
|
||||
call s:assert(getline(1), '', 'textobj-auto: synchro option #3')
|
||||
call s:assert(getline(2), ' ', 'textobj-auto: synchro option #4')
|
||||
|
||||
%delete
|
||||
|
||||
catch
|
||||
call s:quit_by_error()
|
||||
endtry
|
||||
|
||||
|
||||
|
||||
qall!
|
||||
11075
config/neovim/store/lazy-plugins/vim-sandwich/test/operator-add.vim
Normal file
11075
config/neovim/store/lazy-plugins/vim-sandwich/test/operator-add.vim
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
14236
config/neovim/store/lazy-plugins/vim-sandwich/test/operator-replace.vim
Normal file
14236
config/neovim/store/lazy-plugins/vim-sandwich/test/operator-replace.vim
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,80 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:suite = themis#suite('keymappings')
|
||||
|
||||
function! s:suite.before() abort "{{{
|
||||
runtime macros/sandwich/keymap/surround.vim
|
||||
endfunction "}}}
|
||||
function! s:suite.before_each() abort "{{{
|
||||
%delete
|
||||
set filetype=
|
||||
call operator#sandwich#set_default()
|
||||
unlet! g:sandwich#recipes
|
||||
unlet! g:operator#sandwich#recipes
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:suite.after() abort "{{{
|
||||
call s:suite.before_each()
|
||||
mapclear
|
||||
unlet g:sandwich_no_default_key_mappings
|
||||
unlet g:operator_sandwich_no_default_key_mappings
|
||||
unlet g:textobj_sandwich_no_default_key_mappings
|
||||
runtime plugin/sandwich.vim
|
||||
runtime plugin/operator/sandwich.vim
|
||||
runtime plugin/textobj/sandwich.vim
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
|
||||
function! s:suite.surround() abort "{{{
|
||||
call setline('.', 'foo')
|
||||
normal 0ysiw(
|
||||
call g:assert.equals(getline('.'), '(foo)', 'failed at #1')
|
||||
|
||||
call setline('.', 'foo bar')
|
||||
normal 0yss(
|
||||
call g:assert.equals(getline('.'), '(foo bar)', 'failed at #2')
|
||||
|
||||
call setline('.', 'foo bar')
|
||||
normal 04lyS(
|
||||
call g:assert.equals(getline('.'), 'foo (bar)', 'failed at #3')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02lds(
|
||||
call g:assert.equals(getline('.'), '[foo]', 'failed at #4')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02lds[
|
||||
call g:assert.equals(getline('.'), '(foo)', 'failed at #5')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02ldss
|
||||
call g:assert.equals(getline('.'), '[foo]', 'failed at #6')
|
||||
|
||||
call setline('.', '"''foo''"')
|
||||
normal 02ldss
|
||||
call g:assert.equals(getline('.'), '"foo"', 'failed at #7')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02lcs({
|
||||
call g:assert.equals(getline('.'), '[{foo}]', 'failed at #8')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02lcs[{
|
||||
call g:assert.equals(getline('.'), '{(foo)}', 'failed at #9')
|
||||
|
||||
call setline('.', '[(foo)]')
|
||||
normal 02lcss{
|
||||
call g:assert.equals(getline('.'), '[{foo}]', 'failed at #10')
|
||||
|
||||
call setline('.', '"''foo''"')
|
||||
normal 02lcss`
|
||||
call g:assert.equals(getline('.'), '"`foo`"', 'failed at #11')
|
||||
|
||||
call setline('.', 'foo')
|
||||
normal 0viwS(
|
||||
call g:assert.equals(getline('.'), '(foo)', 'failed at #12')
|
||||
endfunction "}}}
|
||||
|
||||
" vim:set foldmethod=marker:
|
||||
" vim:set commentstring="%s:
|
||||
@ -0,0 +1,72 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:suite = themis#suite('magicchar-f: ')
|
||||
|
||||
function! s:suite.before() abort "{{{
|
||||
nmap sd <Plug>(sandwich-delete)
|
||||
xmap sd <Plug>(sandwich-delete)
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:suite.before_each() abort "{{{
|
||||
%delete
|
||||
set filetype=
|
||||
unlet! g:sandwich#magicchar#f#patterns
|
||||
unlet! b:sandwich_magicchar_f_patterns
|
||||
unlet! g:sandwich#recipes g:operator#sandwich#recipes
|
||||
unlet! b:sandwich_recipes b:operator_sandwich_recipes
|
||||
call operator#sandwich#set_default()
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:suite.after() abort "{{{
|
||||
call s:suite.before_each()
|
||||
nunmap sd
|
||||
xunmap sd
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! s:suite.default_pattern() abort "{{{
|
||||
call setline('.', 'foo(bar)')
|
||||
call cursor(1, 1)
|
||||
normal sdf
|
||||
call g:assert.equals(getline('.'), 'bar', 'failed at #1')
|
||||
endfunction "}}}
|
||||
function! s:suite.global_pattern() abort "{{{
|
||||
let g:sandwich#magicchar#f#patterns = [
|
||||
\ {
|
||||
\ 'header' : '\<\%(\h\k*\.\)*\h\k*',
|
||||
\ 'bra' : '(',
|
||||
\ 'ket' : ')',
|
||||
\ 'footer' : '',
|
||||
\ },
|
||||
\ ]
|
||||
call setline('.', 'foo.bar(baz)')
|
||||
call cursor(1, 5)
|
||||
normal sdf
|
||||
call g:assert.equals(getline('.'), 'baz', 'failed at #1')
|
||||
endfunction "}}}
|
||||
function! s:suite.local_pattern() abort "{{{
|
||||
let g:sandwich#magicchar#f#patterns = [
|
||||
\ {
|
||||
\ 'header' : '\<\h\k*\.\h\k*',
|
||||
\ 'bra' : '(',
|
||||
\ 'ket' : ')',
|
||||
\ 'footer' : '',
|
||||
\ },
|
||||
\ ]
|
||||
let b:sandwich_magicchar_f_patterns = [
|
||||
\ {
|
||||
\ 'header' : '\<\%(\h\k*\.\)*\h\k*',
|
||||
\ 'bra' : '(',
|
||||
\ 'ket' : ')',
|
||||
\ 'footer' : '',
|
||||
\ },
|
||||
\ ]
|
||||
call setline('.', 'foo.bar.baz(qux)')
|
||||
call cursor(1, 9)
|
||||
normal sdf
|
||||
call g:assert.equals(getline('.'), 'qux', 'failed at #1')
|
||||
endfunction "}}}
|
||||
|
||||
|
||||
" vim:set foldmethod=marker:
|
||||
" vim:set commentstring="%s:
|
||||
@ -0,0 +1,536 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:suite = themis#suite('magicchar-t emmet-like behavior:')
|
||||
|
||||
let s:scope = themis#helper('scope')
|
||||
let s:t = s:scope.funcs('autoload/sandwich/magicchar/t.vim')
|
||||
|
||||
" test seeds "{{{
|
||||
let s:testseeds = {}
|
||||
let s:testseeds.element = [
|
||||
\ {
|
||||
\ 'input': 'element',
|
||||
\ 'token': ['element'],
|
||||
\ 'items': [{'name': 'element', 'value': 'element'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '',
|
||||
\ 'token': [],
|
||||
\ 'items': [{'name': 'element', 'value': 'div'}],
|
||||
\ },
|
||||
\ ]
|
||||
let s:testseeds.attributes = [
|
||||
\ {
|
||||
\ 'input': '#id1',
|
||||
\ 'token': ['#', 'id1'],
|
||||
\ 'items': [{'name': 'id', 'value': 'id1'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '#id2',
|
||||
\ 'token': ['#', 'id2'],
|
||||
\ 'items': [{'name': 'id', 'value': 'id2'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '#',
|
||||
\ 'token': ['#'],
|
||||
\ 'items': [{'name': 'id', 'value': ''}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '.class1',
|
||||
\ 'token': ['.', 'class1'],
|
||||
\ 'items': [{'name': 'class', 'value': ['class1']}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '.class2',
|
||||
\ 'token': ['.', 'class2'],
|
||||
\ 'items': [{'name': 'class', 'value': ['class2']}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '.',
|
||||
\ 'token': ['.'],
|
||||
\ 'items': [{'name': 'class', 'value': ['']}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr=hello]',
|
||||
\ 'token': ['[', 'attr', '=', 'hello', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': 'hello'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr=world]',
|
||||
\ 'token': ['[', 'attr', '=', 'world', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': 'world'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[hello=world]',
|
||||
\ 'token': ['[', 'hello', '=', 'world', ']'],
|
||||
\ 'items': [{'name': 'hello', 'value': 'world'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[]',
|
||||
\ 'token': ['[', ']'],
|
||||
\ 'items': [],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr="including space"]',
|
||||
\ 'token': ['[', 'attr', '=', '"including space"', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': '"including space"'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[ attr="including space"]',
|
||||
\ 'token': ['[', ' ', 'attr', '=', '"including space"', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': '"including space"'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr ="including space"]',
|
||||
\ 'token': ['[', 'attr', ' ', '=', '"including space"', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': '', 'value': '"including space"'},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr= "including space"]',
|
||||
\ 'token': ['[', 'attr', '=', ' ', '"including space"', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': '"including space"', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': '[attr="including space" ]',
|
||||
\ 'token': ['[', 'attr', '=', '"including space"', ' ', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': '"including space"'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr='including space']",
|
||||
\ 'token': ['[', 'attr', '=', "'including space'", ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': "'including space'"}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[ attr='including space']",
|
||||
\ 'token': ['[', ' ', 'attr', '=', "'including space'", ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': "'including space'"}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr ='including space']",
|
||||
\ 'token': ['[', 'attr', ' ', '=', "'including space'", ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ""},
|
||||
\ {'name': '', 'value': "'including space'"},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr= 'including space']",
|
||||
\ 'token': ['[', 'attr', '=', ' ', "'including space'", ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ""},
|
||||
\ {'name': "'including space'", 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr='including space' ]",
|
||||
\ 'token': ['[', 'attr', '=', "'including space'", ' ', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': "'including space'"}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr=withoutspace]",
|
||||
\ 'token': ['[', 'attr', '=', 'withoutspace', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': 'withoutspace'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[ attr=withoutspace]",
|
||||
\ 'token': ['[', ' ', 'attr', '=', 'withoutspace', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': 'withoutspace'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr =withoutspace]",
|
||||
\ 'token': ['[', 'attr', ' ', '=', 'withoutspace', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': '', 'value': 'withoutspace'},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr= withoutspace]",
|
||||
\ 'token': ['[', 'attr', '=', ' ', 'withoutspace', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': 'withoutspace', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr=withoutspace ]",
|
||||
\ 'token': ['[', 'attr', '=', 'withoutspace', ' ', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': 'withoutspace'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr=]",
|
||||
\ 'token': ['[', 'attr', '=', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': ''}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[ attr=]",
|
||||
\ 'token': ['[', ' ', 'attr', '=', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': ''}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr =]",
|
||||
\ 'token': ['[', 'attr', ' ', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr= ]",
|
||||
\ 'token': ['[', 'attr', '=', ' ', ']'],
|
||||
\ 'items': [{'name': 'attr', 'value': ''}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[=value]",
|
||||
\ 'token': ['[', '=', 'value', ']'],
|
||||
\ 'items': [{'name': '', 'value': 'value'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[ =value]",
|
||||
\ 'token': ['[', ' ', '=', 'value', ']'],
|
||||
\ 'items': [{'name': '', 'value': 'value'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[= value]",
|
||||
\ 'token': ['[', '=', ' ', 'value', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': 'value', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[=value ]",
|
||||
\ 'token': ['[', '=', 'value', ' ', ']'],
|
||||
\ 'items': [{'name': '', 'value': 'value'}],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[==]",
|
||||
\ 'token': ['[', '=', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[ ==]",
|
||||
\ 'token': ['[', ' ', '=', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[= =]",
|
||||
\ 'token': ['[', '=', ' ', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[== ]",
|
||||
\ 'token': ['[', '=', '=', ' ', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr==]",
|
||||
\ 'token': ['[', 'attr', '=', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr', 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[=value=]",
|
||||
\ 'token': ['[', '=', 'value', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': 'value'},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[==value]",
|
||||
\ 'token': ['[', '=', '=', 'value', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': 'value'},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "['word1 word2'==]",
|
||||
\ 'token': ['[', "'word1 word2'", '=', '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': "'word1 word2'", 'value': ''},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[='word1 word2'=]",
|
||||
\ 'token': ['[', '=', "'word1 word2'", '=', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': "'word1 word2'"},
|
||||
\ {'name': '', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[=='word1 word2']",
|
||||
\ 'token': ['[', '=', '=', "'word1 word2'", ']'],
|
||||
\ 'items': [
|
||||
\ {'name': '', 'value': ''},
|
||||
\ {'name': '', 'value': "'word1 word2'"},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr1=value1 attr2=value2]",
|
||||
\ 'token': ['[', 'attr1', '=', 'value1', ' ', 'attr2', '=', 'value2', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr1', 'value': 'value1'},
|
||||
\ {'name': 'attr2', 'value': 'value2'},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr1=value1 attr2]",
|
||||
\ 'token': ['[', 'attr1', '=', 'value1', ' ', 'attr2', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr1', 'value': 'value1'},
|
||||
\ {'name': 'attr2', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr1 attr2=value2]",
|
||||
\ 'token': ['[', 'attr1', ' ', 'attr2', '=', 'value2', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr1', 'value': ''},
|
||||
\ {'name': 'attr2', 'value': 'value2'},
|
||||
\ ],
|
||||
\ },
|
||||
\
|
||||
\ {
|
||||
\ 'input': "[attr1 attr2]",
|
||||
\ 'token': ['[', 'attr1', ' ', 'attr2', ']'],
|
||||
\ 'items': [
|
||||
\ {'name': 'attr1', 'value': ''},
|
||||
\ {'name': 'attr2', 'value': ''},
|
||||
\ ],
|
||||
\ },
|
||||
\ ]
|
||||
function! s:testseeds.generate_parsed(itemlist) dict abort "{{{
|
||||
let itemlist = deepcopy(a:itemlist)
|
||||
call s:overwrite(itemlist, 'id')
|
||||
call s:append(itemlist, 'class')
|
||||
let custom_attr_list = map(filter(deepcopy(itemlist), 'has_key(v:val, "name") && v:val.name !~# ''\%(element\|id\|class\)'''), 'v:val.name')
|
||||
call s:uniq(filter(custom_attr_list, 'v:val !=# ""'))
|
||||
for attr in custom_attr_list
|
||||
call s:overwrite(itemlist, attr)
|
||||
endfor
|
||||
return itemlist
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:overwrite(itemlist, name) abort "{{{
|
||||
let i = 0
|
||||
let n = len(a:itemlist)
|
||||
let i_target = -1
|
||||
while i < n
|
||||
let item = a:itemlist[i]
|
||||
if item.name ==# a:name
|
||||
let i_target = i
|
||||
break
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
if i_target > 0
|
||||
let i = n - 1
|
||||
let value = ''
|
||||
let value_is_fixed = 0
|
||||
while i > i_target
|
||||
let item = a:itemlist[i]
|
||||
if item.name ==# a:name
|
||||
if !value_is_fixed
|
||||
let value = item.value
|
||||
let value_is_fixed = 1
|
||||
endif
|
||||
call remove(a:itemlist, i)
|
||||
endif
|
||||
let i -= 1
|
||||
endwhile
|
||||
if value_is_fixed
|
||||
let a:itemlist[i_target]['value'] = value
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:append(itemlist, name) abort "{{{
|
||||
let i = 0
|
||||
let n = len(a:itemlist)
|
||||
let i_target = -1
|
||||
while i < n
|
||||
let item = a:itemlist[i]
|
||||
if item.name ==# a:name
|
||||
let i_target = i
|
||||
break
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
if i_target > 0
|
||||
let i = n - 1
|
||||
let value = []
|
||||
while i > i_target
|
||||
let item = a:itemlist[i]
|
||||
if item.name ==# a:name
|
||||
let value += item.value
|
||||
call remove(a:itemlist, i)
|
||||
endif
|
||||
let i -= 1
|
||||
endwhile
|
||||
if value !=# []
|
||||
let a:itemlist[i_target]['value'] += reverse(value)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:uniq(list) abort "{{{
|
||||
let i = len(a:list) - 1
|
||||
while i > 0
|
||||
let item = a:list[i]
|
||||
if count(a:list, item) > 1
|
||||
call remove(a:list, i)
|
||||
endif
|
||||
let i -= 1
|
||||
endwhile
|
||||
return a:list
|
||||
endfunction
|
||||
"}}}
|
||||
"}}}
|
||||
|
||||
function! s:suite.tokenize() dict abort "{{{
|
||||
" happy paths
|
||||
|
||||
" 1 seed
|
||||
for element in deepcopy(s:testseeds.element)
|
||||
for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
let input = join([element.input, attribute1.input], '')
|
||||
let expect = element.token + attribute1.token
|
||||
call g:assert.equals(s:t.tokenize(input), expect, 'input: ' . input)
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" 2 seeds
|
||||
for element in deepcopy(s:testseeds.element)
|
||||
for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
for attribute2 in deepcopy(s:testseeds.attributes)
|
||||
let input = join([element.input, attribute1.input, attribute2.input], '')
|
||||
let expect = element.token + attribute1.token + attribute2.token
|
||||
call g:assert.equals(s:t.tokenize(input), expect, 'input: ' . input)
|
||||
endfor
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" " 3 seeds
|
||||
" for element in deepcopy(s:testseeds.element)
|
||||
" for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
" for attribute2 in deepcopy(s:testseeds.attributes)
|
||||
" for attribute3 in deepcopy(s:testseeds.attributes)
|
||||
" let input = join([element.input, attribute1.input, attribute2.input, attribute3.input], '')
|
||||
" let expect = element.token + attribute1.token + attribute2.token + attribute3.token
|
||||
" call g:assert.equals(s:t.tokenize(input), expect, 'input: ' . input)
|
||||
" endfor
|
||||
" endfor
|
||||
" endfor
|
||||
" endfor
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:suite.parse() dict abort "{{{
|
||||
" happy paths
|
||||
|
||||
" 1 seed
|
||||
for element in deepcopy(s:testseeds.element)
|
||||
for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
let input = element.token + attribute1.token
|
||||
let expect = s:testseeds.generate_parsed(element.items + attribute1.items)
|
||||
call g:assert.equals(s:t.parse(input), expect, 'input: ' . string(input))
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" 2 seeds
|
||||
for element in deepcopy(s:testseeds.element)
|
||||
for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
for attribute2 in deepcopy(s:testseeds.attributes)
|
||||
let input = element.token + attribute1.token + attribute2.token
|
||||
let expect = s:testseeds.generate_parsed(element.items + attribute1.items + attribute2.items)
|
||||
call g:assert.equals(s:t.parse(input), expect, 'input: ' . string(input))
|
||||
endfor
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" " 3 seeds
|
||||
" for element in deepcopy(s:testseeds.element)
|
||||
" for attribute1 in deepcopy(s:testseeds.attributes)
|
||||
" for attribute2 in deepcopy(s:testseeds.attributes)
|
||||
" for attribute3 in deepcopy(s:testseeds.attributes)
|
||||
" let input = element.token + attribute1.token + attribute2.token + attribute3.token
|
||||
" let expect = s:testseeds.generate_parsed(element.items + attribute1.items + attribute2.items + attribute3.items)
|
||||
" call g:assert.equals(s:t.parse(input), expect, 'input: ' . string(input))
|
||||
" endfor
|
||||
" endfor
|
||||
" endfor
|
||||
" endfor
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" vim:set foldmethod=marker:
|
||||
" vim:set commentstring="%s:
|
||||
@ -0,0 +1,91 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:suite = themis#suite('magicchar-t:')
|
||||
|
||||
let s:scope = themis#helper('scope')
|
||||
let s:t = s:scope.funcs('autoload/sandwich/magicchar/t.vim')
|
||||
|
||||
|
||||
function! s:suite.before() abort "{{{
|
||||
nmap sa <Plug>(sandwich-add)
|
||||
xmap sa <Plug>(sandwich-add)
|
||||
omap sa <Plug>(sandwich-add)
|
||||
nmap sd <Plug>(sandwich-delete)
|
||||
xmap sd <Plug>(sandwich-delete)
|
||||
nmap sr <Plug>(sandwich-replace)
|
||||
xmap sr <Plug>(sandwich-replace)
|
||||
endfunction
|
||||
"}}}
|
||||
function! s:suite.after() abort "{{{
|
||||
nunmap sa
|
||||
xunmap sa
|
||||
ounmap sa
|
||||
nunmap sd
|
||||
xunmap sd
|
||||
nunmap sr
|
||||
xunmap sr
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! s:suite.add() abort "{{{
|
||||
" #1
|
||||
call setline(1, 'foo')
|
||||
execute "normal 1Gsaiwtp\<CR>"
|
||||
call g:assert.equals(getline(1), '<p>foo</p>', 'failed at #1')
|
||||
|
||||
" #2
|
||||
call setline(1, 'foo')
|
||||
execute "normal 1GsaiwTp\<CR>"
|
||||
call g:assert.equals(getline(1), '<p>foo</p>', 'failed at #2')
|
||||
endfunction "}}}
|
||||
function! s:suite.delete() abort "{{{
|
||||
" #1
|
||||
call setline(1, '<p>foo</p>')
|
||||
normal 1Gsdt
|
||||
call g:assert.equals(getline(1), 'foo', 'failed at #1')
|
||||
|
||||
" #2
|
||||
call setline(1, '<p>foo</p>')
|
||||
normal 1GsdT
|
||||
call g:assert.equals(getline(1), 'foo', 'failed at #2')
|
||||
endfunction "}}}
|
||||
function! s:suite.replace() abort "{{{
|
||||
" #1
|
||||
call setline(1, '<p>foo</p>')
|
||||
execute "normal 1Gffsrttdiv\<CR>"
|
||||
call g:assert.equals(getline(1), '<div>foo</div>', 'failed at #1')
|
||||
|
||||
" #2
|
||||
call setline(1, '<p>foo</p>')
|
||||
execute "normal 1GffsrTTdiv\<CR>"
|
||||
call g:assert.equals(getline(1), '<div>foo</div>', 'failed at #2')
|
||||
|
||||
" #3
|
||||
call setline(1, '<div title="foo">foo</div>')
|
||||
execute "normal 1Gffsrttp\<CR>"
|
||||
call g:assert.equals(getline(1), '<p title="foo">foo</p>', 'failed at #3')
|
||||
|
||||
" #4
|
||||
call setline(1, '<div title="foo">foo</div>')
|
||||
execute "normal 1GffsrTTp\<CR>"
|
||||
call g:assert.equals(getline(1), '<p>foo</p>', 'failed at #4')
|
||||
endfunction "}}}
|
||||
function! s:suite.add_selection_exclusive() abort "{{{
|
||||
set selection=exclusive
|
||||
call s:suite.add()
|
||||
set selection=inclusive
|
||||
endfunction "}}}
|
||||
function! s:suite.delete_selection_exclusive() abort "{{{
|
||||
set selection=exclusive
|
||||
call s:suite.delete()
|
||||
set selection=inclusive
|
||||
endfunction "}}}
|
||||
function! s:suite.replace_selection_exclusive() abort "{{{
|
||||
set selection=exclusive
|
||||
call s:suite.replace()
|
||||
set selection=inclusive
|
||||
endfunction "}}}
|
||||
|
||||
|
||||
" vim:set foldmethod=marker:
|
||||
" vim:set commentstring="%s:
|
||||
5800
config/neovim/store/lazy-plugins/vim-sandwich/test/textobj-auto.vim
Normal file
5800
config/neovim/store/lazy-plugins/vim-sandwich/test/textobj-auto.vim
Normal file
File diff suppressed because it is too large
Load Diff
5628
config/neovim/store/lazy-plugins/vim-sandwich/test/textobj-query.vim
Normal file
5628
config/neovim/store/lazy-plugins/vim-sandwich/test/textobj-query.vim
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user