mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 12:44:27 +08:00
Moved debugging functions outside script files.
This commit is contained in:
1
Makefile
1
Makefile
@@ -8,6 +8,7 @@ install:
|
||||
cp -f doc/${PLUGIN}.txt ~/.vim/doc/${PLUGIN}.txt
|
||||
cp -f plugin/${PLUGIN}.vim ~/.vim/plugin/${PLUGIN}.vim
|
||||
cp -f autoload/${PLUGIN}.vim ~/.vim/autoload/${PLUGIN}.vim
|
||||
cp -f autoload/${PLUGIN}Tests.vim ~/.vim/autoload/${PLUGIN}Tests.vim
|
||||
|
||||
doc_update: install
|
||||
/usr/bin/vim -u NONE -c ':helptags ~/.vim/doc' -c ':q'
|
||||
|
||||
@@ -439,7 +439,7 @@ function! delimitMate#VisualMaps() " {{{
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||
for del in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
|
||||
exec "vnoremap <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '"') . '")'
|
||||
exec "vnoremap <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '")') . '")'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
@@ -568,222 +568,6 @@ function! delimitMate#TestMappings() "{{{
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#Tests() " {{{
|
||||
if !exists("g:delimitMate_testing")
|
||||
echoerr "delimitMate#Tests(): You shouldn't use this function!"
|
||||
return
|
||||
endif
|
||||
let b:test_results = {}
|
||||
function! SetOptions(list) " {{{
|
||||
let b:delimitMate_autoclose = 1
|
||||
let b:delimitMate_matchpairs = &matchpairs
|
||||
let b:delimitMate_quotes = "\" ' `"
|
||||
let b:delimitMate_excluded_regions = ["Comment"]
|
||||
silent! unlet b:delimitMate_visual_leader
|
||||
let b:delimitMate_expand_space = 0
|
||||
let b:delimitMate_expand_cr = 0
|
||||
let b:delimitMate_smart_quotes = 1
|
||||
let b:delimitMate_apostrophes = ""
|
||||
let b:delimitMate_tab2exit = 1
|
||||
" Set current test options:
|
||||
for str in a:list
|
||||
let pair = split(str, ':')
|
||||
exec "let b:delimitMate_" . pair[0] . " = " . pair[1]
|
||||
endfor
|
||||
DelimitMateReload
|
||||
endfunction " }}}
|
||||
|
||||
function! Type(name, input, output, options) " {{{
|
||||
" Set default options:
|
||||
call SetOptions(a:options)
|
||||
normal ggVG"_d
|
||||
exec "normal i" . a:input . "|\<Esc>"
|
||||
call setpos('.', [0, 1, 1, 0])
|
||||
let result = len(a:output) != line('$')
|
||||
for line in a:output
|
||||
if getline('.') != line || result == 1
|
||||
let result = 1
|
||||
break
|
||||
endif
|
||||
call setpos('.', [0, line('.') + 1, 1, 0])
|
||||
endfor
|
||||
let text = getline('.')
|
||||
let i = 2
|
||||
while i <= line('$')
|
||||
let text = text . "<cr>" . getline(i)
|
||||
let i += 1
|
||||
endwhile
|
||||
echom "text: " . text
|
||||
if result == 0
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed: ' . text . ' == ' . join(a:output, '<cr>')"
|
||||
else
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! RepeatLast(name, output) " {{{
|
||||
normal gg.
|
||||
call setpos('.', [0, 1, 1, 0])
|
||||
let result = len(a:output) != line('$')
|
||||
for line in a:output
|
||||
echom line . " vs " . getline('.')
|
||||
if getline('.') != line || result == 1
|
||||
let result = 1
|
||||
break
|
||||
endif
|
||||
call setpos('.', [0, line('.') + 1, 1, 0])
|
||||
endfor
|
||||
let text = getline('1')
|
||||
let i = 2
|
||||
while i <= line('$')
|
||||
let text = text . "<cr>" . getline(i)
|
||||
let i += 1
|
||||
endwhile
|
||||
if result == 0
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Passed: ' . text . ' == ' . join(a:output, '<cr>')"
|
||||
else
|
||||
exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "_R'] = 'Failed: ' . text . ' != ' . join(a:output, '<cr>')"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
" Test's test
|
||||
call Type("Test 1", "123", ["123|"], [])
|
||||
call RepeatLast("Test 1", ["123|123|"])
|
||||
|
||||
" Auto-closing parens
|
||||
call Type("Autoclose parens", "(", ["(|)"], [])
|
||||
call RepeatLast("Autoclose_parens", ["(|)(|)"])
|
||||
|
||||
" Auto-closing quotes
|
||||
call Type("Autoclose quotes", '"', ['"|"'], [])
|
||||
call RepeatLast("Autoclose_quotes", ['"|""|"'])
|
||||
|
||||
" Deleting parens
|
||||
call Type("Delete empty parens", "(\<BS>", ["|"], [])
|
||||
call RepeatLast("Delete empty parens", ["||"])
|
||||
|
||||
" Deleting quotes
|
||||
call Type("Delete emtpy quotes", "\"\<BS>", ['|'], [])
|
||||
call RepeatLast("Delete empty quotes", ["||"])
|
||||
|
||||
" Manual closing parens
|
||||
call Type("Manual closing parens", "()", ["(|)"], ["autoclose:0"])
|
||||
call RepeatLast("Manual closing parens", ["(|)(|)"])
|
||||
|
||||
" Manual closing quotes
|
||||
call Type("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"])
|
||||
call RepeatLast("Manual closing quotes", ['"|""|"'])
|
||||
|
||||
" Jump over paren
|
||||
call Type("Jump over paren", "()", ['()|'], [])
|
||||
call RepeatLast("Jump over paren", ['()|()|'])
|
||||
|
||||
" Jump over quote
|
||||
call Type("Jump over quote", "\"\"", ['""|'], [])
|
||||
call RepeatLast("Jump over quote", ['""|""|'])
|
||||
|
||||
" Apostrophe
|
||||
call Type("Apostrophe", "test'", ["test'|"], [])
|
||||
call RepeatLast("Apostrophe", ["test'|test'|"])
|
||||
|
||||
" Close quote
|
||||
call Type("Close quote", "'\<Del>\<Esc>a'", ["'|'"], [])
|
||||
|
||||
" Closing paren
|
||||
call Type("Closing paren", "abcd)", ["abcd)|"], [])
|
||||
|
||||
" <S-Tab>
|
||||
call Type("S Tab", "(\<S-Tab>", ["()|"], [])
|
||||
call RepeatLast("S Tab", ["()|()|"])
|
||||
|
||||
" Space expansion
|
||||
call Type("Space expansion", "(\<Space>", ['( | )'], ['expand_space:1'])
|
||||
call RepeatLast("Space expansion", ['( | )( | )'])
|
||||
|
||||
" Car return expansion
|
||||
call Type("CR expansion", "(\<CR>", ['(', '|', ')'], ['expand_cr:1'])
|
||||
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping left paren", "1234\<Esc>v,(", ['123(4)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping left paren", ['(1)23(4)'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping left paren", "1234\<Esc>V,(", ['(1234)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping left paren", ['((1234))'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping right paren", "1234\<Esc>v,)", ['123(4)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping right paren", ['(1)23(4)'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping right paren", "1234\<Esc>V,)", ['(1234)'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping right paren", ['((1234))'])
|
||||
|
||||
" Visual wrapping
|
||||
call Type("Visual wrapping quote", "1234\<Esc>v,\"", ['123"4"'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual wrapping quote", ['"1"23"4"'])
|
||||
|
||||
" Visual line wrapping
|
||||
call Type("Visual line wrapping quote", "1234\<Esc>V,\"", ['"1234"'], ['visual_leader:","'])
|
||||
cal RepeatLast("Visual line wrapping quote", ['""1234""'])
|
||||
|
||||
" Visual line wrapping empty line
|
||||
call Type("Visual line wrapping paren empty line", "\<Esc>V,(", ['()'], ['visual_leader:","'])
|
||||
|
||||
" Visual line wrapping empty line
|
||||
call Type("Visual line wrapping quote empty line", "\<Esc>V,\"", ['""'], ['visual_leader:","'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote alphanumeric", "alpha\"numeric", ['alpha"numeric|'], [])
|
||||
call RepeatLast("Smart quote alphanumeric", ['alpha"numeric|alpha"numeric|'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote escaped", "esc\\\"", ['esc\"|'], [])
|
||||
call RepeatLast("Smart quote escaped", ['esc\"|esc\"|'])
|
||||
|
||||
" Smart quotes
|
||||
call Type("Smart quote apostrophe", "I'm", ["I'm|"], ['smart_quotes:0'])
|
||||
call RepeatLast("Smart quote escaped", ["I'm|I'm|"])
|
||||
|
||||
" Backspace inside space expansion
|
||||
call Type("Backspace inside space expansion", "(\<Space>\<BS>", ['(|)'], ['expand_space:1'])
|
||||
call RepeatLast("Backspace inside space expansion", ['(|)(|)'])
|
||||
|
||||
" Backspace inside CR expansion
|
||||
call Type("Backspace inside CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
|
||||
call RepeatLast("Backspace inside CR expansion", ['(|)(|)'])
|
||||
|
||||
" FileType event
|
||||
let g:delimitMate_excluded_ft = "vim"
|
||||
set ft=vim
|
||||
call Type("FileType Autoclose parens", "(", ["(|"], [])
|
||||
unlet g:delimitMate_excluded_ft
|
||||
set ft=
|
||||
|
||||
|
||||
" Show results: {{{
|
||||
normal ggVG"_d
|
||||
call append(0, split(string(b:test_results)[1:-2], ', '))
|
||||
normal "_ddgg
|
||||
nmap <F1> :q!<CR>
|
||||
let @/ = ".\\+Failed:.*!="
|
||||
set nohlsearch
|
||||
"syntax match failedLine "^.*Failed.*$" contains=ALL
|
||||
"syn match passedLine ".*Passed.*"
|
||||
syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
|
||||
syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
|
||||
syn match resultPassed "\('Passed: \)\@<=.\+\('$\)\@="
|
||||
syn match resultFailed "\('Failed: \)\@<=.\+\('$\)\@=" contains=resultInequal
|
||||
syn match resultInequal "!="
|
||||
|
||||
hi def link labelPassed Comment
|
||||
hi def link labelFailed Special
|
||||
hi def link resultPassed Ignore
|
||||
hi def link resultFailed Boolean
|
||||
hi def link resultInequal Error
|
||||
" }}}
|
||||
endfunction " }}}
|
||||
"}}}
|
||||
|
||||
" vim:foldmethod=marker:foldcolumn=4
|
||||
|
||||
@@ -68,9 +68,10 @@ function! s:Init() "{{{
|
||||
elseif exists("g:delimitMate_excluded_regions")
|
||||
let s:excluded_regions = g:delimitMate_excluded_regions
|
||||
else
|
||||
let s:excluded_regions = split("Comment")
|
||||
let s:excluded_regions = "Comment"
|
||||
endif
|
||||
let b:delimitMate_excluded_regions_list = s:excluded_regions " }}}
|
||||
let b:delimitMate_excluded_regions_list = split(s:excluded_regions) " }}}
|
||||
let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list)
|
||||
|
||||
" delimitMate_visual_leader {{{
|
||||
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader")
|
||||
|
||||
Reference in New Issue
Block a user