Skip to content

Commit

Permalink
FEAT: move s:prepare into vader#window#execute
Browse files Browse the repository at this point in the history
While this means more overhead in general, it allows to access
script-local variables in the tests.

squash! FEAT: move s:prepare into vader#window#execute

Use `vader#log` directly instead of `:Log`, since the latter might not
be defined (yet).
  • Loading branch information
blueyed committed Mar 11, 2017
1 parent 34b516e commit beec226
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
43 changes: 14 additions & 29 deletions autoload/vader.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function! vader#run(bang, ...) range
endif

call vader#assert#reset()
call s:prepare()
try
let all_cases = []
let qfl = []
Expand Down Expand Up @@ -182,34 +181,20 @@ function! vader#restore(args)
endfor
endfunction

function! s:prepare()
command! -nargs=+ Log :call vader#log(<args>)
command! -nargs=+ Save :call vader#save(<q-args>)
command! -nargs=* Restore :call vader#restore(<q-args>)
command! -nargs=+ Assert :call vader#assert#true(<args>)
command! -nargs=+ AssertEqual :call vader#assert#equal(<args>)
command! -nargs=+ AssertNotEqual :call vader#assert#not_equal(<args>)
command! -nargs=+ AssertThrows :call vader#assert#throws(<q-args>)
function! SyntaxAt(...) abort
return call('vader#helper#syntax_at', a:000)
endfunction
function! SyntaxOf(...) abort
return call('vader#helper#syntax_of', a:000)
endfunction
endfunction

function! s:cleanup()
let s:register = {}
let s:register_undefined = []
delcommand Log
delcommand Save
delcommand Restore
delcommand Assert
delcommand AssertEqual
delcommand AssertNotEqual
delcommand AssertThrows
unlet g:SyntaxAt
unlet g:SyntaxOf
if exists(':Log') == 2
delcommand Log
delcommand Save
delcommand Restore
delcommand Assert
delcommand AssertEqual
delcommand AssertNotEqual
delcommand AssertThrows
delfunction SyntaxAt
delfunction SyntaxOf
endif
endfunction

function! s:comment(case, label)
Expand Down Expand Up @@ -268,9 +253,9 @@ function! s:execute(prefix, type, block, fpos, lang_if)
call filter(tb_entries, "v:val !~# '\\vvader#assert#[^,]+, line \\d+$'")
for tb_entry in tb_entries
let [source, _, f] = s:get_source_linenr_from_tb_entry(tb_entry)
Log 'in '.f
call vader#log('in '.f)
if len(source)
Log ' '.source
call vader#log(' '.source)
endif
endfor
let tb_first = substitute(tb_first, '^function ', '', '')
Expand All @@ -287,7 +272,7 @@ endfunction

function! s:print_throwpoint()
if v:throwpoint !~ 'vader#assert'
Log v:throwpoint
call vader#log(v:throwpoint)
endif
endfunction

Expand Down
24 changes: 20 additions & 4 deletions autoload/vader/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,30 @@ endfunction
function! vader#window#execute(lines, lang_if)
let temp = tempname()
try
let lines = [
\ 'command! -nargs=+ Log :call vader#log(<args>)',
\ 'command! -nargs=+ Save :call vader#save(<q-args>)',
\ 'command! -nargs=* Restore :call vader#restore(<q-args>)',
\ 'command! -nargs=+ Assert :call vader#assert#true(<args>)',
\ 'command! -nargs=+ AssertEqual :call vader#assert#equal(<args>)',
\ 'command! -nargs=+ AssertNotEqual :call vader#assert#not_equal(<args>)',
\ 'command! -nargs=+ AssertThrows :call vader#assert#throws(<q-args>)',
\ 'function! SyntaxAt(...) abort',
\ " return call('vader#helper#syntax_at', a:000)",
\ 'endfunction',
\ 'function! SyntaxOf(...) abort',
\ " return call('vader#helper#syntax_of', a:000)",
\ 'endfunction',
\ ]

call add(lines, 'function! s:vader_wrapper()')
if empty(a:lang_if)
let lines = copy(a:lines)
call extend(lines, copy(a:lines))
else
let lines = copy(a:lines)
call insert(lines, a:lang_if . ' << __VADER__LANG__IF__')
call add(lines, a:lang_if . ' << __VADER__LANG__IF__')
call extend(lines, copy(a:lines))
call add(lines, '__VADER__LANG__IF__')
endif
call insert(lines, 'function! s:vader_wrapper()')
call extend(lines, ['endfunction', 'call s:vader_wrapper()'])
call writefile(lines, temp)
execute 'source '.temp
Expand Down
9 changes: 9 additions & 0 deletions test/feature/helper.vader
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ Execute (SyntaxOf does not move cursor):
let pos = getpos('.')
AssertEqual pos[1], 2
AssertEqual pos[2], 1

Execute (Helpers can access script-local var):
let s:foo = 1
AssertEqual s:foo, 1

function! s:foo()
return 2
endfunction
Assert s:foo() == 2, 'function s:foo should be callable'

0 comments on commit beec226

Please sign in to comment.