Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1 | " Test using builtin functions in the Vim9 script language. |
| 2 | |
| 3 | source check.vim |
| 4 | source vim9.vim |
| 5 | |
| 6 | " Test for passing too many or too few arguments to builtin functions |
| 7 | func Test_internalfunc_arg_error() |
| 8 | let l =<< trim END |
| 9 | def! FArgErr(): float |
| 10 | return ceil(1.1, 2) |
| 11 | enddef |
| 12 | defcompile |
| 13 | END |
| 14 | call writefile(l, 'Xinvalidarg') |
| 15 | call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr') |
| 16 | let l =<< trim END |
| 17 | def! FArgErr(): float |
| 18 | return ceil() |
| 19 | enddef |
| 20 | defcompile |
| 21 | END |
| 22 | call writefile(l, 'Xinvalidarg') |
| 23 | call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr') |
| 24 | call delete('Xinvalidarg') |
| 25 | endfunc |
| 26 | |
| 27 | " Test for builtin functions returning different types |
| 28 | func Test_InternalFuncRetType() |
| 29 | let lines =<< trim END |
| 30 | def RetFloat(): float |
| 31 | return ceil(1.456) |
| 32 | enddef |
| 33 | |
| 34 | def RetListAny(): list<any> |
| 35 | return items({'k': 'v'}) |
| 36 | enddef |
| 37 | |
| 38 | def RetListString(): list<string> |
| 39 | return split('a:b:c', ':') |
| 40 | enddef |
| 41 | |
| 42 | def RetListDictAny(): list<dict<any>> |
| 43 | return getbufinfo() |
| 44 | enddef |
| 45 | |
| 46 | def RetDictNumber(): dict<number> |
| 47 | return wordcount() |
| 48 | enddef |
| 49 | |
| 50 | def RetDictString(): dict<string> |
| 51 | return environ() |
| 52 | enddef |
| 53 | END |
| 54 | call writefile(lines, 'Xscript') |
| 55 | source Xscript |
| 56 | |
| 57 | call RetFloat()->assert_equal(2.0) |
| 58 | call RetListAny()->assert_equal([['k', 'v']]) |
| 59 | call RetListString()->assert_equal(['a', 'b', 'c']) |
| 60 | call RetListDictAny()->assert_notequal([]) |
| 61 | call RetDictNumber()->assert_notequal({}) |
| 62 | call RetDictString()->assert_notequal({}) |
| 63 | call delete('Xscript') |
| 64 | endfunc |
| 65 | |
| 66 | def Test_abs() |
| 67 | assert_equal(0, abs(0)) |
| 68 | assert_equal(2, abs(-2)) |
| 69 | assert_equal(3, abs(3)) |
| 70 | CheckDefFailure(['abs("text")'], 'E1013: Argument 1: type mismatch, expected number but got string', 1) |
| 71 | if has('float') |
| 72 | assert_equal(0, abs(0)) |
| 73 | assert_equal(2.0, abs(-2.0)) |
| 74 | assert_equal(3.0, abs(3.0)) |
| 75 | endif |
| 76 | enddef |
| 77 | |
| 78 | def Test_add_list() |
| 79 | var l: list<number> # defaults to empty list |
| 80 | add(l, 9) |
| 81 | assert_equal([9], l) |
| 82 | |
| 83 | var lines =<< trim END |
| 84 | var l: list<number> |
| 85 | add(l, "x") |
| 86 | END |
| 87 | CheckDefFailure(lines, 'E1012:', 2) |
| 88 | |
| 89 | lines =<< trim END |
| 90 | var l: list<number> = test_null_list() |
| 91 | add(l, 123) |
| 92 | END |
| 93 | CheckDefExecFailure(lines, 'E1130:', 2) |
| 94 | enddef |
| 95 | |
| 96 | def Test_add_blob() |
| 97 | var b1: blob = 0z12 |
| 98 | add(b1, 0x34) |
| 99 | assert_equal(0z1234, b1) |
| 100 | |
| 101 | var b2: blob # defaults to empty blob |
| 102 | add(b2, 0x67) |
| 103 | assert_equal(0z67, b2) |
| 104 | |
| 105 | var lines =<< trim END |
| 106 | var b: blob |
| 107 | add(b, "x") |
| 108 | END |
| 109 | CheckDefFailure(lines, 'E1012:', 2) |
| 110 | |
| 111 | lines =<< trim END |
| 112 | var b: blob = test_null_blob() |
| 113 | add(b, 123) |
| 114 | END |
| 115 | CheckDefExecFailure(lines, 'E1131:', 2) |
| 116 | enddef |
| 117 | |
| 118 | def Test_bufname() |
| 119 | split SomeFile |
| 120 | bufname('%')->assert_equal('SomeFile') |
| 121 | edit OtherFile |
| 122 | bufname('#')->assert_equal('SomeFile') |
| 123 | close |
| 124 | enddef |
| 125 | |
| 126 | def Test_bufnr() |
| 127 | var buf = bufnr() |
| 128 | bufnr('%')->assert_equal(buf) |
| 129 | |
| 130 | buf = bufnr('Xdummy', true) |
| 131 | buf->assert_notequal(-1) |
| 132 | exe 'bwipe! ' .. buf |
| 133 | enddef |
| 134 | |
| 135 | def Test_bufwinid() |
| 136 | var origwin = win_getid() |
| 137 | below split SomeFile |
| 138 | var SomeFileID = win_getid() |
| 139 | below split OtherFile |
| 140 | below split SomeFile |
| 141 | bufwinid('SomeFile')->assert_equal(SomeFileID) |
| 142 | |
| 143 | win_gotoid(origwin) |
| 144 | only |
| 145 | bwipe SomeFile |
| 146 | bwipe OtherFile |
| 147 | enddef |
| 148 | |
| 149 | def Test_call_call() |
| 150 | var l = [3, 2, 1] |
| 151 | call('reverse', [l]) |
| 152 | l->assert_equal([1, 2, 3]) |
| 153 | enddef |
| 154 | |
| 155 | def Test_char2nr() |
| 156 | char2nr('あ', true)->assert_equal(12354) |
| 157 | enddef |
| 158 | |
| 159 | def Test_col() |
| 160 | new |
| 161 | setline(1, 'asdf') |
| 162 | col([1, '$'])->assert_equal(5) |
| 163 | enddef |
| 164 | |
| 165 | def Test_copy_return_type() |
| 166 | var l = copy([1, 2, 3]) |
| 167 | var res = 0 |
| 168 | for n in l |
| 169 | res += n |
| 170 | endfor |
| 171 | res->assert_equal(6) |
| 172 | |
| 173 | var dl = deepcopy([1, 2, 3]) |
| 174 | res = 0 |
| 175 | for n in dl |
| 176 | res += n |
| 177 | endfor |
| 178 | res->assert_equal(6) |
| 179 | |
| 180 | dl = deepcopy([1, 2, 3], true) |
| 181 | enddef |
| 182 | |
| 183 | def Test_count() |
| 184 | count('ABC ABC ABC', 'b', true)->assert_equal(3) |
| 185 | count('ABC ABC ABC', 'b', false)->assert_equal(0) |
| 186 | enddef |
| 187 | |
| 188 | def Test_expand() |
| 189 | split SomeFile |
| 190 | expand('%', true, true)->assert_equal(['SomeFile']) |
| 191 | close |
| 192 | enddef |
| 193 | |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 194 | def Test_extend_arg_types() |
| 195 | assert_equal([1, 2, 3], extend([1, 2], [3])) |
| 196 | assert_equal([3, 1, 2], extend([1, 2], [3], 0)) |
| 197 | assert_equal([1, 3, 2], extend([1, 2], [3], 1)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 198 | assert_equal([1, 3, 2], extend([1, 2], [3], s:number_one)) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 199 | |
| 200 | assert_equal(#{a: 1, b: 2, c: 3}, extend(#{a: 1, b: 2}, #{c: 3})) |
| 201 | assert_equal(#{a: 1, b: 4}, extend(#{a: 1, b: 2}, #{b: 4})) |
| 202 | assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, 'keep')) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 203 | assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, s:string_keep)) |
| 204 | |
| 205 | var res: list<dict<any>> |
| 206 | extend(res, map([1, 2], {_, v -> {}})) |
| 207 | assert_equal([{}, {}], res) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 208 | |
| 209 | CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 210 | CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 211 | CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 212 | |
| 213 | CheckDefFailure(['extend(#{a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 214 | CheckDefFailure(['extend(#{a: 1}, #{b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>') |
| 215 | CheckDefFailure(['extend(#{a: 1}, #{b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 216 | enddef |
| 217 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 218 | def Test_extend_return_type() |
| 219 | var l = extend([1, 2], [3]) |
| 220 | var res = 0 |
| 221 | for n in l |
| 222 | res += n |
| 223 | endfor |
| 224 | res->assert_equal(6) |
| 225 | enddef |
| 226 | |
| 227 | |
| 228 | def Wrong_dict_key_type(items: list<number>): list<number> |
| 229 | return filter(items, {_, val -> get({val: 1}, 'x')}) |
| 230 | enddef |
| 231 | |
| 232 | def Test_filter_wrong_dict_key_type() |
| 233 | assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1012:') |
| 234 | enddef |
| 235 | |
| 236 | def Test_filter_return_type() |
| 237 | var l = filter([1, 2, 3], {-> 1}) |
| 238 | var res = 0 |
| 239 | for n in l |
| 240 | res += n |
| 241 | endfor |
| 242 | res->assert_equal(6) |
| 243 | enddef |
| 244 | |
| 245 | |
| 246 | def Test_garbagecollect() |
| 247 | garbagecollect(true) |
| 248 | enddef |
| 249 | |
| 250 | def Test_getbufinfo() |
| 251 | var bufinfo = getbufinfo(bufnr()) |
| 252 | getbufinfo('%')->assert_equal(bufinfo) |
| 253 | |
| 254 | edit Xtestfile1 |
| 255 | hide edit Xtestfile2 |
| 256 | hide enew |
| 257 | getbufinfo(#{bufloaded: true, buflisted: true, bufmodified: false}) |
| 258 | ->len()->assert_equal(3) |
| 259 | bwipe Xtestfile1 Xtestfile2 |
| 260 | enddef |
| 261 | |
| 262 | def Test_getbufline() |
| 263 | e SomeFile |
| 264 | var buf = bufnr() |
| 265 | e # |
| 266 | var lines = ['aaa', 'bbb', 'ccc'] |
| 267 | setbufline(buf, 1, lines) |
| 268 | getbufline('#', 1, '$')->assert_equal(lines) |
Bram Moolenaar | e6e70a1 | 2020-10-22 18:23:38 +0200 | [diff] [blame] | 269 | getbufline(-1, '$', '$')->assert_equal([]) |
| 270 | getbufline(-1, 1, '$')->assert_equal([]) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 271 | |
| 272 | bwipe! |
| 273 | enddef |
| 274 | |
| 275 | def Test_getchangelist() |
| 276 | new |
| 277 | setline(1, 'some text') |
| 278 | var changelist = bufnr()->getchangelist() |
| 279 | getchangelist('%')->assert_equal(changelist) |
| 280 | bwipe! |
| 281 | enddef |
| 282 | |
| 283 | def Test_getchar() |
| 284 | while getchar(0) |
| 285 | endwhile |
| 286 | getchar(true)->assert_equal(0) |
| 287 | enddef |
| 288 | |
| 289 | def Test_getcompletion() |
| 290 | set wildignore=*.vim,*~ |
| 291 | var l = getcompletion('run', 'file', true) |
| 292 | l->assert_equal([]) |
| 293 | set wildignore& |
| 294 | enddef |
| 295 | |
| 296 | def Test_getloclist_return_type() |
| 297 | var l = getloclist(1) |
| 298 | l->assert_equal([]) |
| 299 | |
| 300 | var d = getloclist(1, #{items: 0}) |
| 301 | d->assert_equal(#{items: []}) |
| 302 | enddef |
| 303 | |
| 304 | def Test_getqflist_return_type() |
| 305 | var l = getqflist() |
| 306 | l->assert_equal([]) |
| 307 | |
| 308 | var d = getqflist(#{items: 0}) |
| 309 | d->assert_equal(#{items: []}) |
| 310 | enddef |
| 311 | |
| 312 | def Test_getreg() |
| 313 | var lines = ['aaa', 'bbb', 'ccc'] |
| 314 | setreg('a', lines) |
| 315 | getreg('a', true, true)->assert_equal(lines) |
| 316 | enddef |
| 317 | |
| 318 | def Test_getreg_return_type() |
| 319 | var s1: string = getreg('"') |
| 320 | var s2: string = getreg('"', 1) |
| 321 | var s3: list<string> = getreg('"', 1, 1) |
| 322 | enddef |
| 323 | |
| 324 | def Test_glob() |
| 325 | glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) |
| 326 | enddef |
| 327 | |
| 328 | def Test_globpath() |
| 329 | globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim']) |
| 330 | enddef |
| 331 | |
| 332 | def Test_has() |
| 333 | has('eval', true)->assert_equal(1) |
| 334 | enddef |
| 335 | |
| 336 | def Test_hasmapto() |
| 337 | hasmapto('foobar', 'i', true)->assert_equal(0) |
| 338 | iabbrev foo foobar |
| 339 | hasmapto('foobar', 'i', true)->assert_equal(1) |
| 340 | iunabbrev foo |
| 341 | enddef |
| 342 | |
| 343 | def Test_index() |
| 344 | index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) |
| 345 | enddef |
| 346 | |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 347 | let s:number_one = 1 |
| 348 | let s:number_two = 2 |
| 349 | let s:string_keep = 'keep' |
| 350 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 351 | def Test_insert() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 352 | var l = insert([2, 1], 3) |
| 353 | var res = 0 |
| 354 | for n in l |
| 355 | res += n |
| 356 | endfor |
| 357 | res->assert_equal(6) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 358 | |
| 359 | assert_equal([1, 2, 3], insert([2, 3], 1)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 360 | assert_equal([1, 2, 3], insert([2, 3], s:number_one)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 361 | assert_equal([1, 2, 3], insert([1, 2], 3, 2)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 362 | assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 363 | assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) |
| 364 | assert_equal(0z1234, insert(0z34, 0x12)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame^] | 365 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 366 | CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) |
| 367 | CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 368 | enddef |
| 369 | |
| 370 | def Test_keys_return_type() |
| 371 | const var: list<string> = #{a: 1, b: 2}->keys() |
| 372 | var->assert_equal(['a', 'b']) |
| 373 | enddef |
| 374 | |
| 375 | def Test_list2str_str2list_utf8() |
| 376 | var s = "\u3042\u3044" |
| 377 | var l = [0x3042, 0x3044] |
| 378 | str2list(s, true)->assert_equal(l) |
| 379 | list2str(l, true)->assert_equal(s) |
| 380 | enddef |
| 381 | |
| 382 | def SID(): number |
| 383 | return expand('<SID>') |
| 384 | ->matchstr('<SNR>\zs\d\+\ze_$') |
| 385 | ->str2nr() |
| 386 | enddef |
| 387 | |
| 388 | def Test_maparg() |
| 389 | var lnum = str2nr(expand('<sflnum>')) |
| 390 | map foo bar |
| 391 | maparg('foo', '', false, true)->assert_equal(#{ |
| 392 | lnum: lnum + 1, |
| 393 | script: 0, |
| 394 | mode: ' ', |
| 395 | silent: 0, |
| 396 | noremap: 0, |
| 397 | lhs: 'foo', |
| 398 | lhsraw: 'foo', |
| 399 | nowait: 0, |
| 400 | expr: 0, |
| 401 | sid: SID(), |
| 402 | rhs: 'bar', |
| 403 | buffer: 0}) |
| 404 | unmap foo |
| 405 | enddef |
| 406 | |
| 407 | def Test_mapcheck() |
| 408 | iabbrev foo foobar |
| 409 | mapcheck('foo', 'i', true)->assert_equal('foobar') |
| 410 | iunabbrev foo |
| 411 | enddef |
| 412 | |
| 413 | def Test_maparg_mapset() |
| 414 | nnoremap <F3> :echo "hit F3"<CR> |
| 415 | var mapsave = maparg('<F3>', 'n', false, true) |
| 416 | mapset('n', false, mapsave) |
| 417 | |
| 418 | nunmap <F3> |
| 419 | enddef |
| 420 | |
| 421 | def Test_nr2char() |
| 422 | nr2char(97, true)->assert_equal('a') |
| 423 | enddef |
| 424 | |
| 425 | def Test_readdir() |
| 426 | eval expand('sautest')->readdir({e -> e[0] !=# '.'}) |
| 427 | eval expand('sautest')->readdirex({e -> e.name[0] !=# '.'}) |
| 428 | enddef |
| 429 | |
| 430 | def Test_remove_return_type() |
| 431 | var l = remove(#{one: [1, 2], two: [3, 4]}, 'one') |
| 432 | var res = 0 |
| 433 | for n in l |
| 434 | res += n |
| 435 | endfor |
| 436 | res->assert_equal(3) |
| 437 | enddef |
| 438 | |
| 439 | def Test_reverse_return_type() |
| 440 | var l = reverse([1, 2, 3]) |
| 441 | var res = 0 |
| 442 | for n in l |
| 443 | res += n |
| 444 | endfor |
| 445 | res->assert_equal(6) |
| 446 | enddef |
| 447 | |
| 448 | def Test_search() |
| 449 | new |
| 450 | setline(1, ['foo', 'bar']) |
| 451 | var val = 0 |
| 452 | # skip expr returns boolean |
| 453 | search('bar', 'W', 0, 0, {-> val == 1})->assert_equal(2) |
| 454 | :1 |
| 455 | search('bar', 'W', 0, 0, {-> val == 0})->assert_equal(0) |
| 456 | # skip expr returns number, only 0 and 1 are accepted |
| 457 | :1 |
| 458 | search('bar', 'W', 0, 0, {-> 0})->assert_equal(2) |
| 459 | :1 |
| 460 | search('bar', 'W', 0, 0, {-> 1})->assert_equal(0) |
| 461 | assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:') |
| 462 | assert_fails("search('bar', '', 0, 0, {-> -1})", 'E1023:') |
| 463 | enddef |
| 464 | |
| 465 | def Test_searchcount() |
| 466 | new |
| 467 | setline(1, "foo bar") |
| 468 | :/foo |
| 469 | searchcount(#{recompute: true}) |
| 470 | ->assert_equal(#{ |
| 471 | exact_match: 1, |
| 472 | current: 1, |
| 473 | total: 1, |
| 474 | maxcount: 99, |
| 475 | incomplete: 0}) |
| 476 | bwipe! |
| 477 | enddef |
| 478 | |
| 479 | def Test_searchdecl() |
| 480 | searchdecl('blah', true, true)->assert_equal(1) |
| 481 | enddef |
| 482 | |
| 483 | def Test_setbufvar() |
| 484 | setbufvar(bufnr('%'), '&syntax', 'vim') |
| 485 | &syntax->assert_equal('vim') |
| 486 | setbufvar(bufnr('%'), '&ts', 16) |
| 487 | &ts->assert_equal(16) |
| 488 | settabwinvar(1, 1, '&syntax', 'vam') |
| 489 | &syntax->assert_equal('vam') |
| 490 | settabwinvar(1, 1, '&ts', 15) |
| 491 | &ts->assert_equal(15) |
| 492 | setlocal ts=8 |
| 493 | |
| 494 | setbufvar('%', 'myvar', 123) |
| 495 | getbufvar('%', 'myvar')->assert_equal(123) |
| 496 | enddef |
| 497 | |
| 498 | def Test_setloclist() |
| 499 | var items = [#{filename: '/tmp/file', lnum: 1, valid: true}] |
| 500 | var what = #{items: items} |
| 501 | setqflist([], ' ', what) |
| 502 | setloclist(0, [], ' ', what) |
| 503 | enddef |
| 504 | |
| 505 | def Test_setreg() |
| 506 | setreg('a', ['aaa', 'bbb', 'ccc']) |
| 507 | var reginfo = getreginfo('a') |
| 508 | setreg('a', reginfo) |
| 509 | getreginfo('a')->assert_equal(reginfo) |
| 510 | enddef |
| 511 | |
| 512 | def Test_spellsuggest() |
| 513 | if !has('spell') |
| 514 | MissingFeature 'spell' |
| 515 | else |
| 516 | spellsuggest('marrch', 1, true)->assert_equal(['March']) |
| 517 | endif |
| 518 | enddef |
| 519 | |
| 520 | def Test_sort_return_type() |
| 521 | var res: list<number> |
| 522 | res = [1, 2, 3]->sort() |
| 523 | enddef |
| 524 | |
| 525 | def Test_sort_argument() |
| 526 | var res = ['b', 'a', 'c']->sort('i') |
| 527 | res->assert_equal(['a', 'b', 'c']) |
| 528 | enddef |
| 529 | |
| 530 | def Test_split() |
| 531 | split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', '']) |
| 532 | enddef |
| 533 | |
| 534 | def Test_str2nr() |
| 535 | str2nr("1'000'000", 10, true)->assert_equal(1000000) |
| 536 | enddef |
| 537 | |
| 538 | def Test_strchars() |
| 539 | strchars("A\u20dd", true)->assert_equal(1) |
| 540 | enddef |
| 541 | |
| 542 | def Test_submatch() |
| 543 | var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' |
| 544 | var Rep = {-> range(10)->map({_, v -> submatch(v, true)})->string()} |
| 545 | var actual = substitute('A123456789', pat, Rep, '') |
| 546 | var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" |
| 547 | actual->assert_equal(expected) |
| 548 | enddef |
| 549 | |
| 550 | def Test_synID() |
| 551 | new |
| 552 | setline(1, "text") |
| 553 | synID(1, 1, true)->assert_equal(0) |
| 554 | bwipe! |
| 555 | enddef |
| 556 | |
| 557 | def Test_term_gettty() |
| 558 | if !has('terminal') |
| 559 | MissingFeature 'terminal' |
| 560 | else |
| 561 | var buf = Run_shell_in_terminal({}) |
| 562 | term_gettty(buf, true)->assert_notequal('') |
| 563 | StopShellInTerminal(buf) |
| 564 | endif |
| 565 | enddef |
| 566 | |
| 567 | def Test_term_start() |
| 568 | if !has('terminal') |
| 569 | MissingFeature 'terminal' |
| 570 | else |
| 571 | botright new |
| 572 | var winnr = winnr() |
| 573 | term_start(&shell, #{curwin: true}) |
| 574 | winnr()->assert_equal(winnr) |
| 575 | bwipe! |
| 576 | endif |
| 577 | enddef |
| 578 | |
| 579 | def Test_timer_paused() |
| 580 | var id = timer_start(50, {-> 0}) |
| 581 | timer_pause(id, true) |
| 582 | var info = timer_info(id) |
| 583 | info[0]['paused']->assert_equal(1) |
| 584 | timer_stop(id) |
| 585 | enddef |
| 586 | |
| 587 | def Test_win_splitmove() |
| 588 | split |
| 589 | win_splitmove(1, 2, #{vertical: true, rightbelow: true}) |
| 590 | close |
| 591 | enddef |
| 592 | |
| 593 | |
| 594 | " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |