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