Skip to content

Commit 0e8bf0c

Browse files
committed
Added tests
Added the start of some basic tests and a ResultListSave function that is used in them
1 parent 899d6fb commit 0e8bf0c

10 files changed

+131
-1
lines changed

plugin/EasyGrep.vim

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ let s:EasyGrepModeAll=0
334334
let s:EasyGrepModeBuffers=1
335335
let s:EasyGrepModeTracked=2
336336
let s:EasyGrepModeUser=3
337-
let s:EasyGrepNumModes = 4
337+
let s:EasyGrepNumModes=4
338338

339339
" This is a special mode
340340
let s:EasyGrepModeMultipleChoice=4
@@ -3075,6 +3075,39 @@ function! s:ResultListDo(command)
30753075

30763076
endfunction
30773077
"}}}
3078+
" ResultListSave {{{
3079+
function! s:ResultListSave(f)
3080+
if filereadable(a:f)
3081+
let confirmed = confirm("File '".a:f."' exists; overwrite it?", "&Yes\n&No")-1
3082+
if confirmed
3083+
return
3084+
endif
3085+
call s:Echo("Proceeding to overwrite '".a:f."'")
3086+
endif
3087+
3088+
let lst = s:GetErrorList()
3089+
3090+
if empty(lst)
3091+
call s:Error("No result list to save")
3092+
return
3093+
endif
3094+
3095+
try
3096+
let contents = []
3097+
for e in lst
3098+
let line = bufname(e.bufnr)."|".e.lnum." col ".e.col."| ".e.text
3099+
call insert(contents, line, len(contents))
3100+
endfor
3101+
3102+
call writefile(contents, a:f)
3103+
catch
3104+
call s:Error("Error saving result list to '".a:f."'")
3105+
return
3106+
endtry
3107+
3108+
call s:Echo("Result list was saved to '".a:f."' successfully")
3109+
endfunction
3110+
"}}}
30783111
" }}}
30793112
" }}}
30803113

@@ -3090,6 +3123,7 @@ command! -bang ReplaceUndo :call s:ReplaceUndo("<bang>")
30903123
command! -nargs=0 ResultListOpen :call s:ResultListOpen()
30913124
command! -nargs=+ ResultListFilter :call s:ResultListFilter(<f-args>)
30923125
command! -nargs=+ ResultListDo :call s:ResultListDo(<q-args>)
3126+
command! -nargs=1 ResultListSave :call s:ResultListSave(<q-args>)
30933127
"}}}
30943128
" Keymaps {{{
30953129
if !hasmapto("<plug>EgMapGrepOptions")

tests/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
I'm just getting started here. Hopefully I'll be able to add more tests over time.
3+
4+
These tests use runVimTests as a testing framework. It is expected to be located in its own directory two directories up; see runall.sh

tests/_setup.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
let g:EasyGrepDefaultUserPattern="alphabet.in"
3+
let g:EasyGrepMode=3
4+
let g:EasyGrepOpenWindowOnMatch=0
5+
let g:EasyGrepExtraWarnings=0
6+
let g:EasyGrepFileAssociations="../plugin/EasyGrepFileAssociations"
7+
source ../plugin/EasyGrep.vim
8+

tests/alphabet.in

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
a
2+
b
3+
c
4+
d
5+
e
6+
f
7+
g
8+
h
9+
i
10+
j
11+
k
12+
l
13+
m
14+
n
15+
o
16+
p
17+
q
18+
r
19+
s
20+
t
21+
u
22+
v
23+
w
24+
x
25+
y
26+
z
27+
A
28+
B
29+
C
30+
D
31+
E
32+
F
33+
G
34+
H
35+
I
36+
J
37+
K
38+
L
39+
M
40+
N
41+
O
42+
P
43+
Q
44+
R
45+
S
46+
T
47+
U
48+
V
49+
W
50+
X
51+
Y
52+
Z

tests/runall.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bash ../../runVimTests/bin/runVimTests.sh --pure vimgrep.suite

tests/vimgrep.suite

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimgrep_basic.vim

tests/vimgrep_basic.msgout

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
"alphabet.in"
3+
"alphabet.in" 52L, 104C
4+
1 %a "alphabet.in" line 1
5+
6+
alphabet.in
7+
(1 of 1): c
8+
1 %a "alphabet.in" line 3
9+
10+
alphabet.in
11+
(1 of 3): c
12+
[EasyGrep] Result list was saved to 'vimgrep_basic.out' successfully

tests/vimgrep_basic.ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
alphabet.in|3 col 1| c
2+
alphabet.in|3 col 1| c
3+
alphabet.in|29 col 1| C

tests/vimgrep_basic.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
alphabet.in|3 col 1| c
2+
alphabet.in|3 col 1| c
3+
alphabet.in|29 col 1| C

tests/vimgrep_basic.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
" Load the test data.
3+
edit alphabet.in
4+
5+
Grep c
6+
let g:EasyGrepIgnoreCase=1
7+
GrepAdd c
8+
9+
ResultListSave vimgrep_basic.out
10+
quit!
11+
12+

0 commit comments

Comments
 (0)