Skip to content

Commit 565be0b

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 48288d2 + 2795e21 commit 565be0b

File tree

4 files changed

+292
-2
lines changed

4 files changed

+292
-2
lines changed

src/syntax.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,8 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30223022
if (r && regmatch.startpos[0].col
30233023
<= best_regmatch.startpos[0].col)
30243024
{
3025+
int line_len;
3026+
30253027
/* Add offset to skip pattern match */
30263028
syn_add_end_off(&pos, &regmatch, spp_skip, SPO_ME_OFF, 1);
30273029

@@ -3031,6 +3033,7 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30313033
break;
30323034

30333035
line = ml_get_buf(syn_buf, startpos->lnum, FALSE);
3036+
line_len = (int)STRLEN(line);
30343037

30353038
/* take care of an empty match or negative offset */
30363039
if (pos.col <= matchcol)
@@ -3040,12 +3043,12 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30403043
else
30413044
/* Be careful not to jump over the NUL at the end-of-line */
30423045
for (matchcol = regmatch.endpos[0].col;
3043-
line[matchcol] != NUL && matchcol < pos.col;
3046+
matchcol < line_len && matchcol < pos.col;
30443047
++matchcol)
30453048
;
30463049

30473050
/* if the skip pattern includes end-of-line, break here */
3048-
if (line[matchcol] == NUL)
3051+
if (matchcol >= line_len)
30493052
break;
30503053

30513054
continue; /* start with first end pattern again */
@@ -5830,6 +5833,11 @@ syn_cmd_sync(eap, syncing)
58305833
}
58315834
else if (STRCMP(key, "LINECONT") == 0)
58325835
{
5836+
if (*next_arg == NUL) /* missing pattern */
5837+
{
5838+
illegal = TRUE;
5839+
break;
5840+
}
58335841
if (curwin->w_s->b_syn_linecont_pat != NULL)
58345842
{
58355843
EMSG(_("E403: syntax sync: line continuations pattern specified twice"));

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ SCRIPTS_GUI = test16.out
174174
# Keep test_alot.res as the last one, sort the others.
175175
NEW_TESTS = test_assert.res \
176176
test_cdo.res \
177+
test_quickfix.res \
177178
test_viml.res \
178179
test_alot.res
179180

src/testdir/test_quickfix.vim

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
" Test for the quickfix commands.
2+
3+
if !has('quickfix')
4+
finish
5+
endif
6+
7+
" Tests for the :clist and :llist commands
8+
function XlistTests(cchar)
9+
let Xlist = a:cchar . 'list'
10+
let Xgetexpr = a:cchar . 'getexpr'
11+
12+
" With an empty list, command should return error
13+
exe Xgetexpr . ' []'
14+
exe 'silent! ' . Xlist
15+
call assert_true(v:errmsg ==# 'E42: No Errors')
16+
17+
" Populate the list and then try
18+
exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1',
19+
\ 'non-error 2', 'Xtestfile2:2:2:Line2',
20+
\ 'non-error 3', 'Xtestfile3:3:1:Line3']"
21+
22+
" List only valid entries
23+
redir => result
24+
exe Xlist
25+
redir END
26+
let l = split(result, "\n")
27+
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
28+
\ ' 4 Xtestfile2:2 col 2: Line2',
29+
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
30+
31+
" List all the entries
32+
redir => result
33+
exe Xlist . "!"
34+
redir END
35+
let l = split(result, "\n")
36+
call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
37+
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
38+
\ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
39+
40+
" List a range of errors
41+
redir => result
42+
exe Xlist . " 3,6"
43+
redir END
44+
let l = split(result, "\n")
45+
call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
46+
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
47+
48+
redir => result
49+
exe Xlist . "! 3,4"
50+
redir END
51+
let l = split(result, "\n")
52+
call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
53+
54+
redir => result
55+
exe Xlist . " -6,-4"
56+
redir END
57+
let l = split(result, "\n")
58+
call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
59+
60+
redir => result
61+
exe Xlist . "! -5,-3"
62+
redir END
63+
let l = split(result, "\n")
64+
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
65+
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
66+
endfunction
67+
68+
function Test_clist()
69+
call XlistTests('c')
70+
call XlistTests('l')
71+
endfunction
72+
73+
" Tests for the :colder, :cnewer, :lolder and :lnewer commands
74+
" Note that this test assumes that a quickfix/location list is
75+
" already set by previous tests
76+
function XageTests(cchar)
77+
let Xolder = a:cchar . 'older'
78+
let Xnewer = a:cchar . 'newer'
79+
let Xgetexpr = a:cchar . 'getexpr'
80+
if a:cchar == 'c'
81+
let Xgetlist = 'getqflist()'
82+
else
83+
let Xgetlist = 'getloclist(0)'
84+
endif
85+
86+
" Jumping to a non existent list should return error
87+
exe 'silent! ' . Xolder . ' 99'
88+
call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
89+
90+
exe 'silent! ' . Xnewer . ' 99'
91+
call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
92+
93+
" Add three quickfix/location lists
94+
exe Xgetexpr . " ['Xtestfile1:1:3:Line1']"
95+
exe Xgetexpr . " ['Xtestfile2:2:2:Line2']"
96+
exe Xgetexpr . " ['Xtestfile3:3:1:Line3']"
97+
98+
" Go back two lists
99+
exe Xolder
100+
exe 'let l = ' . Xgetlist
101+
call assert_equal('Line2', l[0].text)
102+
103+
" Go forward two lists
104+
exe Xnewer
105+
exe 'let l = ' . Xgetlist
106+
call assert_equal('Line3', l[0].text)
107+
108+
" Test for the optional count argument
109+
exe Xolder . ' 2'
110+
exe 'let l = ' . Xgetlist
111+
call assert_equal('Line1', l[0].text)
112+
113+
exe Xnewer . ' 2'
114+
exe 'let l = ' . Xgetlist
115+
call assert_equal('Line3', l[0].text)
116+
endfunction
117+
118+
function Test_cage()
119+
call XageTests('c')
120+
call XageTests('l')
121+
endfunction
122+
123+
" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
124+
" commands
125+
function XwindowTests(cchar)
126+
let Xwindow = a:cchar . 'window'
127+
let Xclose = a:cchar . 'close'
128+
let Xopen = a:cchar . 'open'
129+
let Xgetexpr = a:cchar . 'getexpr'
130+
131+
" Create a list with no valid entries
132+
exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']"
133+
134+
" Quickfix/Location window should not open with no valid errors
135+
exe Xwindow
136+
call assert_true(winnr('$') == 1)
137+
138+
" Create a list with valid entries
139+
exe Xgetexpr . " ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
140+
\ 'Xtestfile3:3:1:Line3']"
141+
142+
" Open the window
143+
exe Xwindow
144+
call assert_true(winnr('$') == 2 && winnr() == 2 &&
145+
\ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
146+
147+
" Close the window
148+
exe Xclose
149+
call assert_true(winnr('$') == 1)
150+
151+
" Create a list with no valid entries
152+
exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']"
153+
154+
" Open the window
155+
exe Xopen . ' 5'
156+
call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
157+
\ && winheight('.') == 5)
158+
159+
" Opening the window again, should move the cursor to that window
160+
wincmd t
161+
exe Xopen . ' 7'
162+
call assert_true(winnr('$') == 2 && winnr() == 2 &&
163+
\ winheight('.') == 7 &&
164+
\ getline('.') ==# '|| non-error 1')
165+
166+
167+
" Calling cwindow should close the quickfix window with no valid errors
168+
exe Xwindow
169+
call assert_true(winnr('$') == 1)
170+
endfunction
171+
172+
function Test_cwindow()
173+
call XwindowTests('c')
174+
call XwindowTests('l')
175+
endfunction
176+
177+
" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
178+
" commands.
179+
function XfileTests(cchar)
180+
let Xfile = a:cchar . 'file'
181+
let Xgetfile = a:cchar . 'getfile'
182+
let Xaddfile = a:cchar . 'addfile'
183+
if a:cchar == 'c'
184+
let Xgetlist = 'getqflist()'
185+
else
186+
let Xgetlist = 'getloclist(0)'
187+
endif
188+
189+
call writefile(['Xtestfile1:700:10:Line 700',
190+
\ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
191+
192+
enew!
193+
exe Xfile . ' Xqftestfile1'
194+
exe 'let l = ' . Xgetlist
195+
call assert_true(len(l) == 2 &&
196+
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
197+
\ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
198+
199+
" Run cfile/lfile from a modified buffer
200+
enew!
201+
silent! put ='Quickfix'
202+
exe 'silent! ' . Xfile . ' Xqftestfile1'
203+
call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
204+
205+
call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
206+
exe Xaddfile . ' Xqftestfile1'
207+
exe 'let l = ' . Xgetlist
208+
call assert_true(len(l) == 3 &&
209+
\ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
210+
211+
call writefile(['Xtestfile1:222:77:Line 222',
212+
\ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
213+
214+
enew!
215+
exe Xgetfile . ' Xqftestfile1'
216+
exe 'let l = ' . Xgetlist
217+
call assert_true(len(l) == 2 &&
218+
\ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
219+
\ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
220+
221+
call delete('Xqftestfile1')
222+
endfunction
223+
224+
function Test_cfile()
225+
call XfileTests('c')
226+
call XfileTests('l')
227+
endfunction
228+
229+
" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
230+
" :lgetbuffer commands.
231+
function XbufferTests(cchar)
232+
let Xbuffer = a:cchar . 'buffer'
233+
let Xgetbuffer = a:cchar . 'getbuffer'
234+
let Xaddbuffer = a:cchar . 'addbuffer'
235+
if a:cchar == 'c'
236+
let Xgetlist = 'getqflist()'
237+
else
238+
let Xgetlist = 'getloclist(0)'
239+
endif
240+
241+
enew!
242+
silent! call setline(1, ['Xtestfile7:700:10:Line 700',
243+
\ 'Xtestfile8:800:15:Line 800'])
244+
exe Xbuffer . "!"
245+
exe 'let l = ' . Xgetlist
246+
call assert_true(len(l) == 2 &&
247+
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
248+
\ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
249+
250+
enew!
251+
silent! call setline(1, ['Xtestfile9:900:55:Line 900',
252+
\ 'Xtestfile10:950:66:Line 950'])
253+
exe Xgetbuffer
254+
exe 'let l = ' . Xgetlist
255+
call assert_true(len(l) == 2 &&
256+
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
257+
\ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
258+
259+
enew!
260+
silent! call setline(1, ['Xtestfile11:700:20:Line 700',
261+
\ 'Xtestfile12:750:25:Line 750'])
262+
exe Xaddbuffer
263+
exe 'let l = ' . Xgetlist
264+
call assert_true(len(l) == 4 &&
265+
\ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
266+
\ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
267+
\ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
268+
269+
endfunction
270+
271+
function Test_cbuffer()
272+
call XbufferTests('c')
273+
call XbufferTests('l')
274+
endfunction
275+

src/version.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ static char *(features[]) =
756756

757757
static int included_patches[] =
758758
{ /* Add new patch number below this line */
759+
/**/
760+
1054,
761+
/**/
762+
1053,
763+
/**/
764+
1052,
759765
/**/
760766
1051,
761767
/**/

0 commit comments

Comments
 (0)