@@ -147,7 +147,10 @@ endfunc
147147" Tests for regexp patterns without multi-byte support.
148148func 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\n bar" , " o\n b" ])
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.
652660func 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 ®expengine = engine
@@ -722,9 +802,8 @@ func Test_lookbehind_across_line()
722802 bwipe!
723803endfunc
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!
737827endfunc
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!
750848endfunc
751849
@@ -786,8 +884,7 @@ func Test_matching_curpos()
786884endfunc
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!
801907endfunc
802908
803909" Check for detecting error
804910func 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\n baz\n bar" , " \\ %#=1\~ " ), " baz" )
923+ call assert_equal (matchstr (" foo\n baz\n bar" , " \\ %#=2\~ " ), " baz" )
924+ close !
809925endfunc
810926
811927" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments