This commit is contained in:
Yasuhiro Matsumoto
2017-12-07 00:13:40 +09:00
parent 1c6b56f0e0
commit 5181a02a09
2 changed files with 46 additions and 18 deletions

View File

@@ -9,3 +9,7 @@ emmet-vim.zip: remove-zip
release: emmet-vim.zip release: emmet-vim.zip
vimup update-script emmet.vim vimup update-script emmet.vim
test:
@rm test.log
@vim --clean -N -c "let &rtp .= ',' . getcwd()" -c "so unittest.vim" -c EmmetUnitTest! || cat test.log || exit 1

View File

@@ -1,5 +1,6 @@
" {{{ " {{{
let s:sfile = expand('<sfile>') let s:sfile = expand('<sfile>')
let s:logging = 0
function! s:reload(d) function! s:reload(d)
exe 'so' a:d.'/plugin/emmet.vim' exe 'so' a:d.'/plugin/emmet.vim'
@@ -8,22 +9,32 @@ function! s:reload(d)
endfor endfor
endfunction endfunction
function! s:logn(msg)
echon a:msg
call writefile([a:msg, ''], "test.log", "ab")
endfunction
function! s:log(msg)
echo a:msg
call writefile(split(a:msg, "\n"), "test.log", "ab")
endfunction
function! s:show_type(type) function! s:show_type(type)
echohl Search | echon '[' a:type "]\n" | echohl None echohl Search | call s:log('['.a:type.']') | echohl None
echo "\r" echo "\r"
endfunction endfunction
function! s:show_category(category) function! s:show_category(category)
echohl MatchParen | echon '[' a:category "]\n" | echohl None echohl MatchParen | call s:log('['.a:category.']') | echohl None
echo "\r" echo "\r"
endfunction endfunction
function! s:show_pass(pass) function! s:show_pass(pass)
echohl Title | echo 'pass'.a:pass."\n" | echohl None echohl Title | call s:log('pass '.substitute(a:pass, '\s', '', 'g')) | echohl None
endfunction endfunction
function! s:show_done() function! s:show_done()
echohl IncSearch | echo 'done' | echohl None echohl IncSearch | call s:log('done') | echohl None
endfunction endfunction
function! s:escape(str) function! s:escape(str)
@@ -36,37 +47,39 @@ endfunction
function! s:show_title(no, title) function! s:show_title(no, title)
let title = s:escape(a:title) let title = s:escape(a:title)
let width = &columns - 23 let width = &columns - 23
echohl MoreMsg | echon "\rtesting #".printf('%03d', a:no) echon "\r"
echohl None | echon ': ' . (len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)) . ' ... ' echohl MoreMsg | call s:logn('testing #'.printf('%03d', a:no))
echohl None | call s:logn(': '.(len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)).' ... ')
endfunction endfunction
function! s:show_skip(no, title) function! s:show_skip(no, title)
let title = s:escape(a:title) let title = s:escape(a:title)
let width = &columns - 23 let width = &columns - 23
echohl WarningMsg | echon "\rskipped #".printf('%03d', a:no) echon "\r"
echohl None | echon ': ' . (len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)) . ' ... ' echohl WarningMsg | call s:logn('skipped #'.printf('%03d', a:no))
echohl None | call s:logn(': '.(len(title) < width ? (title.repeat(' ', width-len(title))) : strpart(title, 0, width)).' ... ')
echo '' echo ''
endfunction endfunction
function! s:show_ok() function! s:show_ok()
echohl Title | echon "ok\n" | echohl None echohl Title | call s:logn('ok') | echohl None
echo '' echo ''
endfunction endfunction
function! s:show_ng(no, expect, got) function! s:show_ng(no, expect, got)
echohl WarningMsg | echon "ng\n" | echohl None echohl WarningMsg | call s:logn('ng') | echohl None
echohl ErrorMsg | echo 'failed test #'.a:no | echohl None echohl ErrorMsg | call s:log('failed test #'.a:no) | echohl None
set more set more
echohl WarningMsg | echo printf('expect(%d):', len(a:expect)) | echohl None echohl WarningMsg | call s:log(printf('expect(%d):', len(a:expect))) | echohl None
echo join(split(a:expect, "\n", 1), "|\n") echo join(split(a:expect, "\n", 1), "|\n")
echohl WarningMsg | echo printf('got(%d):', len(a:got)) | echohl None echohl WarningMsg | call s:log(printf('got(%d):', len(a:got))) | echohl None
echo join(split(a:got, "\n", 1), "|\n") call s:log(join(split(a:got, "\n", 1), "|\n"))
let cs = split(a:expect, '\zs') let cs = split(a:expect, '\zs')
for c in range(len(cs)) for c in range(len(cs))
if c < len(a:got) if c < len(a:got)
if a:expect[c] != a:got[c] if a:expect[c] != a:got[c]
echohl WarningMsg | echo 'differ at:' | echohl None echohl WarningMsg | call s:log('differ at:') | echohl None
echo a:expect[c :-1] call s:log(a:expect[c :-1])
break break
endif endif
endif endif
@@ -155,8 +168,9 @@ function! s:test(...)
endfor endfor
endfunction endfunction
function! s:do_tests(...) function! s:do_tests(bang, ...)
try try
let s:logging = a:bang
if exists('g:user_emmet_settings') if exists('g:user_emmet_settings')
let s:old_user_emmet_settings = g:user_emmet_settings let s:old_user_emmet_settings = g:user_emmet_settings
endif endif
@@ -166,8 +180,14 @@ function! s:do_tests(...)
let &more = 0 let &more = 0
call call('s:test', a:000) call call('s:test', a:000)
call s:show_done() call s:show_done()
if a:bang == '!'
qall!
endif
catch catch
echohl ErrorMsg | echomsg v:exception | echohl None echohl ErrorMsg | echomsg v:exception | echohl None
if a:bang == '!'
cquit!
endif
finally finally
let &more=oldmore let &more=oldmore
if exists('s:old_user_emmet_settings') if exists('s:old_user_emmet_settings')
@@ -190,7 +210,7 @@ function! s:emmet_unittest_complete(arglead, cmdline, cmdpos)
return [] return []
endfunction endfunction
command! -nargs=* -complete=customlist,<SID>emmet_unittest_complete EmmetUnitTest call s:do_tests(<f-args>) command! -bang -nargs=* -complete=customlist,<SID>emmet_unittest_complete EmmetUnitTest call s:do_tests("<bang>", <f-args>)
if s:sfile == expand('%:p') if s:sfile == expand('%:p')
EmmetUnitTest EmmetUnitTest
endif endif
@@ -561,6 +581,10 @@ finish
'query': "<div onclick=\"javascript:console.log(Date.now() % 1000 > 500)\">test$$$$\\<c-y>j$$$$/>\n</div>", 'query': "<div onclick=\"javascript:console.log(Date.now() % 1000 > 500)\">test$$$$\\<c-y>j$$$$/>\n</div>",
'result': "<div onclick=\"javascript:console.log(Date.now() % 1000 > 500)\" />", 'result': "<div onclick=\"javascript:console.log(Date.now() % 1000 > 500)\" />",
}, },
{
'query': "<div>\n\t<some-tag$$$$\\<c-y>j$$$$/>\n</div>",
'result': "<div>\n\t<some-tag></some-tag>\n</div>",
},
], ],
}, },
{ {