Skip to content

Commit 4d23c52

Browse files
committed
patch 8.2.0535: regexp patterns not fully tested
Problem: Regexp patterns not fully tested. Solution: Add more regexp tests and others. (Yegappan Lakshmanan, closes #5901)
1 parent 25d5700 commit 4d23c52

5 files changed

Lines changed: 166 additions & 21 deletions

File tree

src/testdir/test_marks.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func Test_mark_error()
207207
call assert_fails('mark xx', 'E488:')
208208
call assert_fails('mark _', 'E191:')
209209
call assert_beeps('normal! m~')
210+
211+
call setpos("'k", [0, 100, 1, 0])
212+
call assert_fails("normal 'k", 'E19:')
210213
endfunc
211214

212215
" Test for :lockmarks when pasting content

src/testdir/test_options.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,15 @@ func Test_buftype()
677677
bwipe!
678678
endfunc
679679

680+
" Test for the 'shell' option
681+
func Test_shell()
682+
CheckUnix
683+
let save_shell = &shell
684+
set shell=
685+
call assert_fails('shell', 'E91:')
686+
let &shell = save_shell
687+
endfunc
688+
680689
" Test for the 'shellquote' option
681690
func Test_shellquote()
682691
CheckUnix

src/testdir/test_regexp_latin.vim

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ endfunc
147147
" Tests for regexp patterns without multi-byte support.
148148
func Test_regexp_single_line_pat()
149149
" tl is a List of Lists with:
150-
" regexp engine
150+
" regexp engines to test
151+
" 0 - test with 'regexpengine' values 0 and 1
152+
" 1 - test with 'regexpengine' values 0 and 2
153+
" 2 - test with 'regexpengine' values 0, 1 and 2
151154
" regexp pattern
152155
" text to test the pattern on
153156
" expected match (optional)
@@ -168,6 +171,8 @@ func Test_regexp_single_line_pat()
168171
call add(tl, [2, 'c*', 'abdef', ''])
169172
call add(tl, [2, 'bc\+', 'abccccdef', 'bcccc'])
170173
call add(tl, [2, 'bc\+', 'abdef']) " no match
174+
" match newline character in a string
175+
call add(tl, [2, 'o\nb', "foo\nbar", "o\nb"])
171176

172177
" operator \|
173178
call add(tl, [2, 'a\|ab', 'cabd', 'a']) " alternation is ordered
@@ -591,6 +596,9 @@ func Test_regexp_single_line_pat()
591596
" Test \%V atom
592597
call add(tl, [2, '\%>70vGesamt', 'Jean-Michel Charlier & Victor Hubinon\Gesamtausgabe [Salleck] Buck Danny {Jean-Michel Charlier & Victor Hubinon}\Gesamtausgabe', 'Gesamt'])
593598

599+
" Test for ignoring case and matching repeated characters
600+
call add(tl, [2, '\cb\+', 'aAbBbBcC', 'bBbB'])
601+
594602
" Run the tests
595603
for t in tl
596604
let re = t[0]
@@ -650,6 +658,14 @@ endfunc
650658

651659
" Tests for multi-line regexp patterns without multi-byte support.
652660
func Test_regexp_multiline_pat()
661+
" tl is a List of Lists with:
662+
" regexp engines to test
663+
" 0 - test with 'regexpengine' values 0 and 1
664+
" 1 - test with 'regexpengine' values 0 and 2
665+
" 2 - test with 'regexpengine' values 0, 1 and 2
666+
" regexp pattern
667+
" List with text to test the pattern on
668+
" List with the expected match
653669
let tl = []
654670

655671
" back references
@@ -659,6 +675,70 @@ func Test_regexp_multiline_pat()
659675
" line breaks
660676
call add(tl, [2, '\S.*\nx', ['abc', 'def', 'ghi', 'xjk', 'lmn'], ['abc', 'def', 'XXjk', 'lmn']])
661677

678+
" Any single character or end-of-line
679+
call add(tl, [2, '\_.\+', ['a', 'b', 'c'], ['XX']])
680+
" Any identifier or end-of-line
681+
call add(tl, [2, '\_i\+', ['a', 'b', ';', '2'], ['XX;XX']])
682+
" Any identifier but excluding digits or end-of-line
683+
call add(tl, [2, '\_I\+', ['a', 'b', ';', '2'], ['XX;XX2XX']])
684+
" Any keyword or end-of-line
685+
call add(tl, [2, '\_k\+', ['a', 'b', '=', '2'], ['XX=XX']])
686+
" Any keyword but excluding digits or end-of-line
687+
call add(tl, [2, '\_K\+', ['a', 'b', '=', '2'], ['XX=XX2XX']])
688+
" Any filename character or end-of-line
689+
call add(tl, [2, '\_f\+', ['a', 'b', '.', '5'], ['XX']])
690+
" Any filename character but excluding digits or end-of-line
691+
call add(tl, [2, '\_F\+', ['a', 'b', '.', '5'], ['XX5XX']])
692+
" Any printable character or end-of-line
693+
call add(tl, [2, '\_p\+', ['a', 'b', '=', '4'], ['XX']])
694+
" Any printable character excluding digits or end-of-line
695+
call add(tl, [2, '\_P\+', ['a', 'b', '=', '4'], ['XX4XX']])
696+
" Any whitespace character or end-of-line
697+
call add(tl, [2, '\_s\+', [' ', ' ', 'a', 'b'], ['XXaXXbXX']])
698+
" Any non-whitespace character or end-of-line
699+
call add(tl, [2, '\_S\+', [' ', ' ', 'a', 'b'], [' XX XX']])
700+
" Any decimal digit or end-of-line
701+
call add(tl, [2, '\_d\+', ['1', 'a', '2', 'b', '3'], ['XXaXXbXX']])
702+
" Any non-decimal digit or end-of-line
703+
call add(tl, [2, '\_D\+', ['1', 'a', '2', 'b', '3'], ['1XX2XX3XX']])
704+
" Any hexadecimal digit or end-of-line
705+
call add(tl, [2, '\_x\+', ['1', 'a', 'g', '9', '8'], ['XXgXX']])
706+
" Any non-hexadecimal digit or end-of-line
707+
call add(tl, [2, '\_X\+', ['1', 'a', 'g', '9', '8'], ['1XXaXX9XX8XX']])
708+
" Any octal digit or end-of-line
709+
call add(tl, [2, '\_o\+', ['0', '7', '8', '9', '0'], ['XX8XX9XX']])
710+
" Any non-octal digit or end-of-line
711+
call add(tl, [2, '\_O\+', ['0', '7', '8', '9', '0'], ['0XX7XX0XX']])
712+
" Any word character or end-of-line
713+
call add(tl, [2, '\_w\+', ['A', 'B', '=', 'C', 'D'], ['XX=XX']])
714+
" Any non-word character or end-of-line
715+
call add(tl, [2, '\_W\+', ['A', 'B', '=', 'C', 'D'], ['AXXBXXCXXDXX']])
716+
" Any head-of-word character or end-of-line
717+
call add(tl, [2, '\_h\+', ['a', '1', 'b', '2', 'c'], ['XX1XX2XX']])
718+
" Any non-head-of-word character or end-of-line
719+
call add(tl, [2, '\_H\+', ['a', '1', 'b', '2', 'c'], ['aXXbXXcXX']])
720+
" Any alphabetic character or end-of-line
721+
call add(tl, [2, '\_a\+', ['a', '1', 'b', '2', 'c'], ['XX1XX2XX']])
722+
" Any non-alphabetic character or end-of-line
723+
call add(tl, [2, '\_A\+', ['a', '1', 'b', '2', 'c'], ['aXXbXXcXX']])
724+
" Any lowercase character or end-of-line
725+
call add(tl, [2, '\_l\+', ['a', 'A', 'b', 'B'], ['XXAXXBXX']])
726+
" Any non-lowercase character or end-of-line
727+
call add(tl, [2, '\_L\+', ['a', 'A', 'b', 'B'], ['aXXbXX']])
728+
" Any uppercase character or end-of-line
729+
call add(tl, [2, '\_u\+', ['a', 'A', 'b', 'B'], ['aXXbXX']])
730+
" Any non-uppercase character or end-of-line
731+
call add(tl, [2, '\_U\+', ['a', 'A', 'b', 'B'], ['XXAXXBXX']])
732+
" Collection or end-of-line
733+
call add(tl, [2, '\_[a-z]\+', ['a', 'A', 'b', 'B'], ['XXAXXBXX']])
734+
" start of line anywhere in the text
735+
call add(tl, [2, 'one\zs\_s*\_^\zetwo',
736+
\ ['', 'one', ' two', 'one', '', 'two'],
737+
\ ['', 'one', ' two', 'oneXXtwo']])
738+
" end of line anywhere in the text
739+
call add(tl, [2, 'one\zs\_$\_s*two',
740+
\ ['', 'one', ' two', 'one', '', 'two'], ['', 'oneXX', 'oneXX']])
741+
662742
" Check that \_[0-9] matching EOL does not break a following \>
663743
call add(tl, [2, '\<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\>', ['', 'localnet/192.168.0.1', ''], ['', 'localnet/XX', '']])
664744

@@ -674,7 +754,7 @@ func Test_regexp_multiline_pat()
674754
let before = t[2]
675755
let after = t[3]
676756
for engine in [0, 1, 2]
677-
if engine == 2 && re == 0 || engine == 1 && re ==1
757+
if engine == 2 && re == 0 || engine == 1 && re == 1
678758
continue
679759
endif
680760
let &regexpengine = engine
@@ -722,9 +802,8 @@ func Test_lookbehind_across_line()
722802
bwipe!
723803
endfunc
724804

725-
" Check matching Visual area
726-
func Test_matching_visual_area()
727-
new
805+
" Test for the \%V atom (match inside the visual area)
806+
func Regex_Match_Visual_Area()
728807
call append(0, ['Visual:', 'thexe the thexethe', 'andaxand andaxand',
729808
\ 'oooxofor foroxooo', 'oooxofor foroxooo'])
730809
call cursor(1, 1)
@@ -733,19 +812,38 @@ func Test_matching_visual_area()
733812
exe "normal jfx\<C-V>fxj:s/\\%Vo/O/g\<CR>"
734813
call assert_equal(['Visual:', 'thexE thE thExethe', 'AndAxAnd AndAxAnd',
735814
\ 'oooxOfOr fOrOxooo', 'oooxOfOr fOrOxooo', ''], getline(1, '$'))
815+
%d
816+
endfunc
817+
818+
" Check matching Visual area
819+
func Test_matching_visual_area()
820+
new
821+
set regexpengine=1
822+
call Regex_Match_Visual_Area()
823+
set regexpengine=2
824+
call Regex_Match_Visual_Area()
825+
set regexpengine&
736826
bwipe!
737827
endfunc
738828

739829
" Check matching marks
740-
func Test_matching_marks()
741-
new
830+
func Regex_Mark()
742831
call append(0, ['', '', '', 'Marks:', 'asdfSasdfsadfEasdf', 'asdfSas',
743832
\ 'dfsadfEasdf', '', '', '', '', ''])
744833
call cursor(4, 1)
745834
exe "normal jfSmsfEme:.-4,.+6s/.\\%>'s.*\\%<'e../here/\<CR>"
746835
exe "normal jfSmsj0fEme:.-4,.+6s/.\\%>'s\\_.*\\%<'e../again/\<CR>"
747836
call assert_equal(['', '', '', 'Marks:', 'asdfhereasdf', 'asdfagainasdf',
748837
\ '', '', '', '', '', ''], getline(1, '$'))
838+
%d
839+
endfunc
840+
841+
func Test_matching_marks()
842+
new
843+
set regexpengine=1
844+
call Regex_Mark()
845+
set regexpengine=2
846+
call Regex_Mark()
749847
bwipe!
750848
endfunc
751849

@@ -786,8 +884,7 @@ func Test_matching_curpos()
786884
endfunc
787885

788886
" Test for matching the start and end of a buffer
789-
func Test_start_end_of_buffer_match()
790-
new
887+
func Regex_start_end_buffer()
791888
call setline(1, repeat(['vim edit'], 20))
792889
/\%^
793890
call assert_equal([0, 1, 1, 0], getpos('.'))
@@ -797,15 +894,34 @@ func Test_start_end_of_buffer_match()
797894
call assert_equal([0, 20, 8, 0], getpos('.'))
798895
exe "normal 6gg/..\\%$\<CR>"
799896
call assert_equal([0, 20, 7, 0], getpos('.'))
897+
%d
898+
endfunc
899+
900+
func Test_start_end_of_buffer_match()
901+
new
902+
set regexpengine=1
903+
call Regex_start_end_buffer()
904+
set regexpengine=2
905+
call Regex_start_end_buffer()
800906
bwipe!
801907
endfunc
802908

803909
" Check for detecting error
804910
func Test_regexp_error()
805-
set regexpengine=2
806-
call assert_fails("call matchlist('x x', ' \\ze*')", 'E888:')
807-
call assert_fails("call matchlist('x x', ' \\zs*')", 'E888:')
808-
set re&
911+
call assert_fails("call matchlist('x x', '\\%#=1 \\zs*')", 'E888:')
912+
call assert_fails("call matchlist('x x', '\\%#=1 \\ze*')", 'E888:')
913+
call assert_fails("call matchlist('x x', '\\%#=2 \\zs*')", 'E888:')
914+
call assert_fails("call matchlist('x x', '\\%#=2 \\ze*')", 'E888:')
915+
call assert_fails('exe "normal /\\%#=1\\%[x\\%[x]]\<CR>"', 'E369:')
916+
endfunc
917+
918+
" Test for using the last substitute string pattern (~)
919+
func Test_regexp_last_subst_string()
920+
new
921+
s/bar/baz/e
922+
call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=1\~"), "baz")
923+
call assert_equal(matchstr("foo\nbaz\nbar", "\\%#=2\~"), "baz")
924+
close!
809925
endfunc
810926

811927
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_search.vim

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,7 @@ func Test_search_cmdline8()
688688
endfunc
689689

690690
" Tests for regexp with various magic settings
691-
func Test_search_regexp()
692-
enew!
693-
691+
func Run_search_regexp_magic_opt()
694692
put ='1 a aa abb abbccc'
695693
exe 'normal! /a*b\{2}c\+/e' . "\<CR>"
696694
call assert_equal([0, 2, 17, 0], getpos('.'))
@@ -725,19 +723,31 @@ func Test_search_regexp()
725723
exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>"
726724
call assert_equal([0, 9, 7, 0], getpos('.'))
727725

726+
%d
727+
endfunc
728+
729+
func Test_search_regexp()
730+
enew!
731+
732+
set regexpengine=1
733+
call Run_search_regexp_magic_opt()
734+
set regexpengine=2
735+
call Run_search_regexp_magic_opt()
736+
set regexpengine&
737+
728738
set undolevels=100
729739
put ='9 foobar'
730740
put =''
731741
exe "normal! a\<C-G>u\<Esc>"
732742
normal G
733743
exe 'normal! dv?bar?' . "\<CR>"
734744
call assert_equal('9 foo', getline('.'))
735-
call assert_equal([0, 10, 5, 0], getpos('.'))
736-
call assert_equal(10, line('$'))
745+
call assert_equal([0, 2, 5, 0], getpos('.'))
746+
call assert_equal(2, line('$'))
737747
normal u
738748
call assert_equal('9 foobar', getline('.'))
739-
call assert_equal([0, 10, 6, 0], getpos('.'))
740-
call assert_equal(11, line('$'))
749+
call assert_equal([0, 2, 6, 0], getpos('.'))
750+
call assert_equal(3, line('$'))
741751

742752
set undolevels&
743753
enew!
@@ -1547,8 +1557,12 @@ endfunc
15471557
func Test_invalid_regexp()
15481558
set regexpengine=1
15491559
call assert_fails("call search(repeat('\\(.\\)', 10))", 'E51:')
1550-
call assert_fails("call search('a\\+*')", 'E61:')
1560+
call assert_fails("call search('\\%(')", 'E53:')
1561+
call assert_fails("call search('\\(')", 'E54:')
1562+
call assert_fails("call search('\\)')", 'E55:')
15511563
call assert_fails("call search('x\\@#')", 'E59:')
1564+
call assert_fails('call search(''\v%(%(%(%(%(%(%(%(%(%(%(a){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}){1}'')', 'E60:')
1565+
call assert_fails("call search('a\\+*')", 'E61:')
15521566
call assert_fails("call search('\\_m')", 'E63:')
15531567
call assert_fails("call search('\\+')", 'E64:')
15541568
call assert_fails("call search('\\1')", 'E65:')
@@ -1573,6 +1587,7 @@ func Test_invalid_regexp()
15731587
call assert_fails("call search('\\)')", 'E55:')
15741588
call assert_fails("call search('\\z\\(\\)')", 'E66:')
15751589
call assert_fails("call search('\\%[ab')", 'E69:')
1590+
call assert_fails("call search('\\%[]')", 'E70:')
15761591
call assert_fails("call search('\\%9999999999999999999999999999v')", 'E951:')
15771592
set regexpengine&
15781593
call assert_fails("call search('\\%#=3ab')", 'E864:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
535,
741743
/**/
742744
534,
743745
/**/

0 commit comments

Comments
 (0)