-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathvimspector_test.vim
115 lines (90 loc) · 2.95 KB
/
vimspector_test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
" vimspector - A multi-language debugging system for Vim
" Copyright 2018 Ben Jackson
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.
" Compiler plugin to help running vimspector tests
if exists("current_compiler")
finish
endif
let current_compiler = "vimspector_test"
setlocal errorformat=
\Found\ errors\ in\ %f:%.%#:
let &l:makeprg=fnamemodify( findfile( 'run_tests', '.;' ), ':p' )
\ . ' $* 2>&1'
let s:make_cmd = get( g:, 'vimspector_test_make_cmd', 'Make' )
" If :Make doesn't exist, then use :make
if ! exists( ':' . s:make_cmd )
let s:make_cmd = 'make'
endif
function! VimGetCurrentFunction()
echom s:GetCurrentFunction()
endfunction
function! s:GetCurrentFunction()
" Store the cursor position; we'll need to reset it
let [ l:buf, l:row, l:col, l:offset ] = getpos( '.' )
let l:test_function = ''
let l:pattern = '\V\C\s\*function!\?\s\+\(\<\w\+\>\)\.\*\$'
let l:lnum = prevnonblank( '.' )
" Find the top-level method and class
while l:lnum > 0
call cursor( l:lnum, 1 )
let l:lnum = search( l:pattern, 'bcnWz' )
if l:lnum <= 0
call cursor( l:row, l:col )
return l:test_function
endif
let l:this_decl = substitute( getline( l:lnum ), l:pattern, '\1', '' )
let l:this_decl_is_test = match( l:this_decl, '\V\C\^Test_' ) >= 0
if l:this_decl_is_test
let l:test_function = l:this_decl
if indent( l:lnum ) == 0
call cursor( l:row, l:col )
return l:test_function
endif
endif
let l:lnum = prevnonblank( l:lnum - 1 )
endwhile
endfunction
function! s:RunTestUnderCursor()
update
let l:test_func_name = s:GetCurrentFunction()
if l:test_func_name ==# ''
echo "No test method found"
return
endif
echo "Running test '" . l:test_func_name . "'"
let l:test_arg = expand( '%:p:t' ) . ':' . l:test_func_name
execute s:make_cmd . ' ' . l:test_arg
endfunction
function! s:RunTest()
update
execute s:make_cmd . ' %:p:t'
endfunction
function! s:RunAllTests()
update
execute s:make_cmd
endfunction
if ! has( 'gui_running' )
" ® is right-option+r
nnoremap <buffer> ® :call <SID>RunTest()<CR>
" ® is right-option+r
nnoremap <buffer> Â :call <SID>RunAllTests()<CR>
" † is right-option+t
nnoremap <buffer> † :call <SID>RunTestUnderCursor()<CR>
" å is the right-option+q
nnoremap <buffer> å :cfirst<CR>
" å is the right-option+a
nnoremap <buffer> œ :cnext<CR>
" Ω is the right-option+z
nnoremap <buffer> Ω :cprevious<CR>
endif