1" Tests for regexp in latin1 encoding
2set encoding=latin1
3scriptencoding latin1
4
5func s:equivalence_test()
6  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"
7  let groups = split(str)
8  for group1 in groups
9      for c in split(group1, '\zs')
10	" next statement confirms that equivalence class matches every
11	" character in group
12        call assert_match('^[[=' . c . '=]]*$', group1)
13        for group2 in groups
14          if group2 != group1
15	    " next statement converts that equivalence class doesn't match
16	    " a character in any other group
17            call assert_equal(-1, match(group2, '[[=' . c . '=]]'))
18          endif
19        endfor
20      endfor
21  endfor
22endfunc
23
24func Test_equivalence_re1()
25  set re=1
26  call s:equivalence_test()
27endfunc
28
29func Test_equivalence_re2()
30  set re=2
31  call s:equivalence_test()
32endfunc
33
34func Test_recursive_substitute()
35  new
36  s/^/\=execute("s#^##gn")
37  " check we are now not in the sandbox
38  call setwinvar(1, 'myvar', 1)
39  bwipe!
40endfunc
41
42func Test_nested_backrefs()
43  " Check example in change.txt.
44  new
45  for re in range(0, 2)
46    exe 'set re=' . re
47    call setline(1, 'aa ab x')
48    1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/
49    call assert_equal('-aa ab - -ab - -x-', getline(1))
50
51    call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] \)*\)\(x\)', '-\1- -\2- -\3-', ''))
52  endfor
53  bwipe!
54  set re=0
55endfunc
56
57func Test_eow_with_optional()
58  let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', '']
59  for re in range(0, 2)
60    exe 'set re=' . re
61    let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)')
62    call assert_equal(expected, actual)
63  endfor
64endfunc
65
66func Test_backref()
67  new
68  call setline(1, ['one', 'two', 'three', 'four', 'five'])
69  call assert_equal(3, search('\%#=1\(e\)\1'))
70  call assert_equal(3, search('\%#=2\(e\)\1'))
71  call assert_fails('call search("\\%#=1\\(e\\1\\)")', 'E65:')
72  call assert_fails('call search("\\%#=2\\(e\\1\\)")', 'E65:')
73  bwipe!
74endfunc
75
76func Test_multi_failure()
77  set re=1
78  call assert_fails('/a**', 'E61:')
79  call assert_fails('/a*\+', 'E62:')
80  call assert_fails('/a\{a}', 'E554:')
81  set re=2
82  call assert_fails('/a**', 'E871:')
83  call assert_fails('/a*\+', 'E871:')
84  call assert_fails('/a\{a}', 'E870:')
85  set re=0
86endfunc
87
88func Test_recursive_addstate()
89  " This will call addstate() recursively until it runs into the limit.
90  let lnum = search('\v((){328}){389}')
91  call assert_equal(0, lnum)
92endfunc
93
94func Test_out_of_memory()
95  new
96  s/^/,n
97  " This will be slow...
98  call assert_fails('call search("\\v((n||<)+);")', 'E363:')
99endfunc
100
101func Test_get_equi_class()
102  new
103  " Incomplete equivalence class caused invalid memory access
104  s/^/[[=
105  call assert_equal(1, search(getline(1)))
106  s/.*/[[.
107  call assert_equal(1, search(getline(1)))
108endfunc
109
110func Test_rex_init()
111  set noincsearch
112  set re=1
113  new
114  setlocal iskeyword=a-z
115  call setline(1, ['abc', 'ABC'])
116  call assert_equal(1, search('[[:keyword:]]'))
117  new
118  setlocal iskeyword=A-Z
119  call setline(1, ['abc', 'ABC'])
120  call assert_equal(2, search('[[:keyword:]]'))
121  bwipe!
122  bwipe!
123  set re=0
124endfunc
125
126func Test_range_with_newline()
127  new
128  call setline(1, "a")
129  call assert_equal(0, search("[ -*\\n- ]"))
130  call assert_equal(0, search("[ -*\\t-\\n]"))
131  bwipe!
132endfunc
133
134func Test_pattern_compile_speed()
135  if !exists('+spellcapcheck') || !has('reltime')
136    return
137  endif
138  let start = reltime()
139  " this used to be very slow, not it should be about a second
140  set spc=\\v(((((Nxxxxxxx&&xxxx){179})+)+)+){179}
141  call assert_inrange(0.01, 10.0, reltimefloat(reltime(start)))
142  set spc=
143endfunc
144