1" Tests for various functions. 2 3source shared.vim 4source check.vim 5source term_util.vim 6source screendump.vim 7source vim9.vim 8 9" Must be done first, since the alternate buffer must be unset. 10func Test_00_bufexists() 11 call assert_equal(0, bufexists('does_not_exist')) 12 call assert_equal(1, bufexists(bufnr('%'))) 13 call assert_equal(0, bufexists(0)) 14 new Xfoo 15 let bn = bufnr('%') 16 call assert_equal(1, bufexists(bn)) 17 call assert_equal(1, bufexists('Xfoo')) 18 call assert_equal(1, bufexists(getcwd() . '/Xfoo')) 19 call assert_equal(1, bufexists(0)) 20 bw 21 call assert_equal(0, bufexists(bn)) 22 call assert_equal(0, bufexists('Xfoo')) 23endfunc 24 25func Test_has() 26 call assert_equal(1, has('eval')) 27 call assert_equal(1, has('eval', 1)) 28 29 if has('unix') 30 call assert_equal(1, or(has('ttyin'), 1)) 31 call assert_equal(0, and(has('ttyout'), 0)) 32 call assert_equal(1, has('multi_byte_encoding')) 33 endif 34 call assert_equal(1, has('vcon', 1)) 35 call assert_equal(1, has('mouse_gpm_enabled', 1)) 36 37 call assert_equal(0, has('nonexistent')) 38 call assert_equal(0, has('nonexistent', 1)) 39 40 " Will we ever have patch 9999? 41 let ver = 'patch-' .. v:version / 100 .. '.' .. v:version % 100 .. '.9999' 42 call assert_equal(0, has(ver)) 43endfunc 44 45func Test_empty() 46 call assert_equal(1, empty('')) 47 call assert_equal(0, empty('a')) 48 49 call assert_equal(1, empty(0)) 50 call assert_equal(1, empty(-0)) 51 call assert_equal(0, empty(1)) 52 call assert_equal(0, empty(-1)) 53 54 if has('float') 55 call assert_equal(1, empty(0.0)) 56 call assert_equal(1, empty(-0.0)) 57 call assert_equal(0, empty(1.0)) 58 call assert_equal(0, empty(-1.0)) 59 call assert_equal(0, empty(1.0/0.0)) 60 call assert_equal(0, empty(0.0/0.0)) 61 endif 62 63 call assert_equal(1, empty([])) 64 call assert_equal(0, empty(['a'])) 65 66 call assert_equal(1, empty({})) 67 call assert_equal(0, empty({'a':1})) 68 69 call assert_equal(1, empty(v:null)) 70 call assert_equal(1, empty(v:none)) 71 call assert_equal(1, empty(v:false)) 72 call assert_equal(0, empty(v:true)) 73 74 if has('channel') 75 call assert_equal(1, empty(test_null_channel())) 76 endif 77 if has('job') 78 call assert_equal(1, empty(test_null_job())) 79 endif 80 81 call assert_equal(0, empty(function('Test_empty'))) 82 call assert_equal(0, empty(function('Test_empty', [0]))) 83 84 call assert_fails("call empty(test_void())", 'E685:') 85 call assert_fails("call empty(test_unknown())", 'E685:') 86endfunc 87 88func Test_test_void() 89 call assert_fails('echo 1 == test_void()', 'E1031:') 90 if has('float') 91 call assert_fails('echo 1.0 == test_void()', 'E1031:') 92 endif 93 call assert_fails('let x = json_encode(test_void())', 'E685:') 94 call assert_fails('let x = copy(test_void())', 'E685:') 95 call assert_fails('let x = copy([test_void()])', 'E1031:') 96endfunc 97 98func Test_len() 99 call assert_equal(1, len(0)) 100 call assert_equal(2, len(12)) 101 102 call assert_equal(0, len('')) 103 call assert_equal(2, len('ab')) 104 105 call assert_equal(0, len([])) 106 call assert_equal(0, len(test_null_list())) 107 call assert_equal(2, len([2, 1])) 108 109 call assert_equal(0, len({})) 110 call assert_equal(0, len(test_null_dict())) 111 call assert_equal(2, len({'a': 1, 'b': 2})) 112 113 call assert_fails('call len(v:none)', 'E701:') 114 call assert_fails('call len({-> 0})', 'E701:') 115endfunc 116 117func Test_max() 118 call assert_equal(0, max([])) 119 call assert_equal(2, max([2])) 120 call assert_equal(2, max([1, 2])) 121 call assert_equal(2, max([1, 2, v:null])) 122 123 call assert_equal(0, max({})) 124 call assert_equal(2, max({'a':1, 'b':2})) 125 126 call assert_fails('call max(1)', 'E712:') 127 call assert_fails('call max(v:none)', 'E712:') 128 129 " check we only get one error 130 call assert_fails('call max([#{}, [1]])', ['E728:', 'E728:']) 131 call assert_fails('call max(#{a: {}, b: [1]})', ['E728:', 'E728:']) 132endfunc 133 134func Test_min() 135 call assert_equal(0, min([])) 136 call assert_equal(2, min([2])) 137 call assert_equal(1, min([1, 2])) 138 call assert_equal(0, min([1, 2, v:null])) 139 140 call assert_equal(0, min({})) 141 call assert_equal(1, min({'a':1, 'b':2})) 142 143 call assert_fails('call min(1)', 'E712:') 144 call assert_fails('call min(v:none)', 'E712:') 145 call assert_fails('call min([1, {}])', 'E728:') 146 147 " check we only get one error 148 call assert_fails('call min([[1], #{}])', ['E745:', 'E745:']) 149 call assert_fails('call min(#{a: [1], b: #{}})', ['E745:', 'E745:']) 150endfunc 151 152func Test_strwidth() 153 for aw in ['single', 'double'] 154 exe 'set ambiwidth=' . aw 155 call assert_equal(0, strwidth('')) 156 call assert_equal(1, strwidth("\t")) 157 call assert_equal(3, strwidth('Vim')) 158 call assert_equal(4, strwidth(1234)) 159 call assert_equal(5, strwidth(-1234)) 160 161 call assert_equal(2, strwidth('')) 162 call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde')) 163 call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße')) 164 165 call assert_fails('call strwidth({->0})', 'E729:') 166 call assert_fails('call strwidth([])', 'E730:') 167 call assert_fails('call strwidth({})', 'E731:') 168 endfor 169 170 if has('float') 171 call assert_equal(3, strwidth(1.2)) 172 call CheckDefFailure(['echo strwidth(1.2)'], 'E1013:') 173 call CheckScriptFailure(['vim9script', 'echo strwidth(1.2)'], 'E806:') 174 endif 175 176 set ambiwidth& 177endfunc 178 179func Test_str2nr() 180 call assert_equal(0, str2nr('')) 181 call assert_equal(1, str2nr('1')) 182 call assert_equal(1, str2nr(' 1 ')) 183 184 call assert_equal(1, str2nr('+1')) 185 call assert_equal(1, str2nr('+ 1')) 186 call assert_equal(1, str2nr(' + 1 ')) 187 188 call assert_equal(-1, str2nr('-1')) 189 call assert_equal(-1, str2nr('- 1')) 190 call assert_equal(-1, str2nr(' - 1 ')) 191 192 call assert_equal(123456789, str2nr('123456789')) 193 call assert_equal(-123456789, str2nr('-123456789')) 194 195 call assert_equal(5, str2nr('101', 2)) 196 call assert_equal(5, '0b101'->str2nr(2)) 197 call assert_equal(5, str2nr('0B101', 2)) 198 call assert_equal(-5, str2nr('-101', 2)) 199 call assert_equal(-5, str2nr('-0b101', 2)) 200 call assert_equal(-5, str2nr('-0B101', 2)) 201 202 call assert_equal(65, str2nr('101', 8)) 203 call assert_equal(65, str2nr('0101', 8)) 204 call assert_equal(-65, str2nr('-101', 8)) 205 call assert_equal(-65, str2nr('-0101', 8)) 206 call assert_equal(65, str2nr('0o101', 8)) 207 call assert_equal(65, str2nr('0O0101', 8)) 208 call assert_equal(-65, str2nr('-0O101', 8)) 209 call assert_equal(-65, str2nr('-0o0101', 8)) 210 211 call assert_equal(11259375, str2nr('abcdef', 16)) 212 call assert_equal(11259375, str2nr('ABCDEF', 16)) 213 call assert_equal(-11259375, str2nr('-ABCDEF', 16)) 214 call assert_equal(11259375, str2nr('0xabcdef', 16)) 215 call assert_equal(11259375, str2nr('0Xabcdef', 16)) 216 call assert_equal(11259375, str2nr('0XABCDEF', 16)) 217 call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) 218 219 call assert_equal(1, str2nr("1'000'000", 10, 0)) 220 call assert_equal(256, str2nr("1'0000'0000", 2, 1)) 221 call assert_equal(262144, str2nr("1'000'000", 8, 1)) 222 call assert_equal(1000000, str2nr("1'000'000", 10, 1)) 223 call assert_equal(1000, str2nr("1'000''000", 10, 1)) 224 call assert_equal(65536, str2nr("1'00'00", 16, 1)) 225 226 call assert_equal(0, str2nr('0x10')) 227 call assert_equal(0, str2nr('0b10')) 228 call assert_equal(0, str2nr('0o10')) 229 call assert_equal(1, str2nr('12', 2)) 230 call assert_equal(1, str2nr('18', 8)) 231 call assert_equal(1, str2nr('1g', 16)) 232 233 call assert_equal(0, str2nr(v:null)) 234 call assert_equal(0, str2nr(v:none)) 235 236 call assert_fails('call str2nr([])', 'E730:') 237 call assert_fails('call str2nr({->2})', 'E729:') 238 if has('float') 239 call assert_equal(1, str2nr(1.2)) 240 call CheckDefFailure(['echo str2nr(1.2)'], 'E1013:') 241 call CheckScriptFailure(['vim9script', 'echo str2nr(1.2)'], 'E806:') 242 endif 243 call assert_fails('call str2nr(10, [])', 'E745:') 244endfunc 245 246func Test_strftime() 247 CheckFunction strftime 248 249 " Format of strftime() depends on system. We assume 250 " that basic formats tested here are available and 251 " identical on all systems which support strftime(). 252 " 253 " The 2nd parameter of strftime() is a local time, so the output day 254 " of strftime() can be 17 or 18, depending on timezone. 255 call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) 256 " 257 call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', '%Y-%m-%d %H:%M:%S'->strftime()) 258 259 call assert_fails('call strftime([])', 'E730:') 260 call assert_fails('call strftime("%Y", [])', 'E745:') 261 262 " Check that the time changes after we change the timezone 263 " Save previous timezone value, if any 264 if exists('$TZ') 265 let tz = $TZ 266 endif 267 268 " Force EST and then UTC, save the current hour (24-hour clock) for each 269 let $TZ = 'EST' | let est = strftime('%H') 270 let $TZ = 'UTC' | let utc = strftime('%H') 271 272 " Those hours should be two bytes long, and should not be the same; if they 273 " are, a tzset(3) call may have failed somewhere 274 call assert_equal(strlen(est), 2) 275 call assert_equal(strlen(utc), 2) 276 " TODO: this fails on MS-Windows 277 if has('unix') 278 call assert_notequal(est, utc) 279 endif 280 281 " If we cached a timezone value, put it back, otherwise clear it 282 if exists('tz') 283 let $TZ = tz 284 else 285 unlet $TZ 286 endif 287endfunc 288 289func Test_strptime() 290 CheckFunction strptime 291 292 if exists('$TZ') 293 let tz = $TZ 294 endif 295 let $TZ = 'UTC' 296 297 call assert_equal(1484653763, strptime('%Y-%m-%d %T', '2017-01-17 11:49:23')) 298 299 " Force DST and check that it's considered 300 let $TZ = 'WINTER0SUMMER,J1,J365' 301 call assert_equal(1484653763 - 3600, strptime('%Y-%m-%d %T', '2017-01-17 11:49:23')) 302 303 call assert_fails('call strptime()', 'E119:') 304 call assert_fails('call strptime("xxx")', 'E119:') 305 call assert_equal(0, strptime("%Y", '')) 306 call assert_equal(0, strptime("%Y", "xxx")) 307 308 if exists('tz') 309 let $TZ = tz 310 else 311 unlet $TZ 312 endif 313endfunc 314 315func Test_resolve_unix() 316 CheckUnix 317 318 " Xlink1 -> Xlink2 319 " Xlink2 -> Xlink3 320 silent !ln -s -f Xlink2 Xlink1 321 silent !ln -s -f Xlink3 Xlink2 322 call assert_equal('Xlink3', resolve('Xlink1')) 323 call assert_equal('./Xlink3', resolve('./Xlink1')) 324 call assert_equal('Xlink3/', resolve('Xlink2/')) 325 " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?! 326 "call assert_equal('Xlink3/', resolve('Xlink1/')) 327 "call assert_equal('./Xlink3/', resolve('./Xlink1/')) 328 "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/')) 329 call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1')) 330 331 " Test resolve() with a symlink cycle. 332 " Xlink1 -> Xlink2 333 " Xlink2 -> Xlink3 334 " Xlink3 -> Xlink1 335 silent !ln -s -f Xlink1 Xlink3 336 call assert_fails('call resolve("Xlink1")', 'E655:') 337 call assert_fails('call resolve("./Xlink1")', 'E655:') 338 call assert_fails('call resolve("Xlink2")', 'E655:') 339 call assert_fails('call resolve("Xlink3")', 'E655:') 340 call delete('Xlink1') 341 call delete('Xlink2') 342 call delete('Xlink3') 343 344 silent !ln -s -f Xdir//Xfile Xlink 345 call assert_equal('Xdir/Xfile', resolve('Xlink')) 346 call delete('Xlink') 347 348 silent !ln -s -f Xlink2/ Xlink1 349 call assert_equal('Xlink2', 'Xlink1'->resolve()) 350 call assert_equal('Xlink2/', resolve('Xlink1/')) 351 call delete('Xlink1') 352 353 silent !ln -s -f ./Xlink2 Xlink1 354 call assert_equal('Xlink2', resolve('Xlink1')) 355 call assert_equal('./Xlink2', resolve('./Xlink1')) 356 call delete('Xlink1') 357 358 call assert_equal('/', resolve('/')) 359endfunc 360 361func s:normalize_fname(fname) 362 let ret = substitute(a:fname, '\', '/', 'g') 363 let ret = substitute(ret, '//', '/', 'g') 364 return ret->tolower() 365endfunc 366 367func Test_resolve_win32() 368 CheckMSWindows 369 370 " test for shortcut file 371 if executable('cscript') 372 new Xfile 373 wq 374 let lines =<< trim END 375 Set fs = CreateObject("Scripting.FileSystemObject") 376 Set ws = WScript.CreateObject("WScript.Shell") 377 Set shortcut = ws.CreateShortcut("Xlink.lnk") 378 shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile") 379 shortcut.Save 380 END 381 call writefile(lines, 'link.vbs') 382 silent !cscript link.vbs 383 call delete('link.vbs') 384 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) 385 call delete('Xfile') 386 387 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) 388 call delete('Xlink.lnk') 389 else 390 echomsg 'skipped test for shortcut file' 391 endif 392 393 " remove files 394 call delete('Xlink') 395 call delete('Xdir', 'd') 396 call delete('Xfile') 397 398 " test for symbolic link to a file 399 new Xfile 400 wq 401 call assert_equal('Xfile', resolve('Xfile')) 402 silent !mklink Xlink Xfile 403 if !v:shell_error 404 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink'))) 405 call delete('Xlink') 406 else 407 echomsg 'skipped test for symbolic link to a file' 408 endif 409 call delete('Xfile') 410 411 " test for junction to a directory 412 call mkdir('Xdir') 413 silent !mklink /J Xlink Xdir 414 if !v:shell_error 415 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) 416 417 call delete('Xdir', 'd') 418 419 " test for junction already removed 420 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) 421 call delete('Xlink') 422 else 423 echomsg 'skipped test for junction to a directory' 424 call delete('Xdir', 'd') 425 endif 426 427 " test for symbolic link to a directory 428 call mkdir('Xdir') 429 silent !mklink /D Xlink Xdir 430 if !v:shell_error 431 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) 432 433 call delete('Xdir', 'd') 434 435 " test for symbolic link already removed 436 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) 437 call delete('Xlink') 438 else 439 echomsg 'skipped test for symbolic link to a directory' 440 call delete('Xdir', 'd') 441 endif 442 443 " test for buffer name 444 new Xfile 445 wq 446 silent !mklink Xlink Xfile 447 if !v:shell_error 448 edit Xlink 449 call assert_equal('Xlink', bufname('%')) 450 call delete('Xlink') 451 bw! 452 else 453 echomsg 'skipped test for buffer name' 454 endif 455 call delete('Xfile') 456 457 " test for reparse point 458 call mkdir('Xdir') 459 call assert_equal('Xdir', resolve('Xdir')) 460 silent !mklink /D Xdirlink Xdir 461 if !v:shell_error 462 w Xdir/text.txt 463 call assert_equal('Xdir/text.txt', resolve('Xdir/text.txt')) 464 call assert_equal(s:normalize_fname(getcwd() . '\Xdir\text.txt'), s:normalize_fname(resolve('Xdirlink\text.txt'))) 465 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve('Xdirlink'))) 466 call delete('Xdirlink') 467 else 468 echomsg 'skipped test for reparse point' 469 endif 470 471 call delete('Xdir', 'rf') 472endfunc 473 474func Test_simplify() 475 call assert_equal('', simplify('')) 476 call assert_equal('/', simplify('/')) 477 call assert_equal('/', simplify('/.')) 478 call assert_equal('/', simplify('/..')) 479 call assert_equal('/...', simplify('/...')) 480 call assert_equal('//path', simplify('//path')) 481 if has('unix') 482 call assert_equal('/path', simplify('///path')) 483 call assert_equal('/path', simplify('////path')) 484 endif 485 486 call assert_equal('./dir/file', './dir/file'->simplify()) 487 call assert_equal('./dir/file', simplify('.///dir//file')) 488 call assert_equal('./dir/file', simplify('./dir/./file')) 489 call assert_equal('./file', simplify('./dir/../file')) 490 call assert_equal('../dir/file', simplify('dir/../../dir/file')) 491 call assert_equal('./file', simplify('dir/.././file')) 492 call assert_equal('../dir', simplify('./../dir')) 493 call assert_equal('..', simplify('../testdir/..')) 494 call mkdir('Xdir') 495 call assert_equal('.', simplify('Xdir/../.')) 496 call delete('Xdir', 'd') 497 498 call assert_fails('call simplify({->0})', 'E729:') 499 call assert_fails('call simplify([])', 'E730:') 500 call assert_fails('call simplify({})', 'E731:') 501 if has('float') 502 call assert_equal('1.2', simplify(1.2)) 503 call CheckDefFailure(['echo simplify(1.2)'], 'E1013:') 504 call CheckScriptFailure(['vim9script', 'echo simplify(1.2)'], 'E806:') 505 endif 506endfunc 507 508func Test_pathshorten() 509 call assert_equal('', pathshorten('')) 510 call assert_equal('foo', pathshorten('foo')) 511 call assert_equal('/foo', '/foo'->pathshorten()) 512 call assert_equal('f/', pathshorten('foo/')) 513 call assert_equal('f/bar', pathshorten('foo/bar')) 514 call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten()) 515 call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) 516 call assert_equal('.f/bar', pathshorten('.foo/bar')) 517 call assert_equal('~f/bar', pathshorten('~foo/bar')) 518 call assert_equal('~.f/bar', pathshorten('~.foo/bar')) 519 call assert_equal('.~f/bar', pathshorten('.~foo/bar')) 520 call assert_equal('~/f/bar', pathshorten('~/foo/bar')) 521 call assert_fails('call pathshorten([])', 'E730:') 522 523 " test pathshorten with optional variable to set preferred size of shortening 524 call assert_equal('', pathshorten('', 2)) 525 call assert_equal('foo', pathshorten('foo', 2)) 526 call assert_equal('/foo', pathshorten('/foo', 2)) 527 call assert_equal('fo/', pathshorten('foo/', 2)) 528 call assert_equal('fo/bar', pathshorten('foo/bar', 2)) 529 call assert_equal('fo/ba/foobar', pathshorten('foo/bar/foobar', 2)) 530 call assert_equal('/fo/ba/foobar', pathshorten('/foo/bar/foobar', 2)) 531 call assert_equal('.fo/bar', pathshorten('.foo/bar', 2)) 532 call assert_equal('~fo/bar', pathshorten('~foo/bar', 2)) 533 call assert_equal('~.fo/bar', pathshorten('~.foo/bar', 2)) 534 call assert_equal('.~fo/bar', pathshorten('.~foo/bar', 2)) 535 call assert_equal('~/fo/bar', pathshorten('~/foo/bar', 2)) 536 call assert_fails('call pathshorten([],2)', 'E730:') 537 call assert_notequal('~/fo/bar', pathshorten('~/foo/bar', 3)) 538 call assert_equal('~/foo/bar', pathshorten('~/foo/bar', 3)) 539 call assert_equal('~/f/bar', pathshorten('~/foo/bar', 0)) 540endfunc 541 542func Test_strpart() 543 call assert_equal('de', strpart('abcdefg', 3, 2)) 544 call assert_equal('ab', strpart('abcdefg', -2, 4)) 545 call assert_equal('abcdefg', 'abcdefg'->strpart(-2)) 546 call assert_equal('fg', strpart('abcdefg', 5, 4)) 547 call assert_equal('defg', strpart('abcdefg', 3)) 548 call assert_equal('', strpart('abcdefg', 10)) 549 call assert_fails("let s=strpart('abcdef', [])", 'E745:') 550 551 call assert_equal('lép', strpart('éléphant', 2, 4)) 552 call assert_equal('léphant', strpart('éléphant', 2)) 553 554 call assert_equal('é', strpart('éléphant', 0, 1, 1)) 555 call assert_equal('ép', strpart('éléphant', 3, 2, v:true)) 556 call assert_equal('ó', strpart('cómposed', 1, 1, 1)) 557endfunc 558 559func Test_tolower() 560 call assert_equal("", tolower("")) 561 562 " Test with all printable ASCII characters. 563 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 564 \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) 565 566 " Test with a few uppercase diacritics. 567 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) 568 call assert_equal("bḃḇ", tolower("BḂḆ")) 569 call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) 570 call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) 571 call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) 572 call assert_equal("fḟ ", tolower("FḞ ")) 573 call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) 574 call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) 575 call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) 576 call assert_equal("jĵ", tolower("JĴ")) 577 call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) 578 call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) 579 call assert_equal("mḿṁ", tolower("MḾṀ")) 580 call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) 581 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) 582 call assert_equal("pṕṗ", tolower("PṔṖ")) 583 call assert_equal("q", tolower("Q")) 584 call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) 585 call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) 586 call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) 587 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) 588 call assert_equal("vṽ", tolower("VṼ")) 589 call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) 590 call assert_equal("xẋẍ", tolower("XẊẌ")) 591 call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) 592 call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) 593 594 " Test with a few lowercase diacritics, which should remain unchanged. 595 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) 596 call assert_equal("bḃḇ", tolower("bḃḇ")) 597 call assert_equal("cçćĉċč", tolower("cçćĉċč")) 598 call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) 599 call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) 600 call assert_equal("fḟ", tolower("fḟ")) 601 call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) 602 call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) 603 call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) 604 call assert_equal("jĵǰ", tolower("jĵǰ")) 605 call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) 606 call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) 607 call assert_equal("mḿṁ ", tolower("mḿṁ ")) 608 call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) 609 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) 610 call assert_equal("pṕṗ", tolower("pṕṗ")) 611 call assert_equal("q", tolower("q")) 612 call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) 613 call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) 614 call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) 615 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) 616 call assert_equal("vṽ", tolower("vṽ")) 617 call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) 618 call assert_equal("ẋẍ", tolower("ẋẍ")) 619 call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) 620 call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) 621 622 " According to https://twitter.com/jifa/status/625776454479970304 623 " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase 624 " in length (2 to 3 bytes) when lowercased. So let's test them. 625 call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) 626 627 " This call to tolower with invalid utf8 sequence used to cause access to 628 " invalid memory. 629 call tolower("\xC0\x80\xC0") 630 call tolower("123\xC0\x80\xC0") 631 632 " Test in latin1 encoding 633 let save_enc = &encoding 634 set encoding=latin1 635 call assert_equal("abc", tolower("ABC")) 636 let &encoding = save_enc 637endfunc 638 639func Test_toupper() 640 call assert_equal("", toupper("")) 641 642 " Test with all printable ASCII characters. 643 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', 644 \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) 645 646 " Test with a few lowercase diacritics. 647 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper()) 648 call assert_equal("BḂḆ", toupper("bḃḇ")) 649 call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) 650 call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) 651 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) 652 call assert_equal("FḞ", toupper("fḟ")) 653 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) 654 call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) 655 call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) 656 call assert_equal("JĴǰ", toupper("jĵǰ")) 657 call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) 658 call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) 659 call assert_equal("MḾṀ ", toupper("mḿṁ ")) 660 call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) 661 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) 662 call assert_equal("PṔṖ", toupper("pṕṗ")) 663 call assert_equal("Q", toupper("q")) 664 call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) 665 call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) 666 call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) 667 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) 668 call assert_equal("VṼ", toupper("vṽ")) 669 call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) 670 call assert_equal("ẊẌ", toupper("ẋẍ")) 671 call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) 672 call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) 673 674 " Test that uppercase diacritics, which should remain unchanged. 675 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) 676 call assert_equal("BḂḆ", toupper("BḂḆ")) 677 call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) 678 call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) 679 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) 680 call assert_equal("FḞ ", toupper("FḞ ")) 681 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) 682 call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) 683 call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) 684 call assert_equal("JĴ", toupper("JĴ")) 685 call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) 686 call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) 687 call assert_equal("MḾṀ", toupper("MḾṀ")) 688 call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) 689 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) 690 call assert_equal("PṔṖ", toupper("PṔṖ")) 691 call assert_equal("Q", toupper("Q")) 692 call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) 693 call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) 694 call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) 695 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) 696 call assert_equal("VṼ", toupper("VṼ")) 697 call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) 698 call assert_equal("XẊẌ", toupper("XẊẌ")) 699 call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) 700 call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) 701 702 call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) 703 704 " This call to toupper with invalid utf8 sequence used to cause access to 705 " invalid memory. 706 call toupper("\xC0\x80\xC0") 707 call toupper("123\xC0\x80\xC0") 708 709 " Test in latin1 encoding 710 let save_enc = &encoding 711 set encoding=latin1 712 call assert_equal("ABC", toupper("abc")) 713 let &encoding = save_enc 714endfunc 715 716func Test_tr() 717 call assert_equal('foo', tr('bar', 'bar', 'foo')) 718 call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) 719 call assert_fails("let s=tr([], 'abc', 'def')", 'E730:') 720 call assert_fails("let s=tr('abc', [], 'def')", 'E730:') 721 call assert_fails("let s=tr('abc', 'abc', [])", 'E730:') 722 call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') 723 set encoding=latin1 724 call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') 725 call assert_equal('hEllO', tr('hello', 'eo', 'EO')) 726 call assert_equal('hello', tr('hello', 'xy', 'ab')) 727 call assert_fails('call tr("abc", "123", "₁₂")', 'E475:') 728 set encoding=utf8 729endfunc 730 731" Tests for the mode() function 732let current_modes = '' 733func Save_mode() 734 let g:current_modes = mode(0) . '-' . mode(1) 735 return '' 736endfunc 737 738" Test for the mode() function 739func Test_mode() 740 new 741 call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) 742 743 " Only complete from the current buffer. 744 set complete=. 745 746 inoremap <F2> <C-R>=Save_mode()<CR> 747 748 normal! 3G 749 exe "normal i\<F2>\<Esc>" 750 call assert_equal('i-i', g:current_modes) 751 " i_CTRL-P: Multiple matches 752 exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u" 753 call assert_equal('i-ic', g:current_modes) 754 " i_CTRL-P: Single match 755 exe "normal iBro\<C-P>\<F2>\<Esc>u" 756 call assert_equal('i-ic', g:current_modes) 757 " i_CTRL-X 758 exe "normal iBa\<C-X>\<F2>\<Esc>u" 759 call assert_equal('i-ix', g:current_modes) 760 " i_CTRL-X CTRL-P: Multiple matches 761 exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u" 762 call assert_equal('i-ic', g:current_modes) 763 " i_CTRL-X CTRL-P: Single match 764 exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u" 765 call assert_equal('i-ic', g:current_modes) 766 " i_CTRL-X CTRL-P + CTRL-P: Single match 767 exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" 768 call assert_equal('i-ic', g:current_modes) 769 " i_CTRL-X CTRL-L: Multiple matches 770 exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u" 771 call assert_equal('i-ic', g:current_modes) 772 " i_CTRL-X CTRL-L: Single match 773 exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u" 774 call assert_equal('i-ic', g:current_modes) 775 " i_CTRL-P: No match 776 exe "normal iCom\<C-P>\<F2>\<Esc>u" 777 call assert_equal('i-ic', g:current_modes) 778 " i_CTRL-X CTRL-P: No match 779 exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u" 780 call assert_equal('i-ic', g:current_modes) 781 " i_CTRL-X CTRL-L: No match 782 exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u" 783 call assert_equal('i-ic', g:current_modes) 784 785 " R_CTRL-P: Multiple matches 786 exe "normal RBa\<C-P>\<F2>\<Esc>u" 787 call assert_equal('R-Rc', g:current_modes) 788 " R_CTRL-P: Single match 789 exe "normal RBro\<C-P>\<F2>\<Esc>u" 790 call assert_equal('R-Rc', g:current_modes) 791 " R_CTRL-X 792 exe "normal RBa\<C-X>\<F2>\<Esc>u" 793 call assert_equal('R-Rx', g:current_modes) 794 " R_CTRL-X CTRL-P: Multiple matches 795 exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u" 796 call assert_equal('R-Rc', g:current_modes) 797 " R_CTRL-X CTRL-P: Single match 798 exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u" 799 call assert_equal('R-Rc', g:current_modes) 800 " R_CTRL-X CTRL-P + CTRL-P: Single match 801 exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" 802 call assert_equal('R-Rc', g:current_modes) 803 " R_CTRL-X CTRL-L: Multiple matches 804 exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u" 805 call assert_equal('R-Rc', g:current_modes) 806 " R_CTRL-X CTRL-L: Single match 807 exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u" 808 call assert_equal('R-Rc', g:current_modes) 809 " R_CTRL-P: No match 810 exe "normal RCom\<C-P>\<F2>\<Esc>u" 811 call assert_equal('R-Rc', g:current_modes) 812 " R_CTRL-X CTRL-P: No match 813 exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u" 814 call assert_equal('R-Rc', g:current_modes) 815 " R_CTRL-X CTRL-L: No match 816 exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u" 817 call assert_equal('R-Rc', g:current_modes) 818 819 call assert_equal('n', 0->mode()) 820 call assert_equal('n', 1->mode()) 821 822 " i_CTRL-O 823 exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>" 824 call assert_equal("n-niI", g:current_modes) 825 826 " R_CTRL-O 827 exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>" 828 call assert_equal("n-niR", g:current_modes) 829 830 " gR_CTRL-O 831 exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>" 832 call assert_equal("n-niV", g:current_modes) 833 834 " How to test operator-pending mode? 835 836 call feedkeys("v", 'xt') 837 call assert_equal('v', mode()) 838 call assert_equal('v', mode(1)) 839 call feedkeys("\<Esc>V", 'xt') 840 call assert_equal('V', mode()) 841 call assert_equal('V', mode(1)) 842 call feedkeys("\<Esc>\<C-V>", 'xt') 843 call assert_equal("\<C-V>", mode()) 844 call assert_equal("\<C-V>", mode(1)) 845 call feedkeys("\<Esc>", 'xt') 846 847 call feedkeys("gh", 'xt') 848 call assert_equal('s', mode()) 849 call assert_equal('s', mode(1)) 850 call feedkeys("\<Esc>gH", 'xt') 851 call assert_equal('S', mode()) 852 call assert_equal('S', mode(1)) 853 call feedkeys("\<Esc>g\<C-H>", 'xt') 854 call assert_equal("\<C-S>", mode()) 855 call assert_equal("\<C-S>", mode(1)) 856 call feedkeys("\<Esc>", 'xt') 857 858 call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt') 859 call assert_equal('c-c', g:current_modes) 860 call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt') 861 call assert_equal('c-cv', g:current_modes) 862 call feedkeys("Qcall Save_mode()\<CR>vi\<CR>", 'xt') 863 call assert_equal('c-ce', g:current_modes) 864 " How to test Ex mode? 865 866 bwipe! 867 iunmap <F2> 868 set complete& 869endfunc 870 871" Test for append() 872func Test_append() 873 enew! 874 split 875 call append(0, ["foo"]) 876 call append(1, []) 877 call append(1, test_null_list()) 878 call assert_equal(['foo', ''], getline(1, '$')) 879 split 880 only 881 undo 882 undo 883 884 " Using $ instead of '$' must give an error 885 call assert_fails("call append($, 'foobar')", 'E116:') 886endfunc 887 888" Test for setline() 889func Test_setline() 890 new 891 call setline(0, ["foo"]) 892 call setline(0, []) 893 call setline(0, test_null_list()) 894 call setline(1, ["bar"]) 895 call setline(1, []) 896 call setline(1, test_null_list()) 897 call setline(2, []) 898 call setline(2, test_null_list()) 899 call setline(3, []) 900 call setline(3, test_null_list()) 901 call setline(2, ["baz"]) 902 call assert_equal(['bar', 'baz'], getline(1, '$')) 903 close! 904endfunc 905 906func Test_getbufvar() 907 let bnr = bufnr('%') 908 let b:var_num = '1234' 909 let def_num = '5678' 910 call assert_equal('1234', getbufvar(bnr, 'var_num')) 911 call assert_equal('1234', getbufvar(bnr, 'var_num', def_num)) 912 913 let bd = getbufvar(bnr, '') 914 call assert_equal('1234', bd['var_num']) 915 call assert_true(exists("bd['changedtick']")) 916 call assert_equal(2, len(bd)) 917 918 let bd2 = getbufvar(bnr, '', def_num) 919 call assert_equal(bd, bd2) 920 921 unlet b:var_num 922 call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num)) 923 call assert_equal('', getbufvar(bnr, 'var_num')) 924 925 let bd = getbufvar(bnr, '') 926 call assert_equal(1, len(bd)) 927 let bd = getbufvar(bnr, '',def_num) 928 call assert_equal(1, len(bd)) 929 930 call assert_equal('', getbufvar(9999, '')) 931 call assert_equal(def_num, getbufvar(9999, '', def_num)) 932 unlet def_num 933 934 call assert_equal(0, getbufvar(bnr, '&autoindent')) 935 call assert_equal(0, getbufvar(bnr, '&autoindent', 1)) 936 937 " Set and get a buffer-local variable 938 call setbufvar(bnr, 'bufvar_test', ['one', 'two']) 939 call assert_equal(['one', 'two'], getbufvar(bnr, 'bufvar_test')) 940 941 " Open new window with forced option values 942 set fileformats=unix,dos 943 new ++ff=dos ++bin ++enc=iso-8859-2 944 call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat')) 945 call assert_equal(1, getbufvar(bufnr('%'), '&bin')) 946 call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc')) 947 close 948 949 " Get the b: dict. 950 let b:testvar = 'one' 951 new 952 let b:testvar = 'two' 953 let thebuf = bufnr() 954 wincmd w 955 call assert_equal('two', getbufvar(thebuf, 'testvar')) 956 call assert_equal('two', getbufvar(thebuf, '').testvar) 957 bwipe! 958 959 set fileformats& 960endfunc 961 962func Test_last_buffer_nr() 963 call assert_equal(bufnr('$'), last_buffer_nr()) 964endfunc 965 966func Test_stridx() 967 call assert_equal(-1, stridx('', 'l')) 968 call assert_equal(0, stridx('', '')) 969 call assert_equal(0, 'hello'->stridx('')) 970 call assert_equal(-1, stridx('hello', 'L')) 971 call assert_equal(2, stridx('hello', 'l', -1)) 972 call assert_equal(2, stridx('hello', 'l', 0)) 973 call assert_equal(2, 'hello'->stridx('l', 1)) 974 call assert_equal(3, stridx('hello', 'l', 3)) 975 call assert_equal(-1, stridx('hello', 'l', 4)) 976 call assert_equal(-1, stridx('hello', 'l', 10)) 977 call assert_equal(2, stridx('hello', 'll')) 978 call assert_equal(-1, stridx('hello', 'hello world')) 979 call assert_fails("let n=stridx('hello', [])", 'E730:') 980 call assert_fails("let n=stridx([], 'l')", 'E730:') 981endfunc 982 983func Test_strridx() 984 call assert_equal(-1, strridx('', 'l')) 985 call assert_equal(0, strridx('', '')) 986 call assert_equal(5, strridx('hello', '')) 987 call assert_equal(-1, strridx('hello', 'L')) 988 call assert_equal(3, 'hello'->strridx('l')) 989 call assert_equal(3, strridx('hello', 'l', 10)) 990 call assert_equal(3, strridx('hello', 'l', 3)) 991 call assert_equal(2, strridx('hello', 'l', 2)) 992 call assert_equal(-1, strridx('hello', 'l', 1)) 993 call assert_equal(-1, strridx('hello', 'l', 0)) 994 call assert_equal(-1, strridx('hello', 'l', -1)) 995 call assert_equal(2, strridx('hello', 'll')) 996 call assert_equal(-1, strridx('hello', 'hello world')) 997 call assert_fails("let n=strridx('hello', [])", 'E730:') 998 call assert_fails("let n=strridx([], 'l')", 'E730:') 999endfunc 1000 1001func Test_match_func() 1002 call assert_equal(4, match('testing', 'ing')) 1003 call assert_equal(4, 'testing'->match('ing', 2)) 1004 call assert_equal(-1, match('testing', 'ing', 5)) 1005 call assert_equal(-1, match('testing', 'ing', 8)) 1006 call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) 1007 call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) 1008 call assert_fails("let x=match('vim', [])", 'E730:') 1009 call assert_equal(3, match(['a', 'b', 'c', 'a'], 'a', 1)) 1010 call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) 1011 call assert_equal(4, match('testing', 'ing', -1)) 1012 call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') 1013 call assert_equal(-1, match(test_null_list(), 2)) 1014 call assert_equal(-1, match('abc', '\\%(')) 1015endfunc 1016 1017func Test_matchend() 1018 call assert_equal(7, matchend('testing', 'ing')) 1019 call assert_equal(7, 'testing'->matchend('ing', 2)) 1020 call assert_equal(-1, matchend('testing', 'ing', 5)) 1021 call assert_equal(-1, matchend('testing', 'ing', 8)) 1022 call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) 1023 call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img')) 1024endfunc 1025 1026func Test_matchlist() 1027 call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) 1028 call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) 1029 call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) 1030endfunc 1031 1032func Test_matchstr() 1033 call assert_equal('ing', matchstr('testing', 'ing')) 1034 call assert_equal('ing', 'testing'->matchstr('ing', 2)) 1035 call assert_equal('', matchstr('testing', 'ing', 5)) 1036 call assert_equal('', matchstr('testing', 'ing', 8)) 1037 call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) 1038 call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img')) 1039endfunc 1040 1041func Test_matchstrpos() 1042 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) 1043 call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2)) 1044 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) 1045 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) 1046 call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) 1047 call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) 1048 call assert_equal(['', -1, -1], matchstrpos(test_null_list(), '\a')) 1049endfunc 1050 1051func Test_nextnonblank_prevnonblank() 1052 new 1053insert 1054This 1055 1056 1057is 1058 1059a 1060Test 1061. 1062 call assert_equal(0, nextnonblank(-1)) 1063 call assert_equal(0, nextnonblank(0)) 1064 call assert_equal(1, nextnonblank(1)) 1065 call assert_equal(4, 2->nextnonblank()) 1066 call assert_equal(4, nextnonblank(3)) 1067 call assert_equal(4, nextnonblank(4)) 1068 call assert_equal(6, nextnonblank(5)) 1069 call assert_equal(6, nextnonblank(6)) 1070 call assert_equal(7, nextnonblank(7)) 1071 call assert_equal(0, 8->nextnonblank()) 1072 1073 call assert_equal(0, prevnonblank(-1)) 1074 call assert_equal(0, prevnonblank(0)) 1075 call assert_equal(1, 1->prevnonblank()) 1076 call assert_equal(1, prevnonblank(2)) 1077 call assert_equal(1, prevnonblank(3)) 1078 call assert_equal(4, prevnonblank(4)) 1079 call assert_equal(4, 5->prevnonblank()) 1080 call assert_equal(6, prevnonblank(6)) 1081 call assert_equal(7, prevnonblank(7)) 1082 call assert_equal(0, prevnonblank(8)) 1083 bw! 1084endfunc 1085 1086func Test_byte2line_line2byte() 1087 new 1088 set endofline 1089 call setline(1, ['a', 'bc', 'd']) 1090 1091 set fileformat=unix 1092 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], 1093 \ map(range(-1, 8), 'byte2line(v:val)')) 1094 call assert_equal([-1, -1, 1, 3, 6, 8, -1], 1095 \ map(range(-1, 5), 'line2byte(v:val)')) 1096 1097 set fileformat=mac 1098 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], 1099 \ map(range(-1, 8), 'v:val->byte2line()')) 1100 call assert_equal([-1, -1, 1, 3, 6, 8, -1], 1101 \ map(range(-1, 5), 'v:val->line2byte()')) 1102 1103 set fileformat=dos 1104 call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], 1105 \ map(range(-1, 11), 'byte2line(v:val)')) 1106 call assert_equal([-1, -1, 1, 4, 8, 11, -1], 1107 \ map(range(-1, 5), 'line2byte(v:val)')) 1108 1109 bw! 1110 set noendofline nofixendofline 1111 normal a- 1112 for ff in ["unix", "mac", "dos"] 1113 let &fileformat = ff 1114 call assert_equal(1, line2byte(1)) 1115 call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). 1116 endfor 1117 1118 set endofline& fixendofline& fileformat& 1119 bw! 1120endfunc 1121 1122" Test for byteidx() and byteidxcomp() functions 1123func Test_byteidx() 1124 let a = '.é.' " one char of two bytes 1125 call assert_equal(0, byteidx(a, 0)) 1126 call assert_equal(0, byteidxcomp(a, 0)) 1127 call assert_equal(1, byteidx(a, 1)) 1128 call assert_equal(1, byteidxcomp(a, 1)) 1129 call assert_equal(3, byteidx(a, 2)) 1130 call assert_equal(3, byteidxcomp(a, 2)) 1131 call assert_equal(4, byteidx(a, 3)) 1132 call assert_equal(4, byteidxcomp(a, 3)) 1133 call assert_equal(-1, byteidx(a, 4)) 1134 call assert_equal(-1, byteidxcomp(a, 4)) 1135 1136 let b = '.é.' " normal e with composing char 1137 call assert_equal(0, b->byteidx(0)) 1138 call assert_equal(1, b->byteidx(1)) 1139 call assert_equal(4, b->byteidx(2)) 1140 call assert_equal(5, b->byteidx(3)) 1141 call assert_equal(-1, b->byteidx(4)) 1142 call assert_fails("call byteidx([], 0)", 'E730:') 1143 1144 call assert_equal(0, b->byteidxcomp(0)) 1145 call assert_equal(1, b->byteidxcomp(1)) 1146 call assert_equal(2, b->byteidxcomp(2)) 1147 call assert_equal(4, b->byteidxcomp(3)) 1148 call assert_equal(5, b->byteidxcomp(4)) 1149 call assert_equal(-1, b->byteidxcomp(5)) 1150 call assert_fails("call byteidxcomp([], 0)", 'E730:') 1151endfunc 1152 1153" Test for charidx() 1154func Test_charidx() 1155 let a = 'xáb́y' 1156 call assert_equal(0, charidx(a, 0)) 1157 call assert_equal(1, charidx(a, 3)) 1158 call assert_equal(2, charidx(a, 4)) 1159 call assert_equal(3, charidx(a, 7)) 1160 call assert_equal(-1, charidx(a, 8)) 1161 call assert_equal(-1, charidx(a, -1)) 1162 call assert_equal(-1, charidx('', 0)) 1163 call assert_equal(-1, charidx(test_null_string(), 0)) 1164 1165 " count composing characters 1166 call assert_equal(0, charidx(a, 0, 1)) 1167 call assert_equal(2, charidx(a, 2, 1)) 1168 call assert_equal(3, charidx(a, 4, 1)) 1169 call assert_equal(5, charidx(a, 7, 1)) 1170 call assert_equal(-1, charidx(a, 8, 1)) 1171 call assert_equal(-1, charidx('', 0, 1)) 1172 1173 call assert_fails('let x = charidx([], 1)', 'E474:') 1174 call assert_fails('let x = charidx("abc", [])', 'E474:') 1175 call assert_fails('let x = charidx("abc", 1, [])', 'E474:') 1176 call assert_fails('let x = charidx("abc", 1, -1)', 'E1023:') 1177 call assert_fails('let x = charidx("abc", 1, 2)', 'E1023:') 1178endfunc 1179 1180func Test_count() 1181 let l = ['a', 'a', 'A', 'b'] 1182 call assert_equal(2, count(l, 'a')) 1183 call assert_equal(1, count(l, 'A')) 1184 call assert_equal(1, count(l, 'b')) 1185 call assert_equal(0, count(l, 'B')) 1186 1187 call assert_equal(2, count(l, 'a', 0)) 1188 call assert_equal(1, count(l, 'A', 0)) 1189 call assert_equal(1, count(l, 'b', 0)) 1190 call assert_equal(0, count(l, 'B', 0)) 1191 1192 call assert_equal(3, count(l, 'a', 1)) 1193 call assert_equal(3, count(l, 'A', 1)) 1194 call assert_equal(1, count(l, 'b', 1)) 1195 call assert_equal(1, count(l, 'B', 1)) 1196 call assert_equal(0, count(l, 'c', 1)) 1197 1198 call assert_equal(1, count(l, 'a', 0, 1)) 1199 call assert_equal(2, count(l, 'a', 1, 1)) 1200 call assert_fails('call count(l, "a", 0, 10)', 'E684:') 1201 call assert_fails('call count(l, "a", [])', 'E745:') 1202 1203 let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} 1204 call assert_equal(2, count(d, 'a')) 1205 call assert_equal(1, count(d, 'A')) 1206 call assert_equal(1, count(d, 'b')) 1207 call assert_equal(0, count(d, 'B')) 1208 1209 call assert_equal(2, count(d, 'a', 0)) 1210 call assert_equal(1, count(d, 'A', 0)) 1211 call assert_equal(1, count(d, 'b', 0)) 1212 call assert_equal(0, count(d, 'B', 0)) 1213 1214 call assert_equal(3, count(d, 'a', 1)) 1215 call assert_equal(3, count(d, 'A', 1)) 1216 call assert_equal(1, count(d, 'b', 1)) 1217 call assert_equal(1, count(d, 'B', 1)) 1218 call assert_equal(0, count(d, 'c', 1)) 1219 1220 call assert_fails('call count(d, "a", 0, 1)', 'E474:') 1221 1222 call assert_equal(0, count("foo", "bar")) 1223 call assert_equal(1, count("foo", "oo")) 1224 call assert_equal(2, count("foo", "o")) 1225 call assert_equal(0, count("foo", "O")) 1226 call assert_equal(2, count("foo", "O", 1)) 1227 call assert_equal(2, count("fooooo", "oo")) 1228 call assert_equal(0, count("foo", "")) 1229 1230 call assert_fails('call count(0, 0)', 'E712:') 1231endfunc 1232 1233func Test_changenr() 1234 new Xchangenr 1235 call assert_equal(0, changenr()) 1236 norm ifoo 1237 call assert_equal(1, changenr()) 1238 set undolevels=10 1239 norm Sbar 1240 call assert_equal(2, changenr()) 1241 undo 1242 call assert_equal(1, changenr()) 1243 redo 1244 call assert_equal(2, changenr()) 1245 bw! 1246 set undolevels& 1247endfunc 1248 1249func Test_filewritable() 1250 new Xfilewritable 1251 write! 1252 call assert_equal(1, filewritable('Xfilewritable')) 1253 1254 call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----')) 1255 call assert_equal(0, filewritable('Xfilewritable')) 1256 1257 call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) 1258 call assert_equal(1, 'Xfilewritable'->filewritable()) 1259 1260 call assert_equal(0, filewritable('doesnotexist')) 1261 1262 call mkdir('Xdir') 1263 call assert_equal(2, filewritable('Xdir')) 1264 call delete('Xdir', 'd') 1265 1266 call delete('Xfilewritable') 1267 bw! 1268endfunc 1269 1270func Test_Executable() 1271 if has('win32') 1272 call assert_equal(1, executable('notepad')) 1273 call assert_equal(1, 'notepad.exe'->executable()) 1274 call assert_equal(0, executable('notepad.exe.exe')) 1275 call assert_equal(0, executable('shell32.dll')) 1276 call assert_equal(0, executable('win.ini')) 1277 1278 " get "notepad" path and remove the leading drive and sep. (ex. 'C:\') 1279 let notepadcmd = exepath('notepad.exe') 1280 let driveroot = notepadcmd[:2] 1281 let notepadcmd = notepadcmd[3:] 1282 new 1283 " check that the relative path works in / 1284 execute 'lcd' driveroot 1285 call assert_equal(1, executable(notepadcmd)) 1286 call assert_equal(driveroot .. notepadcmd, notepadcmd->exepath()) 1287 bwipe 1288 1289 " create "notepad.bat" 1290 call mkdir('Xdir') 1291 let notepadbat = fnamemodify('Xdir/notepad.bat', ':p') 1292 call writefile([], notepadbat) 1293 new 1294 " check that the path and the pathext order is valid 1295 lcd Xdir 1296 let [pathext, $PATHEXT] = [$PATHEXT, '.com;.exe;.bat;.cmd'] 1297 call assert_equal(notepadbat, exepath('notepad')) 1298 let $PATHEXT = pathext 1299 bwipe 1300 eval 'Xdir'->delete('rf') 1301 elseif has('unix') 1302 call assert_equal(1, 'cat'->executable()) 1303 call assert_equal(0, executable('nodogshere')) 1304 1305 " get "cat" path and remove the leading / 1306 let catcmd = exepath('cat')[1:] 1307 new 1308 " check that the relative path works in / 1309 lcd / 1310 call assert_equal(1, executable(catcmd)) 1311 let result = catcmd->exepath() 1312 " when using chroot looking for sbin/cat can return bin/cat, that is OK 1313 if catcmd =~ '\<sbin\>' && result =~ '\<bin\>' 1314 call assert_equal('/' .. substitute(catcmd, '\<sbin\>', 'bin', ''), result) 1315 else 1316 call assert_equal('/' .. catcmd, result) 1317 endif 1318 bwipe 1319 else 1320 throw 'Skipped: does not work on this platform' 1321 endif 1322endfunc 1323 1324func Test_executable_longname() 1325 CheckMSWindows 1326 1327 " Create a temporary .bat file with 205 characters in the name. 1328 " Maximum length of a filename (including the path) on MS-Windows is 259 1329 " characters. 1330 " See https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation 1331 let len = 259 - getcwd()->len() - 6 1332 if len > 200 1333 let len = 200 1334 endif 1335 1336 let fname = 'X' . repeat('あ', len) . '.bat' 1337 call writefile([], fname) 1338 call assert_equal(1, executable(fname)) 1339 call delete(fname) 1340endfunc 1341 1342func Test_hostname() 1343 let hostname_vim = hostname() 1344 if has('unix') 1345 let hostname_system = systemlist('uname -n')[0] 1346 call assert_equal(hostname_vim, hostname_system) 1347 endif 1348endfunc 1349 1350func Test_getpid() 1351 " getpid() always returns the same value within a vim instance. 1352 call assert_equal(getpid(), getpid()) 1353 if has('unix') 1354 call assert_equal(systemlist('echo $PPID')[0], string(getpid())) 1355 endif 1356endfunc 1357 1358func Test_hlexists() 1359 call assert_equal(0, hlexists('does_not_exist')) 1360 call assert_equal(0, 'Number'->hlexists()) 1361 call assert_equal(0, highlight_exists('does_not_exist')) 1362 call assert_equal(0, highlight_exists('Number')) 1363 syntax on 1364 call assert_equal(0, hlexists('does_not_exist')) 1365 call assert_equal(1, hlexists('Number')) 1366 call assert_equal(0, highlight_exists('does_not_exist')) 1367 call assert_equal(1, highlight_exists('Number')) 1368 syntax off 1369endfunc 1370 1371" Test for the col() function 1372func Test_col() 1373 new 1374 call setline(1, 'abcdef') 1375 norm gg4|mx6|mY2| 1376 call assert_equal(2, col('.')) 1377 call assert_equal(7, col('$')) 1378 call assert_equal(2, col('v')) 1379 call assert_equal(4, col("'x")) 1380 call assert_equal(6, col("'Y")) 1381 call assert_equal(2, [1, 2]->col()) 1382 call assert_equal(7, col([1, '$'])) 1383 1384 call assert_equal(0, col('')) 1385 call assert_equal(0, col('x')) 1386 call assert_equal(0, col([2, '$'])) 1387 call assert_equal(0, col([1, 100])) 1388 call assert_equal(0, col([1])) 1389 call assert_equal(0, col(test_null_list())) 1390 call assert_fails('let c = col({})', 'E731:') 1391 1392 " test for getting the visual start column 1393 func T() 1394 let g:Vcol = col('v') 1395 return '' 1396 endfunc 1397 let g:Vcol = 0 1398 xmap <expr> <F2> T() 1399 exe "normal gg3|ve\<F2>" 1400 call assert_equal(3, g:Vcol) 1401 xunmap <F2> 1402 delfunc T 1403 1404 " Test for the visual line start and end marks '< and '> 1405 call setline(1, ['one', 'one two', 'one two three']) 1406 "normal! ggVG 1407 call feedkeys("ggVG\<Esc>", 'xt') 1408 call assert_equal(1, col("'<")) 1409 call assert_equal(14, col("'>")) 1410 " Delete the last line of the visually selected region 1411 $d 1412 call assert_notequal(14, col("'>")) 1413 1414 " Test with 'virtualedit' 1415 set virtualedit=all 1416 call cursor(1, 10) 1417 call assert_equal(4, col('.')) 1418 set virtualedit& 1419 1420 bw! 1421endfunc 1422 1423" Test for input() 1424func Test_input_func() 1425 " Test for prompt with multiple lines 1426 redir => v 1427 call feedkeys(":let c = input(\"A\\nB\\nC\\n? \")\<CR>B\<CR>", 'xt') 1428 redir END 1429 call assert_equal("B", c) 1430 call assert_equal(['A', 'B', 'C'], split(v, "\n")) 1431 1432 " Test for default value 1433 call feedkeys(":let c = input('color? ', 'red')\<CR>\<CR>", 'xt') 1434 call assert_equal('red', c) 1435 1436 " Test for completion at the input prompt 1437 func! Tcomplete(arglead, cmdline, pos) 1438 return "item1\nitem2\nitem3" 1439 endfunc 1440 call feedkeys(":let c = input('Q? ', '', 'custom,Tcomplete')\<CR>" 1441 \ .. "\<C-A>\<CR>", 'xt') 1442 delfunc Tcomplete 1443 call assert_equal('item1 item2 item3', c) 1444 1445 " Test for using special characters as default input 1446 call feedkeys(":let c = input('name? ', \"x\\<BS>y\")\<CR>\<CR>", 'xt') 1447 call assert_equal('y', c) 1448 1449 " Test for using <CR> as default input 1450 call feedkeys(":let c = input('name? ', \"\\<CR>\")\<CR>x\<CR>", 'xt') 1451 call assert_equal(' x', c) 1452 1453 call assert_fails("call input('F:', '', 'invalid')", 'E180:') 1454 call assert_fails("call input('F:', '', [])", 'E730:') 1455endfunc 1456 1457" Test for the inputdialog() function 1458func Test_inputdialog() 1459 set timeout timeoutlen=10 1460 if has('gui_running') 1461 call assert_fails('let v=inputdialog([], "xx")', 'E730:') 1462 call assert_fails('let v=inputdialog("Q", [])', 'E730:') 1463 else 1464 call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt') 1465 call assert_equal('xx', v) 1466 call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt') 1467 call assert_equal('yy', v) 1468 endif 1469 set timeout& timeoutlen& 1470endfunc 1471 1472" Test for inputlist() 1473func Test_inputlist() 1474 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') 1475 call assert_equal(1, c) 1476 call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx') 1477 call assert_equal(2, c) 1478 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') 1479 call assert_equal(3, c) 1480 1481 " CR to cancel 1482 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<cr>", 'tx') 1483 call assert_equal(0, c) 1484 1485 " Esc to cancel 1486 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<Esc>", 'tx') 1487 call assert_equal(0, c) 1488 1489 " q to cancel 1490 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>q", 'tx') 1491 call assert_equal(0, c) 1492 1493 " Cancel after inputting a number 1494 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>5q", 'tx') 1495 call assert_equal(0, c) 1496 1497 " Use backspace to delete characters in the prompt 1498 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<BS>3\<BS>2\<cr>", 'tx') 1499 call assert_equal(2, c) 1500 1501 " Use mouse to make a selection 1502 call test_setmouse(&lines - 3, 2) 1503 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx') 1504 call assert_equal(1, c) 1505 " Mouse click outside of the list 1506 call test_setmouse(&lines - 6, 2) 1507 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx') 1508 call assert_equal(-2, c) 1509 1510 call assert_fails('call inputlist("")', 'E686:') 1511 call assert_fails('call inputlist(test_null_list())', 'E686:') 1512endfunc 1513 1514func Test_balloon_show() 1515 CheckFeature balloon_eval 1516 1517 " This won't do anything but must not crash either. 1518 call balloon_show('hi!') 1519 if !has('gui_running') 1520 call balloon_show(range(3)) 1521 call balloon_show([]) 1522 endif 1523endfunc 1524 1525func Test_setbufvar_options() 1526 " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the 1527 " window layout. 1528 call assert_equal(1, winnr('$')) 1529 split dummy_preview 1530 resize 2 1531 set winfixheight winfixwidth 1532 let prev_id = win_getid() 1533 1534 wincmd j 1535 let wh = winheight(0) 1536 let dummy_buf = bufnr('dummy_buf1', v:true) 1537 call setbufvar(dummy_buf, '&buftype', 'nofile') 1538 execute 'belowright vertical split #' . dummy_buf 1539 call assert_equal(wh, winheight(0)) 1540 let dum1_id = win_getid() 1541 1542 wincmd h 1543 let wh = winheight(0) 1544 let dummy_buf = bufnr('dummy_buf2', v:true) 1545 eval 'nofile'->setbufvar(dummy_buf, '&buftype') 1546 execute 'belowright vertical split #' . dummy_buf 1547 call assert_equal(wh, winheight(0)) 1548 1549 bwipe! 1550 call win_gotoid(prev_id) 1551 bwipe! 1552 call win_gotoid(dum1_id) 1553 bwipe! 1554endfunc 1555 1556func Test_redo_in_nested_functions() 1557 nnoremap g. :set opfunc=Operator<CR>g@ 1558 function Operator( type, ... ) 1559 let @x = 'XXX' 1560 execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp' 1561 endfunction 1562 1563 function! Apply() 1564 5,6normal! . 1565 endfunction 1566 1567 new 1568 call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3)) 1569 1normal g.i" 1570 call assert_equal('some "XXX" text', getline(1)) 1571 3,4normal . 1572 call assert_equal('some "XXX" text', getline(3)) 1573 call assert_equal('more "XXX" text', getline(4)) 1574 call Apply() 1575 call assert_equal('some "XXX" text', getline(5)) 1576 call assert_equal('more "XXX" text', getline(6)) 1577 bwipe! 1578 1579 nunmap g. 1580 delfunc Operator 1581 delfunc Apply 1582endfunc 1583 1584func Test_trim() 1585 call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) 1586 call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim()) 1587 call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) 1588 call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) 1589 call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) 1590 call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " ")) 1591 call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) 1592 call assert_equal("RESERVE", trim("你RESERVE好", "你好")) 1593 call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) 1594 call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) 1595 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) 1596 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) 1597 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) 1598 call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要")) 1599 call assert_equal("", trim("", "")) 1600 call assert_equal("a", trim("a", "")) 1601 call assert_equal("", trim("", "a")) 1602 1603 call assert_equal("vim", trim(" vim ", " ", 0)) 1604 call assert_equal("vim ", trim(" vim ", " ", 1)) 1605 call assert_equal(" vim", trim(" vim ", " ", 2)) 1606 call assert_fails('eval trim(" vim ", " ", [])', 'E745:') 1607 call assert_fails('eval trim(" vim ", " ", -1)', 'E475:') 1608 call assert_fails('eval trim(" vim ", " ", 3)', 'E475:') 1609 1610 let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '') 1611 call assert_equal("x", trim(chars . "x" . chars)) 1612 1613 call assert_fails('let c=trim([])', 'E730:') 1614endfunc 1615 1616" Test for reg_recording() and reg_executing() 1617func Test_reg_executing_and_recording() 1618 let s:reg_stat = '' 1619 func s:save_reg_stat() 1620 let s:reg_stat = reg_recording() . ':' . reg_executing() 1621 return '' 1622 endfunc 1623 1624 new 1625 call s:save_reg_stat() 1626 call assert_equal(':', s:reg_stat) 1627 call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt') 1628 call assert_equal('a:', s:reg_stat) 1629 call feedkeys("@a", 'xt') 1630 call assert_equal(':a', s:reg_stat) 1631 call feedkeys("qb@aq", 'xt') 1632 call assert_equal('b:a', s:reg_stat) 1633 call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt') 1634 call assert_equal('":', s:reg_stat) 1635 1636 " :normal command saves and restores reg_executing 1637 let s:reg_stat = '' 1638 let @q = ":call TestFunc()\<CR>:call s:save_reg_stat()\<CR>" 1639 func TestFunc() abort 1640 normal! ia 1641 endfunc 1642 call feedkeys("@q", 'xt') 1643 call assert_equal(':q', s:reg_stat) 1644 delfunc TestFunc 1645 1646 " getchar() command saves and restores reg_executing 1647 map W :call TestFunc()<CR> 1648 let @q = "W" 1649 let g:typed = '' 1650 let g:regs = [] 1651 func TestFunc() abort 1652 let g:regs += [reg_executing()] 1653 let g:typed = getchar(0) 1654 let g:regs += [reg_executing()] 1655 endfunc 1656 call feedkeys("@qy", 'xt') 1657 call assert_equal(char2nr("y"), g:typed) 1658 call assert_equal(['q', 'q'], g:regs) 1659 delfunc TestFunc 1660 unmap W 1661 unlet g:typed 1662 unlet g:regs 1663 1664 " input() command saves and restores reg_executing 1665 map W :call TestFunc()<CR> 1666 let @q = "W" 1667 let g:typed = '' 1668 let g:regs = [] 1669 func TestFunc() abort 1670 let g:regs += [reg_executing()] 1671 let g:typed = '?'->input() 1672 let g:regs += [reg_executing()] 1673 endfunc 1674 call feedkeys("@qy\<CR>", 'xt') 1675 call assert_equal("y", g:typed) 1676 call assert_equal(['q', 'q'], g:regs) 1677 delfunc TestFunc 1678 unmap W 1679 unlet g:typed 1680 unlet g:regs 1681 1682 bwipe! 1683 delfunc s:save_reg_stat 1684 unlet s:reg_stat 1685endfunc 1686 1687func Test_inputsecret() 1688 map W :call TestFunc()<CR> 1689 let @q = "W" 1690 let g:typed1 = '' 1691 let g:typed2 = '' 1692 let g:regs = [] 1693 func TestFunc() abort 1694 let g:typed1 = '?'->inputsecret() 1695 let g:typed2 = inputsecret('password: ') 1696 endfunc 1697 call feedkeys("@qsomething\<CR>else\<CR>", 'xt') 1698 call assert_equal("something", g:typed1) 1699 call assert_equal("else", g:typed2) 1700 delfunc TestFunc 1701 unmap W 1702 unlet g:typed1 1703 unlet g:typed2 1704endfunc 1705 1706func Test_getchar() 1707 call feedkeys('a', '') 1708 call assert_equal(char2nr('a'), getchar()) 1709 call assert_equal(0, getchar(0)) 1710 call assert_equal(0, getchar(1)) 1711 1712 call feedkeys('a', '') 1713 call assert_equal('a', getcharstr()) 1714 call assert_equal('', getcharstr(0)) 1715 call assert_equal('', getcharstr(1)) 1716 1717 call setline(1, 'xxxx') 1718 call test_setmouse(1, 3) 1719 let v:mouse_win = 9 1720 let v:mouse_winid = 9 1721 let v:mouse_lnum = 9 1722 let v:mouse_col = 9 1723 call feedkeys("\<S-LeftMouse>", '') 1724 call assert_equal("\<S-LeftMouse>", getchar()) 1725 call assert_equal(1, v:mouse_win) 1726 call assert_equal(win_getid(1), v:mouse_winid) 1727 call assert_equal(1, v:mouse_lnum) 1728 call assert_equal(3, v:mouse_col) 1729 enew! 1730endfunc 1731 1732func Test_libcall_libcallnr() 1733 CheckFeature libcall 1734 1735 if has('win32') 1736 let libc = 'msvcrt.dll' 1737 elseif has('mac') 1738 let libc = 'libSystem.B.dylib' 1739 elseif executable('ldd') 1740 let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>') 1741 endif 1742 if get(l:, 'libc', '') ==# '' 1743 " On Unix, libc.so can be in various places. 1744 if has('linux') 1745 " There is not documented but regarding the 1st argument of glibc's 1746 " dlopen an empty string and nullptr are equivalent, so using an empty 1747 " string for the 1st argument of libcall allows to call functions. 1748 let libc = '' 1749 elseif has('sun') 1750 " Set the path to libc.so according to the architecture. 1751 let test_bits = system('file ' . GetVimProg()) 1752 let test_arch = system('uname -p') 1753 if test_bits =~ '64-bit' && test_arch =~ 'sparc' 1754 let libc = '/usr/lib/sparcv9/libc.so' 1755 elseif test_bits =~ '64-bit' && test_arch =~ 'i386' 1756 let libc = '/usr/lib/amd64/libc.so' 1757 else 1758 let libc = '/usr/lib/libc.so' 1759 endif 1760 else 1761 " Unfortunately skip this test until a good way is found. 1762 return 1763 endif 1764 endif 1765 1766 if has('win32') 1767 call assert_equal($USERPROFILE, 'USERPROFILE'->libcall(libc, 'getenv')) 1768 else 1769 call assert_equal($HOME, 'HOME'->libcall(libc, 'getenv')) 1770 endif 1771 1772 " If function returns NULL, libcall() should return an empty string. 1773 call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) 1774 1775 " Test libcallnr() with string and integer argument. 1776 call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen')) 1777 call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper')) 1778 1779 call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", ['', 'E364:']) 1780 call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", ['', 'E364:']) 1781 1782 call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", ['', 'E364:']) 1783 call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", ['', 'E364:']) 1784endfunc 1785 1786sandbox function Fsandbox() 1787 normal ix 1788endfunc 1789 1790func Test_func_sandbox() 1791 sandbox let F = {-> 'hello'} 1792 call assert_equal('hello', F()) 1793 1794 sandbox let F = {-> "normal ix\<Esc>"->execute()} 1795 call assert_fails('call F()', 'E48:') 1796 unlet F 1797 1798 call assert_fails('call Fsandbox()', 'E48:') 1799 delfunc Fsandbox 1800 1801 " From a sandbox try to set a predefined variable (which cannot be modified 1802 " from a sandbox) 1803 call assert_fails('sandbox let v:lnum = 10', 'E794:') 1804endfunc 1805 1806func EditAnotherFile() 1807 let word = expand('<cword>') 1808 edit Xfuncrange2 1809endfunc 1810 1811func Test_func_range_with_edit() 1812 " Define a function that edits another buffer, then call it with a range that 1813 " is invalid in that buffer. 1814 call writefile(['just one line'], 'Xfuncrange2') 1815 new 1816 eval 10->range()->setline(1) 1817 write Xfuncrange1 1818 call assert_fails('5,8call EditAnotherFile()', 'E16:') 1819 1820 call delete('Xfuncrange1') 1821 call delete('Xfuncrange2') 1822 bwipe! 1823endfunc 1824 1825func Test_func_exists_on_reload() 1826 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') 1827 call assert_equal(0, exists('*ExistingFunction')) 1828 source Xfuncexists 1829 call assert_equal(1, '*ExistingFunction'->exists()) 1830 " Redefining a function when reloading a script is OK. 1831 source Xfuncexists 1832 call assert_equal(1, exists('*ExistingFunction')) 1833 1834 " But redefining in another script is not OK. 1835 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2') 1836 call assert_fails('source Xfuncexists2', 'E122:') 1837 1838 " Defining a new function from the cmdline should fail if the function is 1839 " already defined 1840 call assert_fails('call feedkeys(":func ExistingFunction()\<CR>", "xt")', 'E122:') 1841 1842 delfunc ExistingFunction 1843 call assert_equal(0, exists('*ExistingFunction')) 1844 call writefile([ 1845 \ 'func ExistingFunction()', 'echo "yes"', 'endfunc', 1846 \ 'func ExistingFunction()', 'echo "no"', 'endfunc', 1847 \ ], 'Xfuncexists') 1848 call assert_fails('source Xfuncexists', 'E122:') 1849 call assert_equal(1, exists('*ExistingFunction')) 1850 1851 call delete('Xfuncexists2') 1852 call delete('Xfuncexists') 1853 delfunc ExistingFunction 1854endfunc 1855 1856" Test confirm({msg} [, {choices} [, {default} [, {type}]]]) 1857func Test_confirm() 1858 CheckUnix 1859 CheckNotGui 1860 1861 call feedkeys('o', 'L') 1862 let a = confirm('Press O to proceed') 1863 call assert_equal(1, a) 1864 1865 call feedkeys('y', 'L') 1866 let a = 'Are you sure?'->confirm("&Yes\n&No") 1867 call assert_equal(1, a) 1868 1869 call feedkeys('n', 'L') 1870 let a = confirm('Are you sure?', "&Yes\n&No") 1871 call assert_equal(2, a) 1872 1873 " confirm() should return 0 when pressing CTRL-C. 1874 call feedkeys("\<C-C>", 'L') 1875 let a = confirm('Are you sure?', "&Yes\n&No") 1876 call assert_equal(0, a) 1877 1878 " <Esc> requires another character to avoid it being seen as the start of an 1879 " escape sequence. Zero should be harmless. 1880 eval "\<Esc>0"->feedkeys('L') 1881 let a = confirm('Are you sure?', "&Yes\n&No") 1882 call assert_equal(0, a) 1883 1884 " Default choice is returned when pressing <CR>. 1885 call feedkeys("\<CR>", 'L') 1886 let a = confirm('Are you sure?', "&Yes\n&No") 1887 call assert_equal(1, a) 1888 1889 call feedkeys("\<CR>", 'L') 1890 let a = confirm('Are you sure?', "&Yes\n&No", 2) 1891 call assert_equal(2, a) 1892 1893 call feedkeys("\<CR>", 'L') 1894 let a = confirm('Are you sure?', "&Yes\n&No", 0) 1895 call assert_equal(0, a) 1896 1897 " Test with the {type} 4th argument 1898 for type in ['Error', 'Question', 'Info', 'Warning', 'Generic'] 1899 call feedkeys('y', 'L') 1900 let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type) 1901 call assert_equal(1, a) 1902 endfor 1903 1904 call assert_fails('call confirm([])', 'E730:') 1905 call assert_fails('call confirm("Are you sure?", [])', 'E730:') 1906 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:') 1907 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:') 1908endfunc 1909 1910func Test_platform_name() 1911 " The system matches at most only one name. 1912 let names = ['amiga', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix'] 1913 call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)'))) 1914 1915 " Is Unix? 1916 call assert_equal(has('bsd'), has('bsd') && has('unix')) 1917 call assert_equal(has('hpux'), has('hpux') && has('unix')) 1918 call assert_equal(has('linux'), has('linux') && has('unix')) 1919 call assert_equal(has('mac'), has('mac') && has('unix')) 1920 call assert_equal(has('qnx'), has('qnx') && has('unix')) 1921 call assert_equal(has('sun'), has('sun') && has('unix')) 1922 call assert_equal(has('win32'), has('win32') && !has('unix')) 1923 call assert_equal(has('win32unix'), has('win32unix') && has('unix')) 1924 1925 if has('unix') && executable('uname') 1926 let uname = system('uname') 1927 " GNU userland on BSD kernels (e.g., GNU/kFreeBSD) don't have BSD defined 1928 call assert_equal(uname =~? '\%(GNU/k\w\+\)\@<!BSD\|DragonFly', has('bsd')) 1929 call assert_equal(uname =~? 'HP-UX', has('hpux')) 1930 call assert_equal(uname =~? 'Linux', has('linux')) 1931 call assert_equal(uname =~? 'Darwin', has('mac')) 1932 call assert_equal(uname =~? 'QNX', has('qnx')) 1933 call assert_equal(uname =~? 'SunOS', has('sun')) 1934 call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) 1935 endif 1936endfunc 1937 1938func Test_readdir() 1939 call mkdir('Xdir') 1940 call writefile([], 'Xdir/foo.txt') 1941 call writefile([], 'Xdir/bar.txt') 1942 call mkdir('Xdir/dir') 1943 1944 " All results 1945 let files = readdir('Xdir') 1946 call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) 1947 1948 " Only results containing "f" 1949 let files = 'Xdir'->readdir({ x -> stridx(x, 'f') != -1 }) 1950 call assert_equal(['foo.txt'], sort(files)) 1951 1952 " Only .txt files 1953 let files = readdir('Xdir', { x -> x =~ '.txt$' }) 1954 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) 1955 1956 " Only .txt files with string 1957 let files = readdir('Xdir', 'v:val =~ ".txt$"') 1958 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) 1959 1960 " Limit to 1 result. 1961 let l = [] 1962 let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) 1963 call assert_equal(1, len(files)) 1964 1965 " Nested readdir() must not crash 1966 let files = readdir('Xdir', 'readdir("Xdir", "1") != []') 1967 call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt']) 1968 1969 eval 'Xdir'->delete('rf') 1970endfunc 1971 1972func Test_readdirex() 1973 call mkdir('Xdir') 1974 call writefile(['foo'], 'Xdir/foo.txt') 1975 call writefile(['barbar'], 'Xdir/bar.txt') 1976 call mkdir('Xdir/dir') 1977 1978 " All results 1979 let files = readdirex('Xdir')->map({-> v:val.name}) 1980 call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) 1981 let sizes = readdirex('Xdir')->map({-> v:val.size}) 1982 call assert_equal([0, 4, 7], sort(sizes)) 1983 1984 " Only results containing "f" 1985 let files = 'Xdir'->readdirex({ e -> stridx(e.name, 'f') != -1 }) 1986 \ ->map({-> v:val.name}) 1987 call assert_equal(['foo.txt'], sort(files)) 1988 1989 " Only .txt files 1990 let files = readdirex('Xdir', { e -> e.name =~ '.txt$' }) 1991 \ ->map({-> v:val.name}) 1992 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) 1993 1994 " Only .txt files with string 1995 let files = readdirex('Xdir', 'v:val.name =~ ".txt$"') 1996 \ ->map({-> v:val.name}) 1997 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) 1998 1999 " Limit to 1 result. 2000 let l = [] 2001 let files = readdirex('Xdir', {e -> len(add(l, e.name)) == 2 ? -1 : 1}) 2002 \ ->map({-> v:val.name}) 2003 call assert_equal(1, len(files)) 2004 2005 " Nested readdirex() must not crash 2006 let files = readdirex('Xdir', 'readdirex("Xdir", "1") != []') 2007 \ ->map({-> v:val.name}) 2008 call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt']) 2009 2010 " report broken link correctly 2011 if has("unix") 2012 call writefile([], 'Xdir/abc.txt') 2013 call system("ln -s Xdir/abc.txt Xdir/link") 2014 call delete('Xdir/abc.txt') 2015 let files = readdirex('Xdir', 'readdirex("Xdir", "1") != []') 2016 \ ->map({-> v:val.name .. '_' .. v:val.type}) 2017 call sort(files)->assert_equal( 2018 \ ['bar.txt_file', 'dir_dir', 'foo.txt_file', 'link_link']) 2019 endif 2020 eval 'Xdir'->delete('rf') 2021 2022 call assert_fails('call readdirex("doesnotexist")', 'E484:') 2023endfunc 2024 2025func Test_readdirex_sort() 2026 CheckUnix 2027 " Skip tests on Mac OS X and Cygwin (does not allow several files with different casing) 2028 if has("osxdarwin") || has("osx") || has("macunix") || has("win32unix") 2029 throw 'Skipped: Test_readdirex_sort on systems that do not allow this using the default filesystem' 2030 endif 2031 let _collate = v:collate 2032 call mkdir('Xdir2') 2033 call writefile(['1'], 'Xdir2/README.txt') 2034 call writefile(['2'], 'Xdir2/Readme.txt') 2035 call writefile(['3'], 'Xdir2/readme.txt') 2036 2037 " 1) default 2038 let files = readdirex('Xdir2')->map({-> v:val.name}) 2039 let default = copy(files) 2040 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort using default') 2041 2042 " 2) no sorting 2043 let files = readdirex('Xdir2', 1, #{sort: 'none'})->map({-> v:val.name}) 2044 let unsorted = copy(files) 2045 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], sort(files), 'unsorted') 2046 call assert_fails("call readdirex('Xdir2', 1, #{slort: 'none'})", 'E857: Dictionary key "sort" required') 2047 2048 " 3) sort by case (same as default) 2049 let files = readdirex('Xdir2', 1, #{sort: 'case'})->map({-> v:val.name}) 2050 call assert_equal(default, files, 'sort by case') 2051 2052 " 4) sort by ignoring case 2053 let files = readdirex('Xdir2', 1, #{sort: 'icase'})->map({-> v:val.name}) 2054 call assert_equal(unsorted->sort('i'), files, 'sort by icase') 2055 2056 " 5) Default Collation 2057 let collate = v:collate 2058 lang collate C 2059 let files = readdirex('Xdir2', 1, #{sort: 'collate'})->map({-> v:val.name}) 2060 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort by C collation') 2061 2062 " 6) Collation de_DE 2063 " Switch locale, this may not work on the CI system, if the locale isn't 2064 " available 2065 try 2066 lang collate de_DE 2067 let files = readdirex('Xdir2', 1, #{sort: 'collate'})->map({-> v:val.name}) 2068 call assert_equal(['readme.txt', 'Readme.txt', 'README.txt'], files, 'sort by de_DE collation') 2069 catch 2070 throw 'Skipped: de_DE collation is not available' 2071 2072 finally 2073 exe 'lang collate' collate 2074 eval 'Xdir2'->delete('rf') 2075 endtry 2076endfunc 2077 2078func Test_readdir_sort() 2079 " some more cases for testing sorting for readdirex 2080 let dir = 'Xdir3' 2081 call mkdir(dir) 2082 call writefile(['1'], dir .. '/README.txt') 2083 call writefile(['2'], dir .. '/Readm.txt') 2084 call writefile(['3'], dir .. '/read.txt') 2085 call writefile(['4'], dir .. '/Z.txt') 2086 call writefile(['5'], dir .. '/a.txt') 2087 call writefile(['6'], dir .. '/b.txt') 2088 2089 " 1) default 2090 let files = readdir(dir) 2091 let default = copy(files) 2092 call assert_equal(default->sort(), files, 'sort using default') 2093 2094 " 2) sort by case (same as default) 2095 let files = readdir(dir, '1', #{sort: 'case'}) 2096 call assert_equal(default, files, 'sort using default') 2097 2098 " 3) sort by ignoring case 2099 let files = readdir(dir, '1', #{sort: 'icase'}) 2100 call assert_equal(default->sort('i'), files, 'sort by ignoring case') 2101 2102 " 4) collation 2103 let collate = v:collate 2104 lang collate C 2105 let files = readdir(dir, 1, #{sort: 'collate'}) 2106 call assert_equal(default->sort(), files, 'sort by C collation') 2107 exe "lang collate" collate 2108 2109 " 5) Errors 2110 call assert_fails('call readdir(dir, 1, 1)', 'E715:') 2111 call assert_fails('call readdir(dir, 1, #{sorta: 1})') 2112 call assert_fails('call readdirex(dir, 1, #{sorta: 1})') 2113 2114 " 6) ignore other values in dict 2115 let files = readdir(dir, '1', #{sort: 'c'}) 2116 call assert_equal(default, files, 'sort using default2') 2117 2118 " Cleanup 2119 exe "lang collate" collate 2120 2121 eval dir->delete('rf') 2122endfunc 2123 2124func Test_delete_rf() 2125 call mkdir('Xdir') 2126 call writefile([], 'Xdir/foo.txt') 2127 call writefile([], 'Xdir/bar.txt') 2128 call mkdir('Xdir/[a-1]') " issue #696 2129 call writefile([], 'Xdir/[a-1]/foo.txt') 2130 call writefile([], 'Xdir/[a-1]/bar.txt') 2131 call assert_true(filereadable('Xdir/foo.txt')) 2132 call assert_true('Xdir/[a-1]/foo.txt'->filereadable()) 2133 2134 call assert_equal(0, delete('Xdir', 'rf')) 2135 call assert_false(filereadable('Xdir/foo.txt')) 2136 call assert_false(filereadable('Xdir/[a-1]/foo.txt')) 2137endfunc 2138 2139func Test_call() 2140 call assert_equal(3, call('len', [123])) 2141 call assert_equal(3, 'len'->call([123])) 2142 call assert_fails("call call('len', 123)", 'E714:') 2143 call assert_equal(0, call('', [])) 2144 call assert_equal(0, call('len', test_null_list())) 2145 2146 function Mylen() dict 2147 return len(self.data) 2148 endfunction 2149 let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} 2150 eval mydict.len->call([], mydict)->assert_equal(4) 2151 call assert_fails("call call('Mylen', [], 0)", 'E715:') 2152 call assert_fails('call foo', 'E107:') 2153 2154 " These once caused a crash. 2155 call call(test_null_function(), []) 2156 call call(test_null_partial(), []) 2157 call assert_fails('call test_null_function()()', 'E1192:') 2158 call assert_fails('call test_null_partial()()', 'E117:') 2159endfunc 2160 2161func Test_char2nr() 2162 call assert_equal(12354, char2nr('あ', 1)) 2163 call assert_equal(120, 'x'->char2nr()) 2164 set encoding=latin1 2165 call assert_equal(120, 'x'->char2nr()) 2166 set encoding=utf-8 2167endfunc 2168 2169func Test_charclass() 2170 call assert_equal(0, charclass(' ')) 2171 call assert_equal(1, charclass('.')) 2172 call assert_equal(2, charclass('x')) 2173 call assert_equal(3, charclass("\u203c")) 2174 " this used to crash vim 2175 call assert_equal(0, "xxx"[-1]->charclass()) 2176endfunc 2177 2178func Test_eventhandler() 2179 call assert_equal(0, eventhandler()) 2180endfunc 2181 2182func Test_bufadd_bufload() 2183 call assert_equal(0, bufexists('someName')) 2184 let buf = bufadd('someName') 2185 call assert_notequal(0, buf) 2186 call assert_equal(1, bufexists('someName')) 2187 call assert_equal(0, getbufvar(buf, '&buflisted')) 2188 call assert_equal(0, bufloaded(buf)) 2189 call bufload(buf) 2190 call assert_equal(1, bufloaded(buf)) 2191 call assert_equal([''], getbufline(buf, 1, '$')) 2192 2193 let curbuf = bufnr('') 2194 eval ['some', 'text']->writefile('XotherName') 2195 let buf = 'XotherName'->bufadd() 2196 call assert_notequal(0, buf) 2197 eval 'XotherName'->bufexists()->assert_equal(1) 2198 call assert_equal(0, getbufvar(buf, '&buflisted')) 2199 call assert_equal(0, bufloaded(buf)) 2200 eval buf->bufload() 2201 call assert_equal(1, bufloaded(buf)) 2202 call assert_equal(['some', 'text'], getbufline(buf, 1, '$')) 2203 call assert_equal(curbuf, bufnr('')) 2204 2205 let buf1 = bufadd('') 2206 let buf2 = bufadd('') 2207 call assert_notequal(0, buf1) 2208 call assert_notequal(0, buf2) 2209 call assert_notequal(buf1, buf2) 2210 call assert_equal(1, bufexists(buf1)) 2211 call assert_equal(1, bufexists(buf2)) 2212 call assert_equal(0, bufloaded(buf1)) 2213 exe 'bwipe ' .. buf1 2214 call assert_equal(0, bufexists(buf1)) 2215 call assert_equal(1, bufexists(buf2)) 2216 exe 'bwipe ' .. buf2 2217 call assert_equal(0, bufexists(buf2)) 2218 2219 bwipe someName 2220 bwipe XotherName 2221 call assert_equal(0, bufexists('someName')) 2222 call delete('XotherName') 2223endfunc 2224 2225func Test_state() 2226 CheckRunVimInTerminal 2227 2228 let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>" 2229 2230 let lines =<< trim END 2231 call setline(1, ['one', 'two', 'three']) 2232 map ;; gg 2233 set complete=. 2234 func RunTimer() 2235 call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')}) 2236 endfunc 2237 au Filetype foobar let g:state = state()|let g:mode = mode() 2238 END 2239 call writefile(lines, 'XState') 2240 let buf = RunVimInTerminal('-S XState', #{rows: 6}) 2241 2242 " Using a ":" command Vim is busy, thus "S" is returned 2243 call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>") 2244 call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000) 2245 call term_sendkeys(buf, ":\<CR>") 2246 2247 " Using a timer callback 2248 call term_sendkeys(buf, ":call RunTimer()\<CR>") 2249 call TermWait(buf, 25) 2250 call term_sendkeys(buf, getstate) 2251 call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000) 2252 2253 " Halfway a mapping 2254 call term_sendkeys(buf, ":call RunTimer()\<CR>;") 2255 call TermWait(buf, 25) 2256 call term_sendkeys(buf, ";") 2257 call term_sendkeys(buf, getstate) 2258 call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000) 2259 2260 " Insert mode completion (bit slower on Mac) 2261 call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>") 2262 call TermWait(buf, 25) 2263 call term_sendkeys(buf, "\<Esc>") 2264 call term_sendkeys(buf, getstate) 2265 call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000) 2266 2267 " Autocommand executing 2268 call term_sendkeys(buf, ":set filetype=foobar\<CR>") 2269 call TermWait(buf, 25) 2270 call term_sendkeys(buf, getstate) 2271 call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000) 2272 2273 " Todo: "w" - waiting for ch_evalexpr() 2274 2275 " messages scrolled 2276 call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>") 2277 call TermWait(buf, 25) 2278 call term_sendkeys(buf, "\<CR>") 2279 call term_sendkeys(buf, getstate) 2280 call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000) 2281 2282 call StopVimInTerminal(buf) 2283 call delete('XState') 2284endfunc 2285 2286func Test_range() 2287 " destructuring 2288 let [x, y] = range(2) 2289 call assert_equal([0, 1], [x, y]) 2290 2291 " index 2292 call assert_equal(4, range(1, 10)[3]) 2293 2294 " add() 2295 call assert_equal([0, 1, 2, 3], add(range(3), 3)) 2296 call assert_equal([0, 1, 2, [0, 1, 2]], add([0, 1, 2], range(3))) 2297 call assert_equal([0, 1, 2, [0, 1, 2]], add(range(3), range(3))) 2298 2299 " append() 2300 new 2301 call append('.', range(5)) 2302 call assert_equal(['', '0', '1', '2', '3', '4'], getline(1, '$')) 2303 bwipe! 2304 2305 " appendbufline() 2306 new 2307 call appendbufline(bufnr(''), '.', range(5)) 2308 call assert_equal(['0', '1', '2', '3', '4', ''], getline(1, '$')) 2309 bwipe! 2310 2311 " call() 2312 func TwoArgs(a, b) 2313 return [a:a, a:b] 2314 endfunc 2315 call assert_equal([0, 1], call('TwoArgs', range(2))) 2316 2317 " col() 2318 new 2319 call setline(1, ['foo', 'bar']) 2320 call assert_equal(2, col(range(1, 2))) 2321 bwipe! 2322 2323 " complete() 2324 execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>" 2325 " complete_info() 2326 execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>" 2327 2328 " copy() 2329 call assert_equal([1, 2, 3], copy(range(1, 3))) 2330 2331 " count() 2332 call assert_equal(0, count(range(0), 3)) 2333 call assert_equal(0, count(range(2), 3)) 2334 call assert_equal(1, count(range(5), 3)) 2335 2336 " cursor() 2337 new 2338 call setline(1, ['aaa', 'bbb', 'ccc']) 2339 call cursor(range(1, 2)) 2340 call assert_equal([2, 1], [col('.'), line('.')]) 2341 bwipe! 2342 2343 " deepcopy() 2344 call assert_equal([1, 2, 3], deepcopy(range(1, 3))) 2345 2346 " empty() 2347 call assert_true(empty(range(0))) 2348 call assert_false(empty(range(2))) 2349 2350 " execute() 2351 new 2352 call setline(1, ['aaa', 'bbb', 'ccc']) 2353 call execute(range(3)) 2354 call assert_equal(2, line('.')) 2355 bwipe! 2356 2357 " extend() 2358 call assert_equal([1, 2, 3, 4], extend([1], range(2, 4))) 2359 call assert_equal([1, 2, 3, 4], extend(range(1, 1), range(2, 4))) 2360 call assert_equal([1, 2, 3, 4], extend(range(1, 1), [2, 3, 4])) 2361 2362 " filter() 2363 call assert_equal([1, 3], filter(range(5), 'v:val % 2')) 2364 call assert_equal([1, 5, 7, 11, 13], filter(filter(range(15), 'v:val % 2'), 'v:val % 3')) 2365 2366 " funcref() 2367 call assert_equal([0, 1], funcref('TwoArgs', range(2))()) 2368 2369 " function() 2370 call assert_equal([0, 1], function('TwoArgs', range(2))()) 2371 2372 " garbagecollect() 2373 let thelist = [1, range(2), 3] 2374 let otherlist = range(3) 2375 call test_garbagecollect_now() 2376 2377 " get() 2378 call assert_equal(4, get(range(1, 10), 3)) 2379 call assert_equal(-1, get(range(1, 10), 42, -1)) 2380 2381 " index() 2382 call assert_equal(1, index(range(1, 5), 2)) 2383 call assert_fails("echo index([1, 2], 1, [])", 'E745:') 2384 2385 " inputlist() 2386 call feedkeys(":let result = inputlist(range(10))\<CR>1\<CR>", 'x') 2387 call assert_equal(1, result) 2388 call feedkeys(":let result = inputlist(range(3, 10))\<CR>1\<CR>", 'x') 2389 call assert_equal(1, result) 2390 2391 " insert() 2392 call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42)) 2393 call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42, 0)) 2394 call assert_equal([1, 42, 2, 3, 4, 5], insert(range(1, 5), 42, 1)) 2395 call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, 4)) 2396 call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, -1)) 2397 call assert_equal([1, 2, 3, 4, 5, 42], insert(range(1, 5), 42, 5)) 2398 2399 " join() 2400 call assert_equal('0 1 2 3 4', join(range(5))) 2401 2402 " json_encode() 2403 call assert_equal('[0,1,2,3]', json_encode(range(4))) 2404 2405 " len() 2406 call assert_equal(0, len(range(0))) 2407 call assert_equal(2, len(range(2))) 2408 call assert_equal(5, len(range(0, 12, 3))) 2409 call assert_equal(4, len(range(3, 0, -1))) 2410 2411 " list2str() 2412 call assert_equal('ABC', list2str(range(65, 67))) 2413 call assert_fails('let s = list2str(5)', 'E474:') 2414 2415 " lock() 2416 let thelist = range(5) 2417 lockvar thelist 2418 2419 " map() 2420 call assert_equal([0, 2, 4, 6, 8], map(range(5), 'v:val * 2')) 2421 call assert_equal([3, 5, 7, 9, 11], map(map(range(5), 'v:val * 2'), 'v:val + 3')) 2422 call assert_equal([2, 6], map(filter(range(5), 'v:val % 2'), 'v:val * 2')) 2423 call assert_equal([2, 4, 8], filter(map(range(5), 'v:val * 2'), 'v:val % 3')) 2424 2425 " match() 2426 call assert_equal(3, match(range(5), 3)) 2427 2428 " matchaddpos() 2429 highlight MyGreenGroup ctermbg=green guibg=green 2430 call matchaddpos('MyGreenGroup', range(line('.'), line('.'))) 2431 2432 " matchend() 2433 call assert_equal(4, matchend(range(5), '4')) 2434 call assert_equal(3, matchend(range(1, 5), '4')) 2435 call assert_equal(-1, matchend(range(1, 5), '42')) 2436 2437 " matchstrpos() 2438 call assert_equal(['4', 4, 0, 1], matchstrpos(range(5), '4')) 2439 call assert_equal(['4', 3, 0, 1], matchstrpos(range(1, 5), '4')) 2440 call assert_equal(['', -1, -1, -1], matchstrpos(range(1, 5), '42')) 2441 2442 " max() reverse() 2443 call assert_equal(0, max(range(0))) 2444 call assert_equal(0, max(range(10, 9))) 2445 call assert_equal(9, max(range(10))) 2446 call assert_equal(18, max(range(0, 20, 3))) 2447 call assert_equal(20, max(range(20, 0, -3))) 2448 call assert_equal(99999, max(range(100000))) 2449 call assert_equal(99999, max(range(99999, 0, -1))) 2450 call assert_equal(99999, max(reverse(range(100000)))) 2451 call assert_equal(99999, max(reverse(range(99999, 0, -1)))) 2452 2453 " min() reverse() 2454 call assert_equal(0, min(range(0))) 2455 call assert_equal(0, min(range(10, 9))) 2456 call assert_equal(5, min(range(5, 10))) 2457 call assert_equal(5, min(range(5, 10, 3))) 2458 call assert_equal(2, min(range(20, 0, -3))) 2459 call assert_equal(0, min(range(100000))) 2460 call assert_equal(0, min(range(99999, 0, -1))) 2461 call assert_equal(0, min(reverse(range(100000)))) 2462 call assert_equal(0, min(reverse(range(99999, 0, -1)))) 2463 2464 " remove() 2465 call assert_equal(1, remove(range(1, 10), 0)) 2466 call assert_equal(2, remove(range(1, 10), 1)) 2467 call assert_equal(9, remove(range(1, 10), 8)) 2468 call assert_equal(10, remove(range(1, 10), 9)) 2469 call assert_equal(10, remove(range(1, 10), -1)) 2470 call assert_equal([3, 4, 5], remove(range(1, 10), 2, 4)) 2471 2472 " repeat() 2473 call assert_equal([0, 1, 2, 0, 1, 2], repeat(range(3), 2)) 2474 call assert_equal([0, 1, 2], repeat(range(3), 1)) 2475 call assert_equal([], repeat(range(3), 0)) 2476 call assert_equal([], repeat(range(5, 4), 2)) 2477 call assert_equal([], repeat(range(5, 4), 0)) 2478 2479 " reverse() 2480 call assert_equal([2, 1, 0], reverse(range(3))) 2481 call assert_equal([0, 1, 2, 3], reverse(range(3, 0, -1))) 2482 call assert_equal([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], reverse(range(10))) 2483 call assert_equal([20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], reverse(range(10, 20))) 2484 call assert_equal([16, 13, 10], reverse(range(10, 18, 3))) 2485 call assert_equal([19, 16, 13, 10], reverse(range(10, 19, 3))) 2486 call assert_equal([19, 16, 13, 10], reverse(range(10, 20, 3))) 2487 call assert_equal([11, 14, 17, 20], reverse(range(20, 10, -3))) 2488 call assert_equal([], reverse(range(0))) 2489 2490 " TODO: setpos() 2491 " new 2492 " call setline(1, repeat([''], bufnr(''))) 2493 " call setline(bufnr('') + 1, repeat('x', bufnr('') * 2 + 6)) 2494 " call setpos('x', range(bufnr(''), bufnr('') + 3)) 2495 " bwipe! 2496 2497 " setreg() 2498 call setreg('a', range(3)) 2499 call assert_equal("0\n1\n2\n", getreg('a')) 2500 2501 " settagstack() 2502 call settagstack(1, #{items : range(4)}) 2503 2504 " sign_define() 2505 call assert_fails("call sign_define(range(5))", "E715:") 2506 call assert_fails("call sign_placelist(range(5))", "E715:") 2507 2508 " sign_undefine() 2509 call assert_fails("call sign_undefine(range(5))", "E908:") 2510 2511 " sign_unplacelist() 2512 call assert_fails("call sign_unplacelist(range(5))", "E715:") 2513 2514 " sort() 2515 call assert_equal([0, 1, 2, 3, 4, 5], sort(range(5, 0, -1))) 2516 2517 " string() 2518 call assert_equal('[0, 1, 2, 3, 4]', string(range(5))) 2519 2520 " taglist() with 'tagfunc' 2521 func TagFunc(pattern, flags, info) 2522 return range(10) 2523 endfunc 2524 set tagfunc=TagFunc 2525 call assert_fails("call taglist('asdf')", 'E987:') 2526 set tagfunc= 2527 2528 " term_start() 2529 if has('terminal') && has('termguicolors') 2530 call assert_fails('call term_start(range(3, 4))', 'E474:') 2531 let g:terminal_ansi_colors = range(16) 2532 if has('win32') 2533 let cmd = "cmd /c dir" 2534 else 2535 let cmd = "ls" 2536 endif 2537 call assert_fails('call term_start("' .. cmd .. '", #{term_finish: "close"})', 'E475:') 2538 unlet g:terminal_ansi_colors 2539 endif 2540 2541 " type() 2542 call assert_equal(v:t_list, type(range(5))) 2543 2544 " uniq() 2545 call assert_equal([0, 1, 2, 3, 4], uniq(range(5))) 2546 2547 " errors 2548 call assert_fails('let x=range(2, 8, 0)', 'E726:') 2549 call assert_fails('let x=range(3, 1)', 'E727:') 2550 call assert_fails('let x=range(1, 3, -2)', 'E727:') 2551 call assert_fails('let x=range([])', 'E745:') 2552 call assert_fails('let x=range(1, [])', 'E745:') 2553 call assert_fails('let x=range(1, 4, [])', 'E745:') 2554endfunc 2555 2556func Test_echoraw() 2557 CheckScreendump 2558 2559 " Normally used for escape codes, but let's test with a CR. 2560 let lines =<< trim END 2561 call echoraw("hello\<CR>x") 2562 END 2563 call writefile(lines, 'XTest_echoraw') 2564 let buf = RunVimInTerminal('-S XTest_echoraw', {'rows': 5, 'cols': 40}) 2565 call VerifyScreenDump(buf, 'Test_functions_echoraw', {}) 2566 2567 " clean up 2568 call StopVimInTerminal(buf) 2569 call delete('XTest_echoraw') 2570endfunc 2571 2572" Test for echo highlighting 2573func Test_echohl() 2574 echohl Search 2575 echo 'Vim' 2576 call assert_equal('Vim', Screenline(&lines)) 2577 " TODO: How to check the highlight group used by echohl? 2578 " ScreenAttrs() returns all zeros. 2579 echohl None 2580endfunc 2581 2582" Test for the eval() function 2583func Test_eval() 2584 call assert_fails("call eval('5 a')", 'E488:') 2585endfunc 2586 2587" Test for the nr2char() function 2588func Test_nr2char() 2589 set encoding=latin1 2590 call assert_equal('@', nr2char(64)) 2591 set encoding=utf8 2592 call assert_equal('a', nr2char(97, 1)) 2593 call assert_equal('a', nr2char(97, 0)) 2594 2595 call assert_equal("\x80\xfc\b\xf4\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x100000) .. '>"')) 2596 call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"')) 2597endfunc 2598 2599" Test for screenattr(), screenchar() and screenchars() functions 2600func Test_screen_functions() 2601 call assert_equal(-1, screenattr(-1, -1)) 2602 call assert_equal(-1, screenchar(-1, -1)) 2603 call assert_equal([], screenchars(-1, -1)) 2604endfunc 2605 2606" Test for getcurpos() and setpos() 2607func Test_getcurpos_setpos() 2608 new 2609 call setline(1, ['012345678', '012345678']) 2610 normal gg6l 2611 let sp = getcurpos() 2612 normal 0 2613 call setpos('.', sp) 2614 normal jyl 2615 call assert_equal('6', @") 2616 call assert_equal(-1, setpos('.', test_null_list())) 2617 call assert_equal(-1, setpos('.', {})) 2618 2619 let winid = win_getid() 2620 normal G$ 2621 let pos = getcurpos() 2622 wincmd w 2623 call assert_equal(pos, getcurpos(winid)) 2624 2625 wincmd w 2626 close! 2627 2628 call assert_equal(getcurpos(), getcurpos(0)) 2629 call assert_equal([0, 0, 0, 0, 0], getcurpos(-1)) 2630 call assert_equal([0, 0, 0, 0, 0], getcurpos(1999)) 2631endfunc 2632 2633" Test for glob() 2634func Test_glob() 2635 call assert_equal('', glob(test_null_string())) 2636 call assert_equal('', globpath(test_null_string(), test_null_string())) 2637 call assert_fails("let x = globpath(&rtp, 'syntax/c.vim', [])", 'E745:') 2638 2639 call writefile([], 'Xglob1') 2640 call writefile([], 'XGLOB2') 2641 set wildignorecase 2642 " Sort output of glob() otherwise we end up with different 2643 " ordering depending on whether file system is case-sensitive. 2644 call assert_equal(['XGLOB2', 'Xglob1'], sort(glob('Xglob[12]', 0, 1))) 2645 set wildignorecase& 2646 2647 call delete('Xglob1') 2648 call delete('XGLOB2') 2649 2650 call assert_fails("call glob('*', 0, {})", 'E728:') 2651endfunc 2652 2653" Test for browse() 2654func Test_browse() 2655 CheckFeature browse 2656 call assert_fails('call browse([], "open", "x", "a.c")', 'E745:') 2657endfunc 2658 2659" Test for browsedir() 2660func Test_browsedir() 2661 CheckFeature browse 2662 call assert_fails('call browsedir("open", [])', 'E730:') 2663endfunc 2664 2665func HasDefault(msg = 'msg') 2666 return a:msg 2667endfunc 2668 2669func Test_default_arg_value() 2670 call assert_equal('msg', HasDefault()) 2671endfunc 2672 2673" Test for gettext() 2674func Test_gettext() 2675 call assert_fails('call gettext(1)', 'E475:') 2676endfunc 2677 2678func Test_builtin_check() 2679 call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:') 2680 call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:') 2681 call assert_fails('let l:["trim"] = {x -> " " .. x}', 'E704:') 2682 call assert_fails('let l:.trim = {x -> " " .. x}', 'E704:') 2683 let lines =<< trim END 2684 vim9script 2685 var s:trim = (x) => " " .. x 2686 END 2687 call CheckScriptFailure(lines, 'E704:') 2688 2689 call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:') 2690 let g:bar = 123 2691 call extend(g:, #{bar: { -> "foo" }}, "keep") 2692 call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:') 2693endfunc 2694 2695 2696" vim: shiftwidth=2 sts=2 expandtab 2697