" Tests for regexp in latin1 encoding
" set encoding=latin1
scriptencoding latin1
source check.vim
func s:equivalence_test()
let str = 'AÀÁÂÃÄÅ B C D EÈÉÊË F G H IÌÍÎÏ J K L M NÑ OÒÓÔÕÖØ P Q R S T UÙÚÛÜ V W X YÝ Z '
\ .. 'aàáâãäå b c d eèéêë f g h iìíîï j k l m nñ oòóôõöø p q r s t uùúûü v w x yýÿ z '
\ .. "0 1 2 3 4 5 6 7 8 9 "
\ .. "` ~ ! ? ; : . , / \\ ' \" | < > [ ] { } ( ) @ # $ % ^ & * _ - + \b \e \f \n \r \t"
let groups = split(str)
for group1 in groups
for c in split(group1, '\zs')
" next statement confirms that equivalence class matches every
" character in group
call assert_match('^[[=' . c . '=]]*$', group1)
for group2 in groups
if group2 != group1
" next statement converts that equivalence class doesn't match
" a character in any other group
call assert_equal(-1, match(group2, '[[=' . c . '=]]'))
endif
endfor
endfor
endfor
endfunc
func Test_equivalence_re1()
throw 'skipped: Nvim does not support enc=latin1'
set re=1
call s:equivalence_test()
endfunc
func Test_equivalence_re2()
throw 'skipped: Nvim does not support enc=latin1'
set re=2
call s:equivalence_test()
endfunc
func Test_range_with_newline()
new
call setline(1, "a")
call assert_equal(0, search("[ -*\\n- ]"))
call assert_equal(0, search("[ -*\\t-\\n]"))
bwipe!
endfunc
func Test_pattern_compile_speed()
CheckOption spellcapcheck
CheckFunction reltimefloat
let start = reltime()
" this used to be very slow, not it should be about a second
set spc=\\v(((((Nxxxxxxx&&xxxx){179})+)+)+){179}
call assert_inrange(0.01, 10.0, reltimefloat(reltime(start)))
set spc=
endfunc
func Test_get_equi_class()
new
" Incomplete equivalence class caused invalid memory access
s/^/[[=
call assert_equal(1, search(getline(1)))
s/.*/[[.
call assert_equal(1, search(getline(1)))
endfunc
func Test_rex_init()
set noincsearch
set re=1
new
setlocal iskeyword=a-z
call setline(1, ['abc', 'ABC'])
call assert_equal(1, search('[[:keyword:]]'))
new
setlocal iskeyword=A-Z
call setline(1, ['abc', 'ABC'])
call assert_equal(2, search('[[:keyword:]]'))
bwipe!
bwipe!
set re=0
endfunc
func Test_backref()
new
call setline(1, ['one', 'two', 'three', 'four', 'five'])
call assert_equal(3, search('\%#=1\(e\)\1'))
call assert_equal(3, search('\%#=2\(e\)\1'))
call assert_fails('call search("\\%#=1\\(e\\1\\)")', 'E65:')
call assert_fails('call search("\\%#=2\\(e\\1\\)")', 'E65:')
bwipe!
endfunc
func Test_multi_failure()
set re=1
call assert_fails('/a**', 'E61:')
call assert_fails('/a*\+', 'E62:')
call assert_fails('/a\{a}', 'E554:')
set re=2
call assert_fails('/a**', 'E871:')
call assert_fails('/a*\+', 'E871:')
call assert_fails('/a\{a}', 'E554:')
set re=0
endfunc
func Test_column_success_failure()
new
call setline(1, 'xbar')
set re=1
%s/\%>0v./A/
call assert_equal('Abar', getline(1))
call assert_fails('/\%v', 'E71:')
call assert_fails('/\%>v', 'E71:')
call assert_fails('/\%c', 'E71:')
call assert_fails('/\%<c', 'E71:')
call assert_fails('/\%l', 'E71:')
set re=2
%s/\%>0v./B/
call assert_equal('Bbar', getline(1))
call assert_fails('/\%v', 'E1273:')
call assert_fails('/\%>v', 'E1273:')
call assert_fails('/\%c', 'E1273:')
call assert_fails('/\%<c', 'E1273:')
call assert_fails('/\%l', 'E1273:')
set re=0
bwipe!
endfunc
func Test_recursive_addstate()
throw 'skipped: TODO: '
" This will call addstate() recursively until it runs into the limit.
let lnum = search('\v((){328}){389}')
call assert_equal(0, lnum)
endfunc
func Test_out_of_memory()
new
s/^/,n
" This will be slow...
call assert_fails('call search("\\v((n||<)+);")', 'E363:')
endfunc
" Tests for regexp patterns without multi-byte support.
func Test_regexp_single_line_pat()
" tl is a List of Lists with:
" regexp engines to test
" 0 - test with 'regexpengine' values 0 and 1
" 1 - test with 'regexpengine' values 0 and 2
" 2 - test with 'regexpengine' values 0, 1 and 2
" 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 = []
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
" match escape character in a string
call add
|