Mercurial > vim
view src/testdir/test64.in @ 4677:c1622ff9ed8d v7.3.1086
updated for version 7.3.1086
Problem: Old regexp engine accepts illegal range, new one doesn't.
Solution: Also accept the illegal range with the new engine.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 01 Jun 2013 13:24:24 +0200 |
parents | 811a4c9b51d8 |
children | 4d92b873acef |
line wrap: on
line source
Test for regexp patterns without multi-byte support. See test95 for multi-byte tests. A pattern that gives the expected result produces OK, so that we know it was actually tried. STARTTEST :so small.vim :" tl is a List of Lists with: :" regexp pattern :" text to test the pattern on :" expected match (optional) :" expected submatch 1 (optional) :" expected submatch 2 (optional) :" etc. :" When there is no match use only the first two items. :let tl = [] :" :"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :"""" Previously written tests """""""""""""""""""""""""""""""" :"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :" :call add(tl, [2, 'ab', 'aab', 'ab']) :call add(tl, [2, 'b', 'abcdef', 'b']) :call add(tl, [2, 'bc*', 'abccccdef', 'bcccc']) :call add(tl, [2, 'bc\{-}', 'abccccdef', 'b']) :call add(tl, [2, 'bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd']) :call add(tl, [2, 'bc*', 'abbdef', 'b']) :call add(tl, [2, 'c*', 'ccc', 'ccc']) :call add(tl, [2, 'bc*', 'abdef', 'b']) :call add(tl, [2, 'c*', 'abdef', '']) :call add(tl, [2, 'bc\+', 'abccccdef', 'bcccc']) :call add(tl, [2, 'bc\+', 'abdef']) "no match :" :"operator \| :call add(tl, [2, 'a\|ab', 'cabd', 'a']) "alternation is ordered :" :call add(tl, [2, 'c\?', 'ccb', 'c']) :call add(tl, [2, 'bc\?', 'abd', 'b']) :call add(tl, [2, 'bc\?', 'abccd', 'bc']) :" :call add(tl, [2, '\va{1}', 'ab', 'a']) :" :call add(tl, [2, '\va{2}', 'aa', 'aa']) :call add(tl, [2, '\va{2}', 'caad', 'aa']) :call add(tl, [2, '\va{2}', 'aba']) :call add(tl, [2, '\va{2}', 'ab']) :call add(tl, [2, '\va{2}', 'abaa', 'aa']) :call add(tl, [2, '\va{2}', 'aaa', 'aa']) :" :call add(tl, [2, '\vb{1}', 'abca', 'b']) :call add(tl, [2, '\vba{2}', 'abaa', 'baa']) :call add(tl, [2, '\vba{3}', 'aabaac']) :" :call add(tl, [2, '\v(ab){1}', 'ab', 'ab', 'ab']) :call add(tl, [2, '\v(ab){1}', 'dabc', 'ab', 'ab']) :call add(tl, [2, '\v(ab){1}', 'acb']) :" :call add(tl, [2, '\v(ab){0,2}', 'acb', "", ""]) :call add(tl, [2, '\v(ab){0,2}', 'ab', 'ab', 'ab']) :call add(tl, [2, '\v(ab){1,2}', 'ab', 'ab', 'ab']) :call add(tl, [2, '\v(ab){1,2}', 'ababc', 'abab', 'ab']) :call add(tl, [2, '\v(ab){2,4}', 'ababcab', 'abab', 'ab']) :call add(tl, [2, '\v(ab){2,4}', 'abcababa', 'abab', 'ab']) :" :call add(tl, [2, '\v(ab){2}', 'abab', 'abab', 'ab']) :call add(tl, [2, '\v(ab){2}', 'cdababe', 'abab', 'ab']) :call add(tl, [2, '\v(ab){2}', 'abac']) :call add(tl, [2, '\v(ab){2}', 'abacabab', 'abab', 'ab']) :call add(tl, [2, '\v((ab){2}){2}', 'abababab', 'abababab', 'abab', 'ab']) :call add(tl, [2, '\v((ab){2}){2}', 'abacabababab', 'abababab', 'abab', 'ab']) :" :call add(tl, [2, '\v(a{1}){1}', 'a', 'a', 'a']) :call add(tl, [2, '\v(a{2}){1}', 'aa', 'aa', 'aa']) :call add(tl, [2, '\v(a{2}){1}', 'aaac', 'aa', 'aa']) :call add(tl, [2, '\v(a{2}){1}', 'daaac', 'aa', 'aa']) :call add(tl, [2, '\v(a{1}){2}', 'daaac', 'aa', 'a']) :call add(tl, [2, '\v(a{1}){2}', 'aaa', 'aa', 'a']) :call add(tl, [2, '\v(a{2})+', 'adaac', 'aa', 'aa']) :call add(tl, [2, '\v(a{2})+', 'aa', 'aa', 'aa']) :call add(tl, [2, '\v(a{2}){1}', 'aa', 'aa', 'aa']) :call add(tl, [2, '\v(a{1}){2}', 'aa', 'aa', 'a']) :call add(tl, [2, '\v(a{1}){1}', 'a', 'a', 'a']) :call add(tl, [2, '\v(a{2}){2}', 'aaaa', 'aaaa', 'aa']) :call add(tl, [2, '\v(a{2}){2}', 'aaabaaaa', 'aaaa', 'aa']) :" :call add(tl, [2, '\v(a+){2}', 'dadaac', 'aa', 'a']) :call add(tl, [2, '\v(a{3}){2}', 'aaaaaaa', 'aaaaaa', 'aaa']) :" :call add(tl, [2, '\v(a{1,2}){2}', 'daaac', 'aaa', 'a']) :call add(tl, [2, '\v(a{1,3}){2}', 'daaaac', 'aaaa', 'a']) :call add(tl, [2, '\v(a{1,3}){2}', 'daaaaac', 'aaaaa', 'aa']) :call add(tl, [2, '\v(a{1,3}){3}', 'daac']) :call add(tl, [2, '\v(a{1,2}){2}', 'dac']) :call add(tl, [2, '\v(a+)+', 'daac', 'aa', 'aa']) :call add(tl, [2, '\v(a+)+', 'aaa', 'aaa', 'aaa']) :call add(tl, [2, '\v(a+){1,2}', 'aaa', 'aaa', 'aaa']) :call add(tl, [2, '\v(a+)(a+)', 'aaa', 'aaa', 'aa', 'a']) :call add(tl, [2, '\v(a{3})+', 'daaaac', 'aaa', 'aaa']) :call add(tl, [2, '\v(a|b|c)+', 'aacb', 'aacb', 'b']) :call add(tl, [2, '\v(a|b|c){2}', 'abcb', 'ab', 'b']) :call add(tl, [2, '\v(abc){2}', 'abcabd', ]) :call add(tl, [2, '\v(abc){2}', 'abdabcabc','abcabc', 'abc']) :" :call add(tl, [2, 'a*', 'cc', '']) :call add(tl, [2, '\v(a*)+', 'cc', '']) :call add(tl, [2, '\v((ab)+)+', 'ab', 'ab', 'ab', 'ab']) :call add(tl, [2, '\v(((ab)+)+)+', 'ab', 'ab', 'ab', 'ab', 'ab']) :call add(tl, [2, '\v(((ab)+)+)+', 'dababc', 'abab', 'abab', 'abab', 'ab']) :call add(tl, [2, '\v(a{0,2})+', 'cc', '']) :call add(tl, [2, '\v(a*)+', '', '']) :call add(tl, [2, '\v((a*)+)+', '', '']) :call add(tl, [2, '\v((ab)*)+', '', '']) :call add(tl, [2, '\va{1,3}', 'aab', 'aa']) :call add(tl, [2, '\va{2,3}', 'abaa', 'aa']) :" :call add(tl, [2, '\v((ab)+|c*)+', 'abcccaba', 'abcccab', '', 'ab']) :call add(tl, [2, '\v(a{2})|(b{3})', 'bbabbbb', 'bbb', '', 'bbb']) :call add(tl, [2, '\va{2}|b{2}', 'abab']) :call add(tl, [2, '\v(a)+|(c)+', 'bbacbaacbbb', 'a', 'a']) :call add(tl, [2, '\vab{2,3}c', 'aabbccccccccccccc', 'abbc']) :call add(tl, [2, '\vab{2,3}c', 'aabbbccccccccccccc', 'abbbc']) :call add(tl, [2, '\vab{2,3}cd{2,3}e', 'aabbbcddee', 'abbbcdde']) :call add(tl, [2, '\va(bc){2}d', 'aabcbfbc' ]) :call add(tl, [2, '\va*a{2}', 'a', ]) :call add(tl, [2, '\va*a{2}', 'aa', 'aa' ]) :call add(tl, [2, '\va*a{2}', 'aaa', 'aaa' ]) :call add(tl, [2, '\va*a{2}', 'bbbabcc', ]) :call add(tl, [2, '\va*b*|a*c*', 'a', 'a']) :call add(tl, [2, '\va{1}b{1}|a{1}b{1}', '']) :" :"submatches :call add(tl, [2, '\v(a)', 'ab', 'a', 'a']) :call add(tl, [2, '\v(a)(b)', 'ab', 'ab', 'a', 'b']) :call add(tl, [2, '\v(ab)(b)(c)', 'abbc', 'abbc', 'ab', 'b', 'c']) :call add(tl, [2, '\v((a)(b))', 'ab', 'ab', 'ab', 'a', 'b']) :call add(tl, [2, '\v(a)|(b)', 'ab', 'a', 'a']) :" :call add(tl, [2, '\v(a*)+', 'aaaa', 'aaaa', '']) :call add(tl, [2, 'x', 'abcdef']) :" :"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :""""" Simple tests """"""""""""""""""""""""""""""""""""""""""" :"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :" :" Search single groups :call add(tl, [2, 'ab', 'aab', 'ab']) :call add(tl, [2, 'ab', 'baced']) :call add(tl, [2, 'ab', ' ab ', 'ab']) :" :" Search multi-modifiers :call add(tl, [2, 'x*', 'xcd', 'x']) :call add(tl, [2, 'x*', 'xxxxxxxxxxxxxxxxsofijiojgf', 'xxxxxxxxxxxxxxxx']) :" empty match is good :call add(tl, [2, 'x*', 'abcdoij', '']) :" no match here :call add(tl, [2, 'x\+', 'abcdoin']) :call add(tl, [2, 'x\+', 'abcdeoijdfxxiuhfij', 'xx']) :call add(tl, [2, 'x\+', 'xxxxx', 'xxxxx']) :call add(tl, [2, 'x\+', 'abc x siufhiush xxxxxxxxx', 'x']) :call add(tl, [2, 'x\=', 'x sdfoij', 'x']) :call add(tl, [2, 'x\=', 'abc sfoij', '']) " empty match is good :call add(tl, [2, 'x\=', 'xxxxxxxxx c', 'x']) :call add(tl, [2, 'x\?', 'x sdfoij', 'x']) :" empty match is good :call add(tl, [2, 'x\?', 'abc sfoij', '']) :call add(tl, [2, 'x\?', 'xxxxxxxxxx c', 'x']) :" :call add(tl, [2, 'a\{0,0}', 'abcdfdoij', '']) :" same thing as 'a?' :call add(tl, [2, 'a\{0,1}', 'asiubid axxxaaa', 'a']) :" same thing as 'a\{0,1}' :call add(tl, [2, 'a\{1,0}', 'asiubid axxxaaa', 'a']) :call add(tl, [2, 'a\{3,6}', 'aa siofuh']) :call add(tl, [2, 'a\{3,6}', 'aaaaa asfoij afaa', 'aaaaa']) :call add(tl, [2, 'a\{3,6}', 'aaaaaaaa', 'aaaaaa']) :call add(tl, [2, 'a\{0}', 'asoiuj', '']) :call add(tl, [2, 'a\{2}', 'aaaa', 'aa']) :call add(tl, [2, 'a\{2}', 'iuash fiusahfliusah fiushfilushfi uhsaifuh askfj nasfvius afg aaaa sfiuhuhiushf', 'aa']) :call add(tl, [2, 'a\{2}', 'abcdefghijklmnopqrestuvwxyz1234567890']) :" same thing as 'a*' :call add(tl, [2, 'a\{0,}', 'oij sdigfusnf', '']) :call add(tl, [2, 'a\{0,}', 'aaaaa aa', 'aaaaa']) :call add(tl, [2, 'a\{2,}', 'sdfiougjdsafg']) :call add(tl, [2, 'a\{2,}', 'aaaaasfoij ', 'aaaaa']) :call add(tl, [2, 'a\{5,}', 'xxaaaaxxx ']) :call add(tl, [2, 'a\{5,}', 'xxaaaaaxxx ', 'aaaaa']) :call add(tl, [2, 'a\{,0}', 'oidfguih iuhi hiu aaaa', '']) :call add(tl, [2, 'a\{,5}', 'abcd', 'a']) :call add(tl, [2, 'a\{,5}', 'aaaaaaaaaa', 'aaaaa']) :" same thing as 'a*' :call add(tl, [2, 'a\{}', 'bbbcddiuhfcd', '']) :call add(tl, [2, 'a\{}', 'aaaaioudfh coisf jda', 'aaaa']) :" :call add(tl, [2, 'a\{-0,0}', 'abcdfdoij', '']) :" anti-greedy version of 'a?' :call add(tl, [2, 'a\{-0,1}', 'asiubid axxxaaa', '']) :call add(tl, [2, 'a\{-3,6}', 'aa siofuh']) :call add(tl, [2, 'a\{-3,6}', 'aaaaa asfoij afaa', 'aaa']) :call add(tl, [2, 'a\{-3,6}', 'aaaaaaaa', 'aaa']) :call add(tl, [2, 'a\{-0}', 'asoiuj', '']) :call add(tl, [2, 'a\{-2}', 'aaaa', 'aa']) :call add(tl, [2, 'a\{-2}', 'abcdefghijklmnopqrestuvwxyz1234567890']) :call add(tl, [2, 'a\{-0,}', 'oij sdigfusnf', '']) :call add(tl, [2, 'a\{-0,}', 'aaaaa aa', '']) :call add(tl, [2, 'a\{-2,}', 'sdfiougjdsafg']) :call add(tl, [2, 'a\{-2,}', 'aaaaasfoij ', 'aa']) :call add(tl, [2, 'a\{-,0}', 'oidfguih iuhi hiu aaaa', '']) :call add(tl, [2, 'a\{-,5}', 'abcd', '']) :call add(tl, [2, 'a\{-,5}', 'aaaaaaaaaa', '']) :" anti-greedy version of 'a*' :call add(tl, [2, 'a\{-}', 'bbbcddiuhfcd', '']) :call add(tl, [2, 'a\{-}', 'aaaaioudfh coisf jda', '']) :" :" Test groups of characters and submatches :call add(tl, [2, '\(abc\)*', 'abcabcabc', 'abcabcabc', 'abc']) :call add(tl, [2, '\(ab\)\+', 'abababaaaaa', 'ababab', 'ab']) :call add(tl, [2, '\(abaaaaa\)*cd', 'cd', 'cd', '']) :call add(tl, [2, '\(test1\)\? \(test2\)\?', 'test1 test3', 'test1 ', 'test1', '']) :call add(tl, [2, '\(test1\)\= \(test2\) \(test4443\)\=', ' test2 test4443 yupiiiiiiiiiii', ' test2 test4443', '', 'test2', 'test4443']) :call add(tl, [2, '\(\(sub1\) hello \(sub 2\)\)', 'asterix sub1 hello sub 2 obelix', 'sub1 hello sub 2', 'sub1 hello sub 2', 'sub1', 'sub 2']) :call add(tl, [2, '\(\(\(yyxxzz\)\)\)', 'abcdddsfiusfyyzzxxyyxxzz', 'yyxxzz', 'yyxxzz', 'yyxxzz', 'yyxxzz']) :call add(tl, [2, '\v((ab)+|c+)+', 'abcccaba', 'abcccab', 'ab', 'ab']) :call add(tl, [2, '\v((ab)|c*)+', 'abcccaba', 'abcccab', '', 'ab']) :call add(tl, [2, '\v(a(c*)+b)+', 'acbababaaa', 'acbabab', 'ab', '']) :call add(tl, [2, '\v(a|b*)+', 'aaaa', 'aaaa', '']) :" :" Test greedy-ness and lazy-ness :call add(tl, [2, 'a\{-2,7}','aaaaaaaaaaaaa', 'aa']) :call add(tl, [2, 'a\{-2,7}x','aaaaaaaaax', 'aaaaaaax']) :call add(tl, [2, 'a\{2,7}','aaaaaaaaaaaaaaaaaaaa', 'aaaaaaa']) :call add(tl, [2, 'a\{2,7}x','aaaaaaaaax', 'aaaaaaax']) :call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz']) :call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa','']) :call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa']) :call add(tl, [2, '\v(a{-1,3})+','aa','aa','a']) :" :" Test Character classes :call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23']) :" :" Test collections and character range [] :call add(tl, [2, '\v[a]', 'abcd', 'a']) :call add(tl, [2, 'a[bcd]', 'abcd', 'ab']) :call add(tl, [2, 'a[b-d]', 'acbd', 'ac']) :call add(tl, [2, '[a-d][e-f][x-x]d', 'cexdxx', 'cexd']) :call add(tl, [2, '\v[[:alpha:]]+', 'abcdefghijklmnopqrstuvwxyz6','abcdefghijklmnopqrstuvwxyz']) :call add(tl, [2, '[[:alpha:]\+]', '6x8','x']) :call add(tl, [2, '[^abc]\+','abcabcabc']) :call add(tl, [2, '[^abc]','defghiasijvoinasoiunbvb','d']) :call add(tl, [2, '[^abc]\+','ddddddda','ddddddd']) :call add(tl, [2, '[^a-d]\+','aaaAAAZIHFNCddd','AAAZIHFNC']) :call add(tl, [2, '[a-f]*','iiiiiiii','']) :call add(tl, [2, '[a-f]*','abcdefgh','abcdef']) :call add(tl, [2, '[^a-f]\+','abcdefgh','gh']) :call add(tl, [2, '[a-c]\{-3,6}','abcabc','abc']) :call add(tl, [2, '[^[:alpha:]]\+','abcccadfoij7787ysf287yrnccdu','7787']) :call add(tl, [2, '[-a]', '-', '-']) :call add(tl, [2, '[a-]', '-', '-']) :" filename regexp :call add(tl, [2, '[-./[:alnum:]_~]\+', 'log13.file', 'log13.file']) :" special chars :call add(tl, [2, '[\]\^\-\\]\+', '\^\\\-\---^', '\^\\\-\---^']) :" collation elem :call add(tl, [2, '[[.a.]]\+', 'aa', 'aa']) :" middle of regexp :call add(tl, [2, 'abc[0-9]*ddd', 'siuhabc ii']) :call add(tl, [2, 'abc[0-9]*ddd', 'adf abc44482ddd oijs', 'abc44482ddd']) :call add(tl, [2, '\_[0-9]\+', 'asfi9888u', '9888']) :call add(tl, [2, '[0-9\n]\+', 'asfi9888u', '9888']) :call add(tl, [2, '\_[0-9]\+', "asfi\n9888u", "\n9888"]) :call add(tl, [2, '\_f', " \na ", "\n"]) :call add(tl, [2, '\_f\+', " \na ", "\na"]) :call add(tl, [2, '[0-9A-Za-z-_.]\+', " @0_a.A-{ ", "0_a.A-"]) :" :"""" Test start/end of line, start/end of file :call add(tl, [2, '^a.', "a_\nb ", "a_"]) :call add(tl, [2, '^a.', "b a \na_"]) :call add(tl, [2, '.a$', " a\n "]) :call add(tl, [2, '.a$', " a b\n_a", "_a"]) :call add(tl, [2, '\%^a.', "a a\na", "a "]) :call add(tl, [2, '\%^a', " a \na "]) :call add(tl, [2, '.a\%$', " a\n "]) :call add(tl, [2, '.a\%$', " a\n_a", "_a"]) :" :"""" Test recognition of some character classes :call add(tl, [2, '[0-9]', '8', '8']) :call add(tl, [2, '[^0-9]', '8']) :call add(tl, [2, '[0-9a-fA-F]*', '0a7', '0a7']) :call add(tl, [2, '[^0-9A-Fa-f]\+', '0a7']) :call add(tl, [2, '[a-z_A-Z0-9]\+', 'aso_sfoij', 'aso_sfoij']) :call add(tl, [2, '[a-z]', 'a', 'a']) :call add(tl, [2, '[a-zA-Z]', 'a', 'a']) :call add(tl, [2, '[A-Z]', 'a']) :call add(tl, [2, '\C[^A-Z]\+', 'ABCOIJDEOIFNSD jsfoij sa', ' jsfoij sa']) :" :"""" Tests for \z features :" match ends at \ze :call add(tl, [2, 'xx \ze test', 'xx ']) :call add(tl, [2, 'abc\zeend', 'oij abcend', 'abc']) :call add(tl, [2, 'aa\zebb\|aaxx', ' aabb ', 'aa']) :call add(tl, [2, 'aa\zebb\|aaxx', ' aaxx ', 'aaxx']) :call add(tl, [2, 'aabb\|aa\zebb', ' aabb ', 'aabb']) :call add(tl, [2, 'aa\zebb\|aaebb', ' aabb ', 'aa']) :" match starts at \zs :call add(tl, [2, 'abc\zsdd', 'ddabcddxyzt', 'dd']) :call add(tl, [2, 'aa \zsax', ' ax']) :call add(tl, [2, 'abc \zsmatch\ze abc', 'abc abc abc match abc abc', 'match']) :call add(tl, [2, '\v(a \zsif .*){2}', 'a if then a if last', 'if last', 'a if last']) :call add(tl, [2, '\>\zs.', 'aword. ', '.']) :" :"""" Tests for \@= and \& features :call add(tl, [2, 'abc\@=', 'abc', 'ab']) :call add(tl, [2, 'abc\@=cd', 'abcd', 'abcd']) :call add(tl, [2, 'abc\@=', 'ababc', 'ab']) :" will never match, no matter the input text :call add(tl, [2, 'abcd\@=e', 'abcd']) :" will never match :call add(tl, [2, 'abcd\@=e', 'any text in here ... ']) :call add(tl, [2, '\v(abc)@=..', 'xabcd', 'ab', 'abc']) :call add(tl, [2, '\(.*John\)\@=.*Bob', 'here is John, and here is B']) :call add(tl, [2, '\(John.*\)\@=.*Bob', 'John is Bobs friend', 'John is Bob', 'John is Bobs friend']) :call add(tl, [2, '\<\S\+\())\)\@=', '$((i=i+1))', 'i=i+1', '))']) :call add(tl, [2, '.*John\&.*Bob', 'here is John, and here is B']) :call add(tl, [2, '.*John\&.*Bob', 'John is Bobs friend', 'John is Bob']) :call add(tl, [2, '\v(test1)@=.*yep', 'this is a test1, yep it is', 'test1, yep', 'test1']) :call add(tl, [2, 'foo\(bar\)\@!', 'foobar']) :call add(tl, [2, 'foo\(bar\)\@!', 'foo bar', 'foo']) :call add(tl, [2, 'if \(\(then\)\@!.\)*$', ' if then else']) :call add(tl, [2, 'if \(\(then\)\@!.\)*$', ' if else ', 'if else ', ' ']) :call add(tl, [2, '\(foo\)\@!bar', 'foobar', 'bar']) :call add(tl, [2, '\(foo\)\@!...bar', 'foobar']) :call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' bar foo ']) :call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' foo bar ']) :call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' foo xxx ', 'foo']) :" :"""" Combining different tests and features :call add(tl, [2, '[[:alpha:]]\{-2,6}', '787abcdiuhsasiuhb4', 'ab']) :call add(tl, [2, '', 'abcd', '']) :call add(tl, [2, '\v(())', 'any possible text', '']) :call add(tl, [2, '\v%(ab(xyz)c)', ' abxyzc ', 'abxyzc', 'xyz']) :call add(tl, [2, '\v(test|)empty', 'tesempty', 'empty', '']) :call add(tl, [2, '\v(a|aa)(a|aa)', 'aaa', 'aa', 'a', 'a']) :" :"""" \%u and friends :call add(tl, [2, '\%d32', 'yes no', ' ']) :call add(tl, [2, '\%o40', 'yes no', ' ']) :call add(tl, [2, '\%x20', 'yes no', ' ']) :call add(tl, [2, '\%u0020', 'yes no', ' ']) :call add(tl, [2, '\%U00000020', 'yes no', ' ']) :" :"""" Alternatives, must use first longest match :call add(tl, [2, 'goo\|go', 'google', 'goo']) :call add(tl, [2, '\<goo\|\<go', 'google', 'goo']) :call add(tl, [2, '\<goo\|go', 'google', 'goo']) :" :"""" Back references :call add(tl, [2, '\(\i\+\) \1', ' abc abc', 'abc abc', 'abc']) :call add(tl, [2, '\(\i\+\) \1', 'xgoo goox', 'goo goo', 'goo']) :call add(tl, [2, '\(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9', 'xabcddefghiabcddefghix', 'abcddefghiabcddefghi', 'a', 'b', 'c', 'dd', 'e', 'f', 'g', 'h', 'i']) :" :"""" Look-behind with limit :call add(tl, [0, '<\@<=span.', 'xxspanxx<spanyyy', 'spany']) :call add(tl, [0, '<\@1<=span.', 'xxspanxx<spanyyy', 'spany']) :call add(tl, [0, '<\@2<=span.', 'xxspanxx<spanyyy', 'spany']) :call add(tl, [0, '\(<<\)\@<=span.', 'xxspanxxxx<spanxx<<spanyyy', 'spany', '<<']) :call add(tl, [0, '\(<<\)\@1<=span.', 'xxspanxxxx<spanxx<<spanyyy']) :call add(tl, [0, '\(<<\)\@2<=span.', 'xxspanxxxx<spanxx<<spanyyy', 'spany', '<<']) :" :"""" "\_" prepended negated collection matches EOL :call add(tl, [2, '\_[^8-9]\+', "asfi\n9888", "asfi\n"]) :call add(tl, [2, '\_[^a]\+', "asfi\n9888", "sfi\n9888"]) :" :"""" Requiring lots of states. :call add(tl, [2, '[0-9a-zA-Z]\{8}-\([0-9a-zA-Z]\{4}-\)\{3}[0-9a-zA-Z]\{12}', " 12345678-1234-1234-1234-123456789012 ", "12345678-1234-1234-1234-123456789012", "1234-"]) :" :" :"""" Run the tests :" :for t in tl : let re = t[0] : let pat = t[1] : let text = t[2] : let matchidx = 3 : for engine in [0, 1, 2] : if engine == 2 && !re : continue : endif : let ®expengine = engine : try : let l = matchlist(text, pat) : catch : $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"' : endtry :" check the match itself : if len(l) == 0 && len(t) > matchidx : $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"' : elseif len(l) > 0 && len(t) == matchidx : $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match' : elseif len(t) > matchidx && l[0] != t[matchidx] : $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"' : else : $put ='OK ' . engine . ' - ' . pat : endif : if len(l) > 0 :" check all the nine submatches : for i in range(1, 9) : if len(t) <= matchidx + i : let e = '' : else : let e = t[matchidx + i] : endif : if l[i] != e : $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' : endif : endfor : unlet i : endif : endfor :endfor :unlet t tl e l :" :" Check that \_[0-9] matching EOL does not break a following \> :" This only works on a buffer line, not with expression evaluation /^Find this /\%#=0\<\(\(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]\?\)\> y$Gop:" /^Find this /\%#=1\<\(\(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]\?\)\> y$Gop:" /^Find this /\%#=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]\?\)\> y$Gop:" :" :" Check that using a pattern on two lines doesn't get messed up by using :" matchstr() with \ze in between. :set re=0 /^Substitute here :.+1,.+2s/""/\='"'.matchstr(getline("."), '\d\+\ze<').'"' /^Substitute here :.+1,.+2yank Gop:" :" :" Check a pattern with a line break matches in the right position. /^Multiline /\S.*\nx :.yank y$Gop:" :" :" Check a pattern with a look beind crossing a line boundary /^Behind: /\(<\_[xy]\+\)\@3<=start :.yank Gop:" :" :" Check patterns matching cursor position. :func! Postest() new call setline(1, ['ffooooo', 'boboooo', 'zoooooo', 'koooooo', 'moooooo', "\t\t\tfoo", 'abababababababfoo', 'bababababababafoo', '********_']) call setpos('.', [0, 1, 0, 0]) s/\%>3c.//g call setpos('.', [0, 2, 4, 0]) s/\%#.*$//g call setpos('.', [0, 3, 0, 0]) s/\%<3c./_/g %s/\%4l\%>5c./_/g %s/\%6l\%>25v./_/g %s/\%>6l\%3c./!/g %s/\%>7l\%12c./?/g %s/\%>7l\%<9l\%>5v\%<8v./#/g 1,$yank quit! endfunc Go-0-:set re=0 :call Postest() :put o-1-:set re=1 :call Postest() :put o-2-:set re=2 :call Postest() :put :" :" start and end of buffer /\%^ yeGop:" 50%/\%^.. yeGopA END:" 50%/\%$ "ayb20gg/..\%$ "bybGo"apo"bp:" :" :/\%#=1^Results/,$wq! test.out ENDTEST Find this: localnet/192.168.0.1 Substitute here: <T="">Ta 5</Title> <T="">Ac 7</Title> Multiline: abc def ghi xjk lmn Behind: asdfasd<yyy xxstart1 asdfasd<yy xxxxstart2 asdfasd<yy xxxstart3 Results of test64: