/
luatest.vim
47 lines (39 loc) · 1.13 KB
/
luatest.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
" Matt, recall that \v is a starting modifier to Vimscript to mean "very
" magic." Because, of course it is. :|
if !exists('g:test#lua#luatest#file_pattern')
let g:test#lua#luatest#file_pattern = '\vtest_[^/]+\.lua$'
endif
let test#luatest#patterns = {
\ 'test': ['\vfunction\s+\w*\.?(\w+)\(\)'],
\ 'namespace': [],
\}
function! test#lua#luatest#test_file(file) abort
return a:file =~# g:test#lua#luatest#file_pattern
endfunction
function! test#lua#luatest#build_position(type, position) abort
if a:type ==# 'nearest'
let name = s:nearest_test(a:position)
if !empty(name)
return [a:position['file'].'::'.name]
else
return [a:position['file']]
endif
elseif a:type ==# 'file'
return [a:position['file']]
else
return []
endif
endfunction
function! test#lua#luatest#build_args(args) abort
return a:args
endfunction
function! test#lua#luatest#executable() abort
return 'luatest'
endfunction
function! s:nearest_test(position) abort
let name = test#base#nearest_test(a:position, g:test#luatest#patterns)
if !empty(name['test'])
return name['test'][0]
endif
return ""
endfunction