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