1" Tests for regexp in utf8 encoding 2 3func s:equivalence_test() 4 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ñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ" 5 let groups = split(str) 6 for group1 in groups 7 for c in split(group1, '\zs') 8 " next statement confirms that equivalence class matches every 9 " character in group 10 call assert_match('^[[=' . c . '=]]*$', group1) 11 for group2 in groups 12 if group2 != group1 13 " next statement converts that equivalence class doesn't match 14 " character in any other group 15 call assert_equal(-1, match(group2, '[[=' . c . '=]]')) 16 endif 17 endfor 18 endfor 19 endfor 20endfunc 21 22func Test_equivalence_re1() 23 set re=1 24 call s:equivalence_test() 25 set re=0 26endfunc 27 28func Test_equivalence_re2() 29 set re=2 30 call s:equivalence_test() 31 set re=0 32endfunc 33 34func s:classes_test() 35 if has('win32') 36 set iskeyword=@,48-57,_,192-255 37 endif 38 set isprint=@,161-255 39 call assert_equal('Motörhead', matchstr('Motörhead', '[[:print:]]\+')) 40 41 let alnumchars = '' 42 let alphachars = '' 43 let backspacechar = '' 44 let blankchars = '' 45 let cntrlchars = '' 46 let digitchars = '' 47 let escapechar = '' 48 let graphchars = '' 49 let lowerchars = '' 50 let printchars = '' 51 let punctchars = '' 52 let returnchar = '' 53 let spacechars = '' 54 let tabchar = '' 55 let upperchars = '' 56 let xdigitchars = '' 57 let identchars = '' 58 let identchars1 = '' 59 let kwordchars = '' 60 let kwordchars1 = '' 61 let fnamechars = '' 62 let fnamechars1 = '' 63 let i = 1 64 while i <= 255 65 let c = nr2char(i) 66 if c =~ '[[:alpha:]]' 67 let alphachars .= c 68 endif 69 if c =~ '[[:alnum:]]' 70 let alnumchars .= c 71 endif 72 if c =~ '[[:backspace:]]' 73 let backspacechar .= c 74 endif 75 if c =~ '[[:blank:]]' 76 let blankchars .= c 77 endif 78 if c =~ '[[:cntrl:]]' 79 let cntrlchars .= c 80 endif 81 if c =~ '[[:digit:]]' 82 let digitchars .= c 83 endif 84 if c =~ '[[:escape:]]' 85 let escapechar .= c 86 endif 87 if c =~ '[[:graph:]]' 88 let graphchars .= c 89 endif 90 if c =~ '[[:lower:]]' 91 let lowerchars .= c 92 endif 93 if c =~ '[[:print:]]' 94 let printchars .= c 95 endif 96 if c =~ '[[:punct:]]' 97 let punctchars .= c 98 endif 99 if c =~ '[[:return:]]' 100 let returnchar .= c 101 endif 102 if c =~ '[[:space:]]' 103 let spacechars .= c 104 endif 105 if c =~ '[[:tab:]]' 106 let tabchar .= c 107 endif 108 if c =~ '[[:upper:]]' 109 let upperchars .= c 110 endif 111 if c =~ '[[:xdigit:]]' 112 let xdigitchars .= c 113 endif 114 if c =~ '[[:ident:]]' 115 let identchars .= c 116 endif 117 if c =~ '\i' 118 let identchars1 .= c 119 endif 120 if c =~ '[[:keyword:]]' 121 let kwordchars .= c 122 endif 123 if c =~ '\k' 124 let kwordchars1 .= c 125 endif 126 if c =~ '[[:fname:]]' 127 let fnamechars .= c 128 endif 129 if c =~ '\f' 130 let fnamechars1 .= c 131 endif 132 let i += 1 133 endwhile 134 135 call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alphachars) 136 call assert_equal('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alnumchars) 137 call assert_equal("\b", backspacechar) 138 call assert_equal("\t ", blankchars) 139 call assert_equal("\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0b\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\e\x1c\x1d\x1e\x1f\x7f", cntrlchars) 140 call assert_equal("0123456789", digitchars) 141 call assert_equal("\<Esc>", escapechar) 142 call assert_equal('!"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', graphchars) 143 call assert_equal('abcdefghijklmnopqrstuvwxyzµßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', lowerchars) 144 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ', printchars) 145 call assert_equal('!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~', punctchars) 146 call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ', upperchars) 147 call assert_equal("\r", returnchar) 148 call assert_equal("\t\n\x0b\f\r ", spacechars) 149 call assert_equal("\t", tabchar) 150 call assert_equal('0123456789ABCDEFabcdef', xdigitchars) 151 152 if has('win32') 153 let identchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz ¡¢£¤¥¦§µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' 154 let kwordchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 155 elseif has('ebcdic') 156 let identchars_ok = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz¬®µº¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 157 let kwordchars_ok = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz¬®µº¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 158 else 159 let identchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 160 let kwordchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 161 endif 162 163 if has('win32') 164 let fnamechars_ok = '!#$%+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_abcdefghijklmnopqrstuvwxyz{}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 165 elseif has('amiga') 166 let fnamechars_ok = '$+,-./0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 167 elseif has('vms') 168 let fnamechars_ok = '#$%+,-./0123456789:;<>ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 169 elseif has('ebcdic') 170 let fnamechars_ok = '#$%+,-./=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 171 else 172 let fnamechars_ok = '#$%+,-./0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' 173 endif 174 175 call assert_equal(identchars_ok, identchars) 176 call assert_equal(kwordchars_ok, kwordchars) 177 call assert_equal(fnamechars_ok, fnamechars) 178 179 call assert_equal(identchars1, identchars) 180 call assert_equal(kwordchars1, kwordchars) 181 call assert_equal(fnamechars1, fnamechars) 182endfunc 183 184func Test_classes_re1() 185 set re=1 186 call s:classes_test() 187 set re=0 188endfunc 189 190func Test_classes_re2() 191 set re=2 192 call s:classes_test() 193 set re=0 194endfunc 195 196func Test_recursive_substitute() 197 new 198 s/^/\=execute("s#^##gn") 199 " check we are now not in the sandbox 200 call setwinvar(1, 'myvar', 1) 201 bwipe! 202endfunc 203 204func Test_nested_backrefs() 205 " Check example in change.txt. 206 new 207 for re in range(0, 2) 208 exe 'set re=' . re 209 call setline(1, 'aa ab x') 210 1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/ 211 call assert_equal('-aa ab - -ab - -x-', getline(1)) 212 213 call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] \)*\)\(x\)', '-\1- -\2- -\3-', '')) 214 endfor 215 bwipe! 216 set re=0 217endfunc 218 219func Test_eow_with_optional() 220 let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', ''] 221 for re in range(0, 2) 222 exe 'set re=' . re 223 let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)') 224 call assert_equal(expected, actual) 225 endfor 226endfunc 227 228func Test_reversed_range() 229 for re in range(0, 2) 230 exe 'set re=' . re 231 call assert_fails('call match("abc def", "[c-a]")', 'E944:') 232 endfor 233 set re=0 234endfunc 235 236func Test_large_class() 237 set re=1 238 call assert_fails('call match("abc def", "[\u3000-\u4000]")', 'E945:') 239 set re=2 240 call assert_equal(0, 'abc def' =~# '[\u3000-\u4000]') 241 call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]') 242 set re=0 243endfunc 244 245func Test_optmatch_toolong() 246 set re=1 247 " Can only handle about 8000 characters. 248 let pat = '\\%[' .. repeat('x', 9000) .. ']' 249 call assert_fails('call match("abc def", "' .. pat .. '")', 'E339:') 250 set re=0 251endfunc 252 253" Test for regexp patterns with multi-byte support, using utf-8. 254func Test_multibyte_chars() 255 " tl is a List of Lists with: 256 " 2: test auto/old/new 0: test auto/old 1: test auto/new 257 " regexp pattern 258 " text to test the pattern on 259 " expected match (optional) 260 " expected submatch 1 (optional) 261 " expected submatch 2 (optional) 262 " etc. 263 " When there is no match use only the first two items. 264 let tl = [] 265 266 " Multi-byte character tests. These will fail unless vim is compiled 267 " with Multibyte (FEAT_MBYTE) or BIG/HUGE features. 268 call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna']) 269 call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes 270 call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos']) 271 call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม']) 272 call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna']) 273 274 " this is not a normal "i" but 0xec 275 call add(tl, [2, '\p\+', 'ìa', 'ìa']) 276 call add(tl, [2, '\p*', 'aあ', 'aあ']) 277 278 " Test recognition of some character classes 279 call add(tl, [2, '\i\+', '&*¨xx ', 'xx']) 280 call add(tl, [2, '\f\+', '&*fname ', 'fname']) 281 282 " Test composing character matching 283 call add(tl, [2, '.ม', 'xม่x yมy', 'yม']) 284 call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่']) 285 call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"]) 286 call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"]) 287 call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) 288 call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) 289 call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) 290 call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) 291 call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"]) 292 call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"]) 293 call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"]) 294 call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"]) 295 call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"]) 296 call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"]) 297 call add(tl, [2, "a", "ca\u0300t"]) 298 call add(tl, [2, "ca", "ca\u0300t"]) 299 call add(tl, [2, "a\u0300", "ca\u0300t", "a\u0300"]) 300 call add(tl, [2, 'a\%C', "ca\u0300t", "a\u0300"]) 301 call add(tl, [2, 'ca\%C', "ca\u0300t", "ca\u0300"]) 302 call add(tl, [2, 'ca\%Ct', "ca\u0300t", "ca\u0300t"]) 303 304 " Test \Z 305 call add(tl, [2, 'ú\Z', 'x']) 306 call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה']) 307 call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה']) 308 call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה']) 309 call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה']) 310 call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ']) 311 call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"]) 312 call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"]) 313 call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"]) 314 call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"]) 315 call add(tl, [2, "\u05b9\\Z", "xyz"]) 316 call add(tl, [2, "\\Z\u05b9", "xyz"]) 317 call add(tl, [2, "\u05b9\\Z", "xy\u05b9z", "y\u05b9"]) 318 call add(tl, [2, "\\Z\u05b9", "xy\u05b9z", "y\u05b9"]) 319 call add(tl, [1, "\u05b9\\+\\Z", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"]) 320 call add(tl, [1, "\\Z\u05b9\\+", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"]) 321 322 " Combining different tests and features 323 call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd']) 324 325 " Run the tests 326 for t in tl 327 let re = t[0] 328 let pat = t[1] 329 let text = t[2] 330 let matchidx = 3 331 for engine in [0, 1, 2] 332 if engine == 2 && re == 0 || engine == 1 && re == 1 333 continue 334 endif 335 let ®expengine = engine 336 try 337 let l = matchlist(text, pat) 338 catch 339 call assert_report('Error ' . engine . ': pat: \"' . pat . 340 \ '\", text: \"' . text . 341 \ '\", caused an exception: \"' . v:exception . '\"') 342 endtry 343 " check the match itself 344 if len(l) == 0 && len(t) > matchidx 345 call assert_report('Error ' . engine . ': pat: \"' . pat . 346 \ '\", text: \"' . text . 347 \ '\", did not match, expected: \"' . t[matchidx] . '\"') 348 elseif len(l) > 0 && len(t) == matchidx 349 call assert_report('Error ' . engine . ': pat: \"' . pat . 350 \ '\", text: \"' . text . '\", match: \"' . l[0] . 351 \ '\", expected no match') 352 elseif len(t) > matchidx && l[0] != t[matchidx] 353 call assert_report('Error ' . engine . ': pat: \"' . pat . 354 \ '\", text: \"' . text . '\", match: \"' . l[0] . 355 \ '\", expected: \"' . t[matchidx] . '\"') 356 else 357 " Test passed 358 endif 359 if len(l) > 0 360 " check all the nine submatches 361 for i in range(1, 9) 362 if len(t) <= matchidx + i 363 let e = '' 364 else 365 let e = t[matchidx + i] 366 endif 367 if l[i] != e 368 call assert_report('Error ' . engine . ': pat: \"' . pat . 369 \ '\", text: \"' . text . '\", submatch ' . i . 370 \ ': \"' . l[i] . '\", expected: \"' . e . '\"') 371 endif 372 endfor 373 unlet i 374 endif 375 endfor 376 endfor 377 set regexpengine& 378endfunc 379 380" check that 'ambiwidth' does not change the meaning of \p 381func Test_ambiwidth() 382 set regexpengine=1 ambiwidth=single 383 call assert_equal(0, match("\u00EC", '\p')) 384 set regexpengine=1 ambiwidth=double 385 call assert_equal(0, match("\u00EC", '\p')) 386 set regexpengine=2 ambiwidth=single 387 call assert_equal(0, match("\u00EC", '\p')) 388 set regexpengine=2 ambiwidth=double 389 call assert_equal(0, match("\u00EC", '\p')) 390 set regexpengine& ambiwidth& 391endfunc 392 393func Run_regexp_ignore_case() 394 call assert_equal('iIİ', substitute('iIİ', '\([iIİ]\)', '\1', 'g')) 395 396 call assert_equal('iIx', substitute('iIİ', '\c\([İ]\)', 'x', 'g')) 397 call assert_equal('xxİ', substitute('iIİ', '\(i\c\)', 'x', 'g')) 398 call assert_equal('iIx', substitute('iIİ', '\(İ\c\)', 'x', 'g')) 399 call assert_equal('iIx', substitute('iIİ', '\c\(\%u0130\)', 'x', 'g')) 400 call assert_equal('iIx', substitute('iIİ', '\c\([\u0130]\)', 'x', 'g')) 401 call assert_equal('iIx', substitute('iIİ', '\c\([\u012f-\u0131]\)', 'x', 'g')) 402endfunc 403 404func Test_regexp_ignore_case() 405 set regexpengine=1 406 call Run_regexp_ignore_case() 407 set regexpengine=2 408 call Run_regexp_ignore_case() 409 set regexpengine& 410endfunc 411 412" Tests for regexp with multi-byte encoding and various magic settings 413func Run_regexp_multibyte_magic() 414 let text =<< trim END 415 1 a aa abb abbccc 416 2 d dd dee deefff 417 3 g gg ghh ghhiii 418 4 j jj jkk jkklll 419 5 m mm mnn mnnooo 420 6 x ^aa$ x 421 7 (a)(b) abbaa 422 8 axx [ab]xx 423 9 หม่x อมx 424 a อมx หม่x 425 b ちカヨは 426 c x ¬€x 427 d 天使x 428 e ������y 429 f ������z 430 g a啷bb 431 j 0123❤x 432 k combinations 433 l äö üᾱ̆́ 434 END 435 436 new 437 call setline(1, text) 438 exe 'normal /a*b\{2}c\+/e' .. "\<CR>x" 439 call assert_equal('1 a aa abb abbcc', getline('.')) 440 exe 'normal /\Md\*e\{2}f\+/e' .. "\<CR>x" 441 call assert_equal('2 d dd dee deeff', getline('.')) 442 set nomagic 443 exe 'normal /g\*h\{2}i\+/e' .. "\<CR>x" 444 call assert_equal('3 g gg ghh ghhii', getline('.')) 445 exe 'normal /\mj*k\{2}l\+/e' .. "\<CR>x" 446 call assert_equal('4 j jj jkk jkkll', getline('.')) 447 exe 'normal /\vm*n{2}o+/e' .. "\<CR>x" 448 call assert_equal('5 m mm mnn mnnoo', getline('.')) 449 exe 'normal /\V^aa$/' .. "\<CR>x" 450 call assert_equal('6 x aa$ x', getline('.')) 451 set magic 452 exe 'normal /\v(a)(b)\2\1\1/e' .. "\<CR>x" 453 call assert_equal('7 (a)(b) abba', getline('.')) 454 exe 'normal /\V[ab]\(\[xy]\)\1' .. "\<CR>x" 455 call assert_equal('8 axx ab]xx', getline('.')) 456 457 " search for multi-byte without composing char 458 exe 'normal /ม' .. "\<CR>x" 459 call assert_equal('9 หม่x อx', getline('.')) 460 461 " search for multi-byte with composing char 462 exe 'normal /ม่' .. "\<CR>x" 463 call assert_equal('a อมx หx', getline('.')) 464 465 " find word by change of word class 466 exe 'normal /ち\<カヨ\>は' .. "\<CR>x" 467 call assert_equal('b カヨは', getline('.')) 468 469 " Test \%u, [\u] and friends 470 " c 471 exe 'normal /\%u20ac' .. "\<CR>x" 472 call assert_equal('c x ¬x', getline('.')) 473 " d 474 exe 'normal /[\u4f7f\u5929]\+' .. "\<CR>x" 475 call assert_equal('d 使x', getline('.')) 476 " e 477 exe 'normal /\%U12345678' .. "\<CR>x" 478 call assert_equal('e y', getline('.')) 479 " f 480 exe 'normal /[\U1234abcd\u1234\uabcd]' .. "\<CR>x" 481 call assert_equal('f z', getline('.')) 482 " g 483 exe 'normal /\%d21879b' .. "\<CR>x" 484 call assert_equal('g abb', getline('.')) 485 486 " j Test backwards search from a multi-byte char 487 exe "normal /x\<CR>x?.\<CR>x" 488 call assert_equal('j 012❤', getline('.')) 489 " k 490 let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g' 491 @w 492 call assert_equal('k œ̄ṣ́m̥̄ᾱ̆́', getline(18)) 493 494 close! 495endfunc 496 497func Test_regexp_multibyte_magic() 498 set regexpengine=1 499 call Run_regexp_multibyte_magic() 500 set regexpengine=2 501 call Run_regexp_multibyte_magic() 502 set regexpengine& 503endfunc 504 505" Test for 7.3.192 506" command ":s/ \?/ /g" splits multi-byte characters into bytes 507func Test_split_multibyte_to_bytes() 508 new 509 call setline(1, 'l äö üᾱ̆́') 510 s/ \?/ /g 511 call assert_equal(' l ä ö ü ᾱ̆́', getline(1)) 512 close! 513endfunc 514 515" Test for matchstr() with multibyte characters 516func Test_matchstr_multibyte() 517 new 518 call assert_equal('ב', matchstr("אבגד", ".", 0, 2)) 519 call assert_equal('בג', matchstr("אבגד", "..", 0, 2)) 520 call assert_equal('א', matchstr("אבגד", ".", 0, 0)) 521 call assert_equal('ג', matchstr("אבגד", ".", 4, -1)) 522 close! 523endfunc 524 525" Test for 7.4.636 526" A search with end offset gets stuck at end of file. 527func Test_search_with_end_offset() 528 new 529 call setline(1, ['', 'dog(a', 'cat(']) 530 exe "normal /(/e+" .. "\<CR>" 531 normal "ayn 532 call assert_equal("a\ncat(", @a) 533 close! 534endfunc 535 536" Check that "^" matches even when the line starts with a combining char 537func Test_match_start_of_line_combining() 538 new 539 call setline(1, ['', "\u05ae", '']) 540 exe "normal gg/^\<CR>" 541 call assert_equal(2, getcurpos()[1]) 542 bwipe! 543endfunc 544 545" Check that [[:upper:]] matches for automatic engine 546func Test_match_char_class_upper() 547 new 548 let _engine=®expengine 549 550 " Test 1: [[:upper:]]\{2,\} 551 set regexpengine=0 552 call setline(1, ['05. ПЕСНЯ О ГЕРОЯХ муз. А. Давиденко, М. Коваля и Б. Шехтера ...', '05. PJESNJA O GJEROJAKH mus. A. Davidjenko, M. Kovalja i B. Shjekhtjera ...']) 553 call cursor(1,1) 554 let search_cmd='norm /\<[[:upper:]]\{2,\}\>' .. "\<CR>" 555 exe search_cmd 556 call assert_equal(4, searchcount().total, 'TEST 1') 557 set regexpengine=1 558 exe search_cmd 559 call assert_equal(2, searchcount().total, 'TEST 1') 560 set regexpengine=2 561 exe search_cmd 562 call assert_equal(4, searchcount().total, 'TEST 1') 563 564 " Test 2: [[:upper:]].\+ 565 let search_cmd='norm /\<[[:upper:]].\+\>' .. "\<CR>" 566 set regexpengine=0 567 exe search_cmd 568 call assert_equal(2, searchcount().total, 'TEST 2') 569 set regexpengine=1 570 exe search_cmd 571 call assert_equal(1, searchcount().total, 'TEST 2') 572 set regexpengine=2 573 exe search_cmd 574 call assert_equal(2, searchcount().total, 'TEST 2') 575 576 " Test 3: [[:lower:]]\+ 577 let search_cmd='norm /\<[[:lower:]]\+\>' .. "\<CR>" 578 set regexpengine=0 579 exe search_cmd 580 call assert_equal(4, searchcount().total, 'TEST 3 lower') 581 set regexpengine=1 582 exe search_cmd 583 call assert_equal(2, searchcount().total, 'TEST 3 lower') 584 set regexpengine=2 585 exe search_cmd 586 call assert_equal(4, searchcount().total, 'TEST 3 lower') 587 588 " clean up 589 let ®expengine=_engine 590 bwipe! 591endfunc 592 593" vim: shiftwidth=2 sts=2 expandtab 594