robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8832c381e1
master
1" Tests for register operations 2 3source check.vim 4source view_util.vim 5 6" This test must be executed first to check for empty and unset registers. 7func Test_aaa_empty_reg_test () 8call assert_fails ( 'normal @@' , 'E748:' ) 9call assert_fails ( 'normal @%' , 'E354:' ) 10call assert_fails ( 'normal @#' , 'E354:' ) 11call assert_fails ( 'normal @!' , 'E354:' ) 12call assert_fails ( 'normal @:' , 'E30:' ) 13call assert_fails ( 'normal @.' , 'E29:' ) 14call assert_fails ( 'put /' , 'E35:' ) 15call assert_fails ( 'put .' , 'E29:' ) 16endfunc 17 18func Test_yank_shows_register () 19enew 20set report = 0 21call setline ( 1 , [ 'foo' , 'bar' ]) 22" Line-wise 23exe 'norm! yy' 24call assert_equal ( '1 line yanked' , v: statusmsg ) 25exe 'norm! "zyy' 26call assert_equal ( '1 line yanked into "z' , v: statusmsg ) 27exe 'norm! yj' 28call assert_equal ( '2 lines yanked' , v: statusmsg ) 29exe 'norm! "zyj' 30call assert_equal ( '2 lines yanked into "z' , v: statusmsg ) 31 32" Block-wise 33exe "norm! \<C-V>y" 34call assert_equal ( 'block of 1 line yanked' , v: statusmsg ) 35exe "norm! \<C-V>\"zy" 36call assert_equal ( 'block of 1 line yanked into "z' , v: statusmsg ) 37exe "norm! \<C-V>jy" 38call assert_equal ( 'block of 2 lines yanked' , v: statusmsg ) 39exe "norm! \<C-V>j\"zy" 40call assert_equal ( 'block of 2 lines yanked into "z' , v: statusmsg ) 41 42bwipe ! 43endfunc 44 45func Test_display_registers () 46" Disable clipboard 47let save_clipboard = get ( g:, 'clipboard' , {}) 48let g: clipboard = {} 49defer execute('let g:clipboard = save_clipboard') 50 51e file1 52e file2 53call setline ( 1 , [ 'foo' , 'bar' ]) 54/ bar 55exe 'norm! y2l"axx' 56call feedkeys ( "i\<C-R>=2*4\n\<esc>" ) 57call feedkeys ( ":ls\n" , 'xt' ) 58 59" these commands work in the sandbox 60let a = execute ( 'sandbox display' ) 61" When X11 connection is not available, there is a warning W23 62" filter this out (we could also run the :display command twice) 63let a = substitute ( a , 'W23.*0\n' , '' , '' ) 64let b = execute ( 'sandbox registers' ) 65 66call assert_equal ( a , b ) 67call assert_match ( '^\nType Name Content\n' 68 \. ' c "" a\n' 69 \. ' c "0 ba\n' 70 \. ' c "a b\n' 71 \. '.*' 72 \. ' c "- a\n' 73 \. '.*' 74 \. ' c ": ls\n' 75 \. ' c "% file2\n' 76 \. ' c "# file1\n' 77 \. ' c "/ bar\n' 78 \. ' c "= 2\*4' , a ) 79 80let a = execute ( 'registers a' ) 81call assert_match ( '^\nType Name Content\n' 82 \. ' c "a b' , a ) 83 84let a = execute ( 'registers :' ) 85call assert_match ( '^\nType Name Content\n' 86 \. ' c ": ls' , a ) 87 88let a = execute ( 'registers %' ) 89call assert_match ( '^\nType Name Content\n' 90 \. ' c "% file2' , a ) 91 92let a = execute ( 'registers #' ) 93call assert_match ( '^\nType Name Content\n' 94 \. ' c "# file1' , a ) 95 96bwipe ! 97endfunc 98 99func Test_register_one () 100" delete a line goes into register one 101new 102call setline ( 1 , "one" ) 103normal dd 104call assert_equal ( "one\n" , @1) 105 106" delete a word does not change register one, does change "- 107call setline ( 1 , "two" ) 108normal de 109call assert_equal ( "one\n" , @1) 110call assert_equal ( "two" , @-) 111 112" delete a word with a register does not change register one 113call setline ( 1 , "three" ) 114normal "ade 115call assert_equal ( "three" , @a) 116call assert_equal ( "one\n" , @1) 117 118" delete a word with register DOES change register one with one of a list of 119" operators 120" % 121call setline ( 1 , [ "(12)3" ]) 122normal "ad% 123call assert_equal ( "(12)" , @a) 124call assert_equal ( "(12)" , @1) 125 126" ( 127call setline ( 1 , [ "first second" ]) 128normal $"ad( 129call assert_equal ( "first secon" , @a) 130call assert_equal ( "first secon" , @1) 131 132" ) 133call setline ( 1 , [ "First Second." ]) 134normal gg0"ad) 135call assert_equal ( "First Second." , @a) 136call assert_equal ( "First Second." , @1) 137 138" ` 139call setline ( 1 , [ "start here." ]) 140normal gg0fhmx0"ad`x 141call assert_equal ( "start " , @a) 142call assert_equal ( "start " , @1) 143 144" / 145call setline ( 1 , [ "searchX" ]) 146exe "normal gg0\"ad/X\<CR>" 147call assert_equal ( "search" , @a) 148call assert_equal ( "search" , @1) 149 150" ? 151call setline ( 1 , [ "Ysearch" ]) 152exe "normal gg$\"ad?Y\<CR>" 153call assert_equal ( "Ysearc" , @a) 154call assert_equal ( "Ysearc" , @1) 155 156" n 157call setline ( 1 , [ "Ynext" ]) 158normal gg$"adn 159call assert_equal ( "Ynex" , @a) 160call assert_equal ( "Ynex" , @1) 161 162" N 163call setline ( 1 , [ "prevY" ]) 164normal gg0"adN 165call assert_equal ( "prev" , @a) 166call assert_equal ( "prev" , @1) 167 168" } 169call setline ( 1 , [ "one" , "" ]) 170normal gg0"ad} 171call assert_equal ( "one\n" , @a) 172call assert_equal ( "one\n" , @1) 173 174" { 175call setline ( 1 , [ "" , "two" ]) 176normal 2G$"ad{ 177call assert_equal ( "\ntw" , @a) 178call assert_equal ( "\ntw" , @1) 179 180bwipe ! 181endfunc 182 183func Test_recording_status_in_ex_line () 184set noruler 185norm qx 186redraw ! 187call assert_equal ( 'recording @x' , Screenline ( & lines )) 188set shortmess = q 189redraw ! 190call assert_equal ( '' , Screenline ( & lines )) " Nvim: shm+=q fully hides message 191set shortmess & 192norm q 193redraw ! 194call assert_equal ( '' , Screenline ( & lines )) 195set ruler 196norm qx 197redraw ! 198call assert_match ( 'recording @x\s*0,0-1\s*All' , Screenline ( & lines )) 199set shortmess = q 200redraw ! 201call assert_match ( '\s*0,0-1\s*All' , Screenline ( & lines )) " Nvim: shm+=q fully hides 202set shortmess & 203norm q 204redraw ! 205call assert_match ( '\s*0,0-1\s*All' , Screenline ( & lines )) 206endfunc 207 208" Check that replaying a typed sequence does not use an Esc and following 209" characters as an escape sequence. 210func Test_recording_esc_sequence () 211new 212try 213let save_F2 = & t_F2 214catch 215endtry 216let t_F2 = "\<Esc>OQ" 217call feedkeys ( "qqiTest\<Esc>" , "xt" ) 218call feedkeys ( "OQuirk\<Esc>q" , "xt" ) 219call feedkeys ( "Go\<Esc>@q" , "xt" ) 220call assert_equal ([ 'Quirk' , 'Test' , 'Quirk' , 'Test' ], getline ( 1 , 4 )) 221bwipe ! 222if exists ( 'save_F2' ) 223let & t_F2 = save_F2 224else 225set t_F2 = 226endif 227endfunc 228 229func Test_recording_with_select_mode () 230new 231call feedkeys ( "qacc12345\<Esc>gH98765\<Esc>q" , "tx" ) 232call assert_equal ( "98765" , getline ( 1 )) 233call assert_equal ( "cc12345\<Esc>gH98765\<Esc>" , @a) 234call setline ( 1 , 'asdf' ) 235normal ! @a 236call assert_equal ( "98765" , getline ( 1 )) 237bwipe ! 238endfunc 239 240func Run_test_recording_with_select_mode_utf8 () 241new 242 243" Test with different text lengths: 5, 7, 9, 11, 13, 15, to check that 244" a character isn't split between two buffer blocks. 245for s in [ '12345' , '口=口' , '口口口' , '口=口=口' , '口口=口口' , '口口口口口' ] 246" 0x80 is K_SPECIAL 247" 0x9B is CSI 248" 哦: 0xE5 0x93 0xA6 249" 洛: 0xE6 0xB4 0x9B 250" 固: 0xE5 0x9B 0xBA 251" 四: 0xE5 0x9B 0x9B 252" 最: 0xE6 0x9C 0x80 253" 倒: 0xE5 0x80 0x92 254" 倀: 0xE5 0x80 0x80 255for c in [ '哦' , '洛' , '固' , '四' , '最' , '倒' , '倀' ] 256call setline ( 1 , 'asdf' ) 257call feedkeys ( $ "qacc{s}\<Esc>gH{c}\<Esc>q", "tx") 258call assert_equal ( c , getline ( 1 )) 259call assert_equal ( $ "cc{s}\<Esc>gH{c}\<Esc>", @a) 260call setline ( 1 , 'asdf' ) 261normal ! @a 262call assert_equal ( c , getline ( 1 )) 263 264" Test with Shift modifier. 265let shift_c = eval ( $ '"\<S-{c}>"') 266call setline ( 1 , 'asdf' ) 267call feedkeys ( $ "qacc{s}\<Esc>gH{shift_c}\<Esc>q", "tx") 268call assert_equal ( c , getline ( 1 )) 269call assert_equal ( $ "cc{s}\<Esc>gH{shift_c}\<Esc>", @a) 270call setline ( 1 , 'asdf' ) 271normal ! @a 272call assert_equal ( c , getline ( 1 )) 273endfor 274endfor 275 276bwipe ! 277endfunc 278 279func Test_recording_with_select_mode_utf8 () 280call Run_test_recording_with_select_mode_utf8 () 281endfunc 282 283" This must be done as one of the last tests, because it starts the GUI, which 284" cannot be undone. 285func Test_zz_recording_with_select_mode_utf8_gui () 286CheckCanRunGui 287 288gui -f 289call Run_test_recording_with_select_mode_utf8 () 290endfunc 291 292func Test_recording_append_utf8 () 293new 294 295let keys = "cc哦洛固四最倒倀\<Esc>0" 296call feedkeys ( $ 'qr{keys}q', 'xt') 297call assert_equal ( keys , @r) 298 299let morekeys = "A…foobar\<Esc>0" 300call feedkeys ( $ 'qR{morekeys}q', 'xt') 301call assert_equal ( keys .. morekeys , @r) 302 303bwipe ! 304endfunc 305 306func Test_recording_with_super_mod () 307if "\<D-j>" [ -1 :] == '>' 308throw 'Skipped: <D- modifier not supported' 309endif 310 311nnoremap < D-j > < Ignore > 312let s = repeat ( "\<D-j>" , 1000 ) 313" This used to crash Vim 314call feedkeys ( $ 'qr{s}q', 'tx') 315call assert_equal ( s , @r) 316nunmap <D-j> 317endfunc 318 319" Test for executing the last used register (@) 320func Test_last_used_exec_reg () 321" Test for the @: command 322let a = '' 323call feedkeys ( ":let a ..= 'Vim'\<CR>" , 'xt' ) 324normal @: 325call assert_equal ( 'VimVim' , a ) 326 327" Test for the @= command 328let x = '' 329let a = ":let x ..= 'Vim'\<CR>" 330exe "normal @=a\<CR>" 331normal @@ 332call assert_equal ( 'VimVim' , x ) 333 334" Test for the @. command 335let a = '' 336call feedkeys ( "i:let a ..= 'Edit'\<CR>" , 'xt' ) 337normal @. 338normal @@ 339call assert_equal ( 'EditEdit' , a ) 340 341" Test for repeating the last command-line in visual mode 342call append ( 0 , 'register' ) 343normal gg 344let @r= '' 345call feedkeys ( "v:yank R\<CR>" , 'xt' ) 346call feedkeys ( "v@:" , 'xt' ) 347call assert_equal ( "\nregister\nregister\n" , @r) 348 349enew ! 350endfunc 351 352func Test_get_register () 353enew 354edit Xfile1 355edit Xfile2 356call assert_equal ( 'Xfile2' , getreg ( '%' )) 357call assert_equal ( 'Xfile1' , getreg ( '#' )) 358 359call feedkeys ( "iTwo\<Esc>" , 'xt' ) 360call assert_equal ( 'Two' , getreg ( '.' )) 361call assert_equal ( '' , getreg ( '_' )) 362call assert_beeps ( 'normal ":yy' ) 363call assert_beeps ( 'normal "%yy' ) 364call assert_beeps ( 'normal ".yy' ) 365 366call assert_equal ( '' , getreg ( "\<C-F>" )) 367call assert_equal ( '' , getreg ( "\<C-W>" )) 368call assert_equal ( '' , getreg ( "\<C-L>" )) 369" Change the last used register to '"' for the next test 370normal ! ""yy 371let @"= 'happy' 372call assert_equal ( 'happy' , getreg ()) 373call assert_equal ( 'happy' , getreg ( '' )) 374 375call assert_equal ( '' , getregtype ( '!' )) 376call assert_fails ( 'echo getregtype([])' , 'E730:' ) 377call assert_equal ( 'v' , getregtype ()) 378call assert_equal ( 'v' , getregtype ( '' )) 379 380" Test for inserting an invalid register content 381call assert_beeps ( 'exe "normal i\<C-R>!"' ) 382 383" Test for inserting a register with multiple lines 384call deletebufline ( '' , 1 , '$' ) 385call setreg ( 'r' , [ 'a' , 'b' ]) 386exe "normal i\<C-R>r" 387call assert_equal ([ 'a' , 'b' , '' ], getline ( 1 , '$' )) 388 389" Test for inserting a multi-line register in the command line 390call feedkeys ( ":\<C-R>r\<Esc>" , 'xt' ) 391" Nvim: no trailing CR because of #6137 392" call assert_equal("a\rb\r", histget(':', -1)) 393call assert_equal ( "a\rb" , histget ( ':' , -1 )) 394 395call assert_fails ( 'let r = getreg("=", [])' , 'E745:' ) 396call assert_fails ( 'let r = getreg("=", 1, [])' , 'E745:' ) 397enew ! 398 399" Using a register in operator-pending mode should fail 400call assert_beeps ( 'norm! c"' ) 401endfunc 402 403func Test_set_register () 404call assert_fails ( "call setreg('#', 200)" , 'E86:' ) 405" call assert_fails("call setreg('a', test_unknown())", 'E908:') 406 407edit Xfile_alt_1 408let b1 = bufnr ( '' ) 409edit Xfile_alt_2 410let b2 = bufnr ( '' ) 411edit Xfile_alt_3 412let b3 = bufnr ( '' ) 413call setreg ( '#' , 'alt_1' ) 414call assert_equal ( 'Xfile_alt_1' , getreg ( '#' )) 415call setreg ( '#' , b2 ) 416call assert_equal ( 'Xfile_alt_2' , getreg ( '#' )) 417call setreg ( '#' , '' ) 418call assert_equal ( '' , getreg ( '#' )) 419call setreg ( '#' , 'alt_1' ) 420let @#= '' 421call assert_equal ( '' , getreg ( '#' )) 422 423let ab = 'regwrite' 424call setreg ( '=' , '' ) 425call setreg ( '=' , 'a' , 'a' ) 426call setreg ( '=' , 'b' , 'a' ) 427call assert_equal ( 'regwrite' , getreg ( '=' )) 428 429" Test for setting a list of lines to special registers 430call setreg ( '/' , []) 431call assert_equal ( '' , @/) 432call setreg ( '=' , []) 433call assert_equal ( '' , @=) 434call assert_fails ( "call setreg('/', ['a', 'b'])" , 'E883:' ) 435call assert_fails ( "call setreg('=', ['a', 'b'])" , 'E883:' ) 436call assert_fails ( "call setreg('#', ['a', 'b'])" , 'E883:' ) 437call assert_equal ( 0 , setreg ( '_' , [ 'a' , 'b' ])) 438 439" Test for recording to a invalid register 440call assert_beeps ( 'normal q$' ) 441 442" Appending to a register when recording 443call append ( 0 , "text for clipboard test" ) 444normal gg 445call feedkeys ( 'qrllq' , 'xt' ) 446call feedkeys ( 'qRhhq' , 'xt' ) 447call assert_equal ( 'llhh' , getreg ( 'r' )) 448 449" Appending a list of characters to a register from different lines 450let @r= '' 451call append ( 0 , [ 'abcdef' , '123456' ]) 452normal gg"ry3l 453call cursor ( 2 , 4 ) 454normal "Ry3l 455call assert_equal ( 'abc456' , @r) 456 457" Test for gP with multiple lines selected using characterwise motion 458 %delete 459call append ( 0 , [ 'vim editor' , 'vim editor' ]) 460let @r= '' 461exe "normal ggwy/vim /e\<CR>gP" 462call assert_equal ([ 'vim editor' , 'vim editor' , 'vim editor' ], getline ( 1 , 3 )) 463 464" Test for gP with . register 465 %delete 466normal iabc 467normal ".gp 468call assert_equal ( 'abcabc' , getline ( 1 )) 469normal 0".gP 470call assert_equal ( 'abcabcabc' , getline ( 1 )) 471 472let @"= '' 473call setreg ( '' , '1' ) 474call assert_equal ( '1' , @") 475call setreg ( '@' , '2' ) 476call assert_equal ( '2' , @") 477 478enew ! 479endfunc 480 481" Test for blockwise register width calculations 482func Test_set_register_blockwise_width () 483" Test for regular calculations and overriding the width 484call setreg ( 'a' , "12\n1234\n123" , 'b' ) 485call assert_equal ( "\<c-v>4" , getreginfo ( 'a' ). regtype ) 486call setreg ( 'a' , "12\n1234\n123" , 'b1' ) 487call assert_equal ( "\<c-v>1" , getreginfo ( 'a' ). regtype ) 488call setreg ( 'a' , "12\n1234\n123" , 'b6' ) 489call assert_equal ( "\<c-v>6" , getreginfo ( 'a' ). regtype ) 490 491" Test for Unicode parsing 492call setreg ( 'a' , "z😅😅z\n12345" , 'b' ) 493call assert_equal ( "\<c-v>6" , getreginfo ( 'a' ). regtype ) 494call setreg ( 'a' , [ "z😅😅z" , "12345" ], 'b' ) 495call assert_equal ( "\<c-v>6" , getreginfo ( 'a' ). regtype ) 496endfunc 497 498" Test for clipboard registers (* and +) 499func Test_clipboard_regs () 500throw 'skipped: needs clipboard=autoselect,autoselectplus' 501 502CheckNotGui 503CheckFeature clipboard_working 504 505new 506call append ( 0 , "text for clipboard test" ) 507normal gg"*yiw 508call assert_equal ( 'text' , getreg ( '*' )) 509normal gg2w"+yiw 510call assert_equal ( 'clipboard' , getreg ( '+' )) 511 512" Test for replacing the clipboard register contents 513set clipboard = unnamed 514let @*= 'food' 515normal ggviw"*p 516call assert_equal ( 'text' , getreg ( '*' )) 517call assert_equal ( 'food for clipboard test' , getline ( 1 )) 518normal ggviw"*p 519call assert_equal ( 'food' , getreg ( '*' )) 520call assert_equal ( 'text for clipboard test' , getline ( 1 )) 521 522" Test for replacing the selection register contents 523set clipboard = unnamedplus 524let @+= 'food' 525normal ggviw"+p 526call assert_equal ( 'text' , getreg ( '+' )) 527call assert_equal ( 'food for clipboard test' , getline ( 1 )) 528normal ggviw"+p 529call assert_equal ( 'food' , getreg ( '+' )) 530call assert_equal ( 'text for clipboard test' , getline ( 1 )) 531 532" Test for auto copying visually selected text to clipboard register 533call setline ( 1 , "text for clipboard test" ) 534let @*= '' 535set clipboard = autoselect 536normal ggwwviwy 537call assert_equal ( 'clipboard' , @*) 538 539" Test for auto copying visually selected text to selection register 540let @+= '' 541set clipboard = autoselectplus 542normal ggwviwy 543call assert_equal ( 'for' , @+) 544 545set clipboard & vim 546bwipe ! 547endfunc 548 549" Test for restarting the current mode (insert or (virtual) replace) after 550" executing the contents of a register 551func Test_exec_reg_restart_mode () 552new 553 554let @r= "ivim \<Esc>" 555 556call setline ( 1 , 'editor' ) 557normal gg 558call feedkeys ( "i\<C-O>@r\<C-R>=mode(1)\<CR>" , 'xt' ) 559call assert_equal ( 'vimi editor' , getline ( 1 )) 560 561call setline ( 1 , 'editor' ) 562normal gg 563call feedkeys ( "R\<C-O>@r\<C-R>=mode(1)\<CR>" , 'xt' ) 564call assert_equal ( 'vimReditor' , getline ( 1 )) 565 566call setline ( 1 , 'editor' ) 567normal gg 568call feedkeys ( "gR\<C-O>@r\<C-R>=mode(1)\<CR>" , 'xt' ) 569call assert_equal ( 'vimRvditor' , getline ( 1 )) 570 571" If the register doesn't return to Normal mode, Vim should stay in whatever 572" mode the register ends up with, and should not insert extra text. #20085 573for [ s0 , expected ] in 574 \[[ 'i' , 'vim editor,i' ], [ 'R' , 'vim or,R' ], [ 'gR' , 'vim or,Rv' ]] 575let @r= $ "{s0}vim " 576for s1 in [ 'i' , 'R' , 'gR' ] 577call setline ( 1 , 'editor' ) 578normal gg 579call feedkeys ( $ "{s1}\<C-O>@r\<End>,\<C-R>=mode(1)\<CR>", 'xt') 580call assert_equal ( expected , getline ( 1 )) 581endfor 582endfor 583 584bwipe ! 585endfunc 586 587" Test for executing a register using :@ command 588func Test_execute_register () 589call setreg ( 'r' , []) 590call assert_beeps ( '@r' ) 591let i = 1 592let @q= 'let i+= 1' 593 @q 594 @ 595call assert_equal ( 3 , i ) 596 597" try to execute expression register and use a backspace to cancel it 598new 599call feedkeys ( "@=\<BS>ax\<CR>y" , 'xt' ) 600call assert_equal ([ 'x' , 'y' ], getline ( 1 , '$' )) 601bw ! 602 603" cannot execute a register in operator pending mode 604call assert_beeps ( 'normal! c@r' ) 605endfunc 606 607" Test for getting register info 608func Test_get_reginfo () 609enew 610call setline ( 1 , [ 'foo' , 'bar' ]) 611 612exe 'norm! "zyy' 613let info = getreginfo ( '"' ) 614call assert_equal ( 'z' , info . points_to ) 615call setreg ( 'y' , 'baz' ) 616call assert_equal ( 'z' , getreginfo ( '' ). points_to ) 617call setreg ( 'y' , { 'isunnamed' : v: true }) 618call assert_equal ( 'y' , getreginfo ( '"' ). points_to ) 619 620exe '$put' 621call assert_equal ( getreg ( 'y' ), getline ( 3 )) 622call setreg ( '' , 'qux' ) 623call assert_equal ( '0' , getreginfo ( '' ). points_to ) 624call setreg ( 'x' , 'quux' ) 625call assert_equal ( '0' , getreginfo ( '' ). points_to ) 626 627let info = getreginfo ( '' ) 628call assert_equal ( getreg ( '' , 1 , 1 ), info . regcontents ) 629call assert_equal ( getregtype ( '' ), info . regtype ) 630 631exe "norm! 0\<c-v>e" .. '"zy' 632let info = getreginfo ( 'z' ) 633call assert_equal ( getreg ( 'z' , 1 , 1 ), info . regcontents ) 634call assert_equal ( getregtype ( 'z' ), info . regtype ) 635call assert_equal ( 1 , + info . isunnamed ) 636 637let info = getreginfo ( '"' ) 638call assert_equal ( 'z' , info . points_to ) 639 640let @a= "a1b2" 641nnoremap < F2 > <Cmd> let g: RegInfo = getreginfo () <CR> 642exe "normal \"a\<F2>" 643call assert_equal ({ 'regcontents' : [ 'a1b2' ], 'isunnamed' : v: false , 644 \'regtype' : 'v' }, g: RegInfo ) 645nunmap <F2> 646unlet g: RegInfo 647 648" The type of "isunnamed" was VAR_SPECIAL but should be VAR_BOOL. Can only 649" be noticed when using json_encod(). 650call setreg ( 'a' , 'foo' ) 651let reginfo = getreginfo ( 'a' ) 652let expected = #{ regcontents : [ 'foo' ], isunnamed : v: false , regtype : 'v' } 653call assert_equal ( json_encode ( expected ), json_encode ( reginfo )) 654 655bwipe ! 656endfunc 657 658" Test for restoring register with dict from getreginfo 659func Test_set_register_dict () 660enew ! 661 662call setreg ( '"' , #{ regcontents : [ 'one' , 'two' ], 663 \regtype : 'V' , points_to : 'z' }) 664call assert_equal ([ 'one' , 'two' ], getreg ( '"' , 1 , 1 )) 665let info = getreginfo ( '"' ) 666call assert_equal ( 'z' , info . points_to ) 667call assert_equal ( 'V' , info . regtype ) 668call assert_equal ( 1 , + getreginfo ( 'z' ). isunnamed ) 669 670call setreg ( 'x' , #{ regcontents : [ 'three' , 'four' ], 671 \regtype : 'v' , isunnamed : v: true }) 672call assert_equal ([ 'three' , 'four' ], getreg ( '"' , 1 , 1 )) 673let info = getreginfo ( '"' ) 674call assert_equal ( 'x' , info . points_to ) 675call assert_equal ( 'v' , info . regtype ) 676call assert_equal ( 1 , + getreginfo ( 'x' ). isunnamed ) 677 678call setreg ( 'y' , #{ regcontents : 'five' , 679 \regtype : "\<c-v>" , isunnamed : v: false }) 680call assert_equal ( "\<c-v>4" , getreginfo ( 'y' ). regtype ) 681call assert_equal ( 0 , + getreginfo ( 'y' ). isunnamed ) 682call assert_equal ([ 'three' , 'four' ], getreg ( '"' , 1 , 1 )) 683call assert_equal ( 'x' , getreginfo ( '"' ). points_to ) 684 685call setreg ( '"' , #{ regcontents : 'six' }) 686call assert_equal ( '0' , getreginfo ( '"' ). points_to ) 687call assert_equal ( 1 , + getreginfo ( '0' ). isunnamed ) 688call assert_equal ([ 'six' ], getreginfo ( '0' ). regcontents ) 689call assert_equal ([ 'six' ], getreginfo ( '"' ). regcontents ) 690 691let @x= 'one' 692call setreg ( 'x' , {}) 693call assert_equal ( 1 , len ( split ( execute ( 'reg x' ), '\n' ))) 694 695call assert_fails ( "call setreg('0', #{regtype: 'V'}, 'v')" , 'E118:' ) 696call assert_fails ( "call setreg('0', #{regtype: 'X'})" , 'E475:' ) 697call assert_fails ( "call setreg('0', #{regtype: 'vy'})" , 'E475:' ) 698 699bwipe ! 700endfunc 701 702func Test_v_register () 703enew 704call setline ( 1 , 'nothing' ) 705 706func s: Put () 707let s: register = v: register 708exec 'normal! "' .. v: register .. 'P' 709endfunc 710nnoremap <buffer> < plug > (test) :< c-u > call s:Put()< cr > 711xnoremap <buffer> < plug > (test) :< c-u > call s:Put()< cr > 712nmap <buffer> S< plug > (test) 713xmap <buffer> S< plug > (test) 714 715let @z= "testz\n" 716let @"= "test@\n" 717 718let s: register = '' 719call feedkeys ( '"_ddS' , 'mx' ) 720call assert_equal ( '"' , s: register ) " fails before 8.2.0929 721call assert_equal ( 'test@' , getline ( '.' )) " fails before 8.2.0929 722 723let s: register = '' 724call feedkeys ( 'V"_dS' , 'mx' ) 725call assert_equal ( '"' , s: register ) 726call assert_equal ( 'test@' , getline ( '.' )) 727 728let s: register = '' 729call feedkeys ( '"zS' , 'mx' ) 730call assert_equal ( 'z' , s: register ) 731call assert_equal ( 'testz' , getline ( '.' )) 732 733let s: register = '' 734call feedkeys ( '"zSS' , 'mx' ) 735call assert_equal ( '"' , s: register ) 736call assert_equal ( 'test@' , getline ( '.' )) 737 738let s: register = '' 739call feedkeys ( "\"z\<Ignore>S" , 'mx' ) 740call assert_equal ( 'z' , s: register ) 741call assert_equal ( 'testz' , getline ( '.' )) 742 743let s: register = '' 744call feedkeys ( '"_S' , 'mx' ) 745call assert_equal ( '_' , s: register ) 746 747let s: register = '' 748call feedkeys ( 'V"zS' , 'mx' ) 749call assert_equal ( 'z' , s: register ) 750call assert_equal ( 'testz' , getline ( '.' )) 751 752let s: register = '' 753call feedkeys ( 'V"zSS' , 'mx' ) 754call assert_equal ( '"' , s: register ) 755call assert_equal ( 'test@' , getline ( '.' )) 756 757let s: register = '' 758call feedkeys ( "V\"z\<Ignore>S" , 'mx' ) 759call assert_equal ( 'z' , s: register ) 760call assert_equal ( 'testz' , getline ( '.' )) 761 762let s: register = '' 763call feedkeys ( 'V"_S' , 'mx' ) 764call assert_equal ( '_' , s: register ) 765 766let s: register = '' 767normal "_ddS 768call assert_equal ( '"' , s: register ) " fails before 8.2.0929 769call assert_equal ( 'test@' , getline ( '.' )) " fails before 8.2.0929 770 771let s: register = '' 772normal V"_dS 773call assert_equal ( '"' , s: register ) 774call assert_equal ( 'test@' , getline ( '.' )) 775 776let s: register = '' 777execute 'normal "z:call' "s:Put()\n" 778call assert_equal ( 'z' , s: register ) 779call assert_equal ( 'testz' , getline ( '.' )) 780 781" Test operator and omap 782let @b= 'testb' 783func s: OpFunc (...) 784let s: register2 = v: register 785endfunc 786set opfunc = s:OpFunc 787 788normal "bg@l 789normal S 790call assert_equal ( '"' , s: register ) " fails before 8.2.0929 791call assert_equal ( 'b' , s: register2 ) 792 793func s: Motion () 794let s: register1 = v: register 795normal ! l 796endfunc 797onoremap <buffer> Q :< c-u > call s:Motion()< cr > 798 799normal "bg@Q 800normal S 801call assert_equal ( '"' , s: register ) 802call assert_equal ( 'b' , s: register1 ) 803call assert_equal ( '"' , s: register2 ) 804 805set opfunc & 806bwipe ! 807endfunc 808 809" Test for executing the contents of a register as an Ex command with line 810" continuation. 811func Test_execute_reg_as_ex_cmd () 812" Line continuation with just two lines 813let code =<< trim END 814let l = [ 815\ 1] 816END 817let @r= code ->join ( "\n" ) 818let l = [] 819 @r 820call assert_equal ([ 1 ], l ) 821 822" Line continuation with more than two lines 823let code =<< trim END 824let l = [ 825\ 1, 826\ 2, 827\ 3] 828END 829let @r= code ->join ( "\n" ) 830let l = [] 831 @r 832call assert_equal ([ 1 , 2 , 3 ], l ) 833 834" use comments interspersed with code 835let code =<< trim END 836let l = [ 837"\ one 838\ 1, 839"\ two 840\ 2, 841"\ three 842\ 3] 843END 844let @r= code ->join ( "\n" ) 845let l = [] 846 @r 847call assert_equal ([ 1 , 2 , 3 ], l ) 848 849" use line continuation in the middle 850let code =<< trim END 851let a = "one" 852let l = [ 853\ 1, 854\ 2] 855let b = "two" 856END 857let @r= code ->join ( "\n" ) 858let l = [] 859 @r 860call assert_equal ([ 1 , 2 ], l ) 861call assert_equal ( "one" , a ) 862call assert_equal ( "two" , b ) 863 864" only one line with a \ 865let @r= "\\let l = 1" 866call assert_fails ( '@r' , 'E10:' ) 867 868" only one line with a "\ 869let @r= ' "\ let i = 1' 870 @r 871call assert_false ( exists ( 'i' )) 872 873" first line also begins with a \ 874let @r= "\\let l = [\n\\ 1]" 875call assert_fails ( '@r' , 'E10:' ) 876 877" Test with a large number of lines 878let @r= "let str = \n" 879let @r..= repeat ( " \\ 'abcdefghijklmnopqrstuvwxyz' ..\n" , 312 ) 880let @r..= ' \ ""' 881 @r 882call assert_equal ( repeat ( 'abcdefghijklmnopqrstuvwxyz' , 312 ), str ) 883endfunc 884 885func Test_ve_blockpaste () 886new 887set ve = all 8880 put =['QWERTZ','ASDFGH'] 889call cursor ( 1 , 1 ) 890exe ":norm! \<C-V>3ljdP" 891call assert_equal ( 1 , col ( '.' )) 892call assert_equal ([ 'QWERTZ' , 'ASDFGH' ], getline ( 1 , 2 )) 893call cursor ( 1 , 1 ) 894exe ":norm! \<C-V>3ljd" 895call cursor ( 1 , 1 ) 896norm ! $3lP 897call assert_equal ( 5 , col ( '.' )) 898call assert_equal ([ 'TZ QWER' , 'GH ASDF' ], getline ( 1 , 2 )) 899set ve & vim 900bwipe ! 901endfunc 902 903func Test_insert_small_delete () 904new 905call setline ( 1 , [ 'foo foobar bar' ]) 906call cursor ( 1 , 1 ) 907exe ":norm! ciw'\<C-R>-'" 908call assert_equal ( "'foo' foobar bar" , getline ( 1 )) 909exe ":norm! w.w." 910call assert_equal ( "'foo' 'foobar' 'bar'" , getline ( 1 )) 911bwipe ! 912endfunc 913 914" Record in insert mode using CTRL-O 915func Test_record_in_insert_mode () 916new 917let @r= '' 918call setline ( 1 , [ 'foo' ]) 919call feedkeys ( "i\<C-O>qrbaz\<C-O>q" , 'xt' ) 920call assert_equal ( 'baz' , @r) 921bwipe ! 922endfunc 923 924func Test_record_in_select_mode () 925new 926call setline ( 1 , 'text' ) 927sil norm q00 928sil norm q 929call assert_equal ( '0ext' , getline ( 1 )) 930 931 %delete 932let @r= '' 933call setline ( 1 , [ 'abc' , 'abc' , 'abc' ]) 934smap < F2 > < Right > <Right > , 935call feedkeys ( "qrgh\<F2>Dk\<Esc>q" , 'xt' ) 936call assert_equal ( "gh\<F2>Dk\<Esc>" , @r) 937norm j0@rj0@@ 938call assert_equal ([ ',Dk' , ',Dk' , ',Dk' ], getline ( 1 , 3 )) 939sunmap <F2> 940 941bwipe ! 942endfunc 943 944" A mapping that ends recording should be removed from the recorded register. 945func Test_end_record_using_mapping () 946new 947call setline ( 1 , 'aaa' ) 948nnoremap s q 949call feedkeys ( 'safas' , 'tx' ) 950call assert_equal ( 'fa' , @a) 951nunmap s 952 953nnoremap xx q 954call feedkeys ( '0xxafaxx' , 'tx' ) 955call assert_equal ( 'fa' , @a) 956nunmap xx 957 958nnoremap xsx q 959call feedkeys ( '0qafaxsx' , 'tx' ) 960call assert_equal ( 'fa' , @a) 961nunmap xsx 962 963bwipe ! 964endfunc 965 966" Starting a new recording should work immediately after replaying a recording 967" that ends with a <Nop> mapping or a character search. 968func Test_end_reg_executing () 969new 970nnoremap s< Nop > 971let @a= 's' 972call feedkeys ( "@aqaq\<Esc>" , 'tx' ) 973call assert_equal ( '' , @a) 974call assert_equal ( '' , getline ( 1 )) 975 976call setline ( 1 , 'aaa' ) 977nnoremap s qa 978let @a= 'fa' 979call feedkeys ( "@asq\<Esc>" , 'tx' ) 980call assert_equal ( '' , @a) 981call assert_equal ( 'aaa' , getline ( 1 )) 982 983nunmap s 984bwipe ! 985endfunc 986 987func Test_reg_executing_in_range_normal () 988new 989set showcmd 990call setline ( 1 , range ( 10 )) 991let g: log = [] 992nnoremap s<Cmd> let g: log += [ reg_executing ()] <CR> 993let @r= 's' 994 995 %normal @r 996call assert_equal ( repeat ([ 'r' ], 10 ), g: log ) 997 998nunmap s 999unlet g: log 1000set showcmd & 1001bwipe ! 1002endfunc 1003 1004" An operator-pending mode mapping shouldn't be applied to keys typed in 1005" Insert mode immediately after a character search when replaying. 1006func Test_replay_charsearch_omap () 1007CheckFeature timers 1008 1009new 1010call setline ( 1 , 'foo[blah]' ) 1011onoremap , k 1012call timer_start ( 10 , { ->feedkeys ( ",bar\<Esc>q" , 't' )}) 1013call feedkeys ( 'qrct[' , 'xt!' ) 1014call assert_equal ( ',bar[blah]' , getline ( 1 )) 1015call assert_equal ( "ct[\<Ignore>,bar\<Esc>" , @r) 1016call assert_equal ( 'ct[<Ignore>,bar<Esc>' , keytrans ( @r)) 1017undo 1018call assert_equal ( 'foo[blah]' , getline ( 1 )) 1019call feedkeys ( '@r' , 'xt!' ) 1020call assert_equal ( ',bar[blah]' , getline ( 1 )) 1021 1022ounmap , 1023bwipe ! 1024endfunc 1025 1026" Make sure that y_append is correctly reset 1027" and the previous register is working as expected 1028func Test_register_y_append_reset () 1029new 1030call setline ( 1 , [ '1' , 1031 \'2 ----------------------------------------------------' , 1032 \'3' , 1033 \'4' , 1034 \'5 ----------------------------------------------------' , 1035 \'6' , 1036 \'7' , 1037 \'8 ----------------------------------------------------' , 1038 \'9' , 1039 \'10 aaaaaaa 4.' , 1040 \'11 Game Dbl-Figures Leaders:' , 1041 \'12 Player Pts FG% 3P% FT% RB AS BL ST TO PF EFF' , 1042 \'13 bbbbbbbbb 12 (50 /0 /67 )/ 7/ 3/ 0/ 2/ 3/ 4/+15' , 1043 \'14 cccccc 12 (57 /67 /100)/ 2/ 1/ 1/ 0/ 1/ 3/+12' , 1044 \'15 ddddddd 10 (63 /0 /0 )/ 1/ 3/ 0/ 3/ 5/ 3/ +9' , 1045 \'16 4 5-15 0-3 2-2 5-12 1-1 3-4 33.3 0.0 100 41.7 100 75 12 14' , 1046 \'17 F 23-55 2-10 9-11 23-52 3-13 26-29 41.8 20 81.8 44.2 23.1 89.7 57 75' , 1047 \'18 4 3 6 3 2 3 3 4 3 3 7 3 1 4 6 -1 -1 +2 -1 -2' , 1048 \'19 F 13 19 5 10 4 17 22 9 14 32 13 4 20 17 -1 -13 -4 -3 -3 +5' ]) 104911 1050exe "norm! \"a5dd" 1051norm ! j 1052exe "norm! \"bY" 1053norm ! 2j 1054exe "norm! \"BY" 1055norm ! 4k 1056norm ! 5dd 1057norm ! 3k 1058" The next put should put the content of the unnamed register, not of 1059" register b! 1060norm ! p 1061call assert_equal ([ '1' , 1062 \'2 ----------------------------------------------------' , 1063 \'3' , 1064 \'4' , 1065 \'5 ----------------------------------------------------' , 1066 \'6' , 1067 \'10 aaaaaaa 4.' , 1068 \'16 4 5-15 0-3 2-2 5-12 1-1 3-4 33.3 0.0 100 41.7 100 75 12 14' , 1069 \'17 F 23-55 2-10 9-11 23-52 3-13 26-29 41.8 20 81.8 44.2 23.1 89.7 57 75' , 1070 \'18 4 3 6 3 2 3 3 4 3 3 7 3 1 4 6 -1 -1 +2 -1 -2' , 1071 \'19 F 13 19 5 10 4 17 22 9 14 32 13 4 20 17 -1 -13 -4 -3 -3 +5' , 1072 \'7' , 1073 \'8 ----------------------------------------------------' , 1074 \'9' ], getline ( 1 , '$' )) 1075bwipe ! 1076endfunc 1077 1078func Test_insert_small_delete_replace_mode () 1079new 1080call setline ( 1 , [ 'foo' , 'bar' , 'foobar' , 'bar' ]) 1081let @- = 'foo' 1082call cursor ( 2 , 1 ) 1083exe ":norm! R\<C-R>-\<C-R>-" 1084call assert_equal ( 'foofoo' , getline ( 2 )) 1085call cursor ( 3 , 1 ) 1086norm ! D 1087call assert_equal ([ 'foo' , 'foofoo' , '' , 'bar' ], getline ( 1 , 4 )) 1088call cursor ( 4 , 2 ) 1089exe ":norm! R\<C-R>-ZZZZ" 1090call assert_equal ([ 'foo' , 'foofoo' , '' , 'bfoobarZZZZ' ], getline ( 1 , 4 )) 1091call cursor ( 1 , 1 ) 1092let @- = '' 1093exe ":norm! R\<C-R>-ZZZ" 1094call assert_equal ([ 'ZZZ' , 'foofoo' , '' , 'bfoobarZZZZ' ], getline ( 1 , 4 )) 1095let @- = 'βbβ' 1096call cursor ( 4 , 1 ) 1097exe ":norm! R\<C-R>-" 1098call assert_equal ([ 'ZZZ' , 'foofoo' , '' , 'βbβobarZZZZ' ], getline ( 1 , 4 )) 1099let @- = 'bβb' 1100call cursor ( 4 , 1 ) 1101exe ":norm! R\<C-R>-" 1102call assert_equal ([ 'ZZZ' , 'foofoo' , '' , 'bβbobarZZZZ' ], getline ( 1 , 4 )) 1103let @- = 'βbβ' 1104call cursor ( 4 , 1 ) 1105exe ":norm! R\<C-R>-" 1106call assert_equal ([ 'ZZZ' , 'foofoo' , '' , 'βbβobarZZZZ' ], getline ( 1 , 4 )) 1107bwipe ! 1108endfunc 1109 1110" this caused an illegal memory access and a crash 1111func Test_register_cursor_column_negative () 1112CheckRunVimInTerminal 1113let script =<< trim END 1114f XREGISTER 1115call setline(1, 'abcdef a') 1116call setreg("a", "\n", 'c') 1117call cursor(1, 7) 1118call feedkeys("i\<C-R>\<C-P>azyx$#\<esc>", 't') 1119END 1120call writefile ( script , 'XRegister123' , 'D' ) 1121let buf = RunVimInTerminal ( '-S XRegister123' , {}) 1122call term_sendkeys ( buf , "\<c-g>" ) 1123call WaitForAssert ({ ->assert_match ( 'XREGISTER' , term_getline ( buf , 19 ))}) 1124call StopVimInTerminal ( buf ) 1125endfunc 1126 1127" test '] mark generated by op_yank 1128func Test_mark_from_yank () 1129new 1130" double quote object 1131call setline ( 1 , 'test "yank" mark' ) 1132normal ! yi" 1133call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1134normal ! ya" 1135call assert_equal ([ 0 , 1 , 13 , 0 ], getpos ( "']" )) 1136" single quote object 1137call setline ( 1 , 'test ''yank'' mark' ) 1138normal ! yi' 1139call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1140normal ! ya' 1141call assert_equal ([ 0 , 1 , 13 , 0 ], getpos ( "']" )) 1142" paren object 1143call setline ( 1 , 'test (yank) mark' ) 1144call cursor ( 1 , 9 ) 1145normal ! yi( 1146call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1147call cursor ( 1 , 9 ) 1148normal ! ya( 1149call assert_equal ([ 0 , 1 , 11 , 0 ], getpos ( "']" )) 1150" brace object 1151call setline ( 1 , 'test {yank} mark' ) 1152call cursor ( 1 , 9 ) 1153normal ! yi{ 1154call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1155call cursor ( 1 , 9 ) 1156normal ! ya{ 1157call assert_equal ([ 0 , 1 , 11 , 0 ], getpos ( "']" )) 1158" bracket object 1159call setline ( 1 , 'test [yank] mark' ) 1160call cursor ( 1 , 9 ) 1161normal ! yi[ 1162call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1163call cursor ( 1 , 9 ) 1164normal ! ya[ 1165call assert_equal ([ 0 , 1 , 11 , 0 ], getpos ( "']" )) 1166" block object 1167call setline ( 1 , 'test <yank> mark' ) 1168call cursor ( 1 , 9 ) 1169normal ! yi< 1170call assert_equal ([ 0 , 1 , 10 , 0 ], getpos ( "']" )) 1171call cursor ( 1 , 9 ) 1172normal ! ya< 1173call assert_equal ([ 0 , 1 , 11 , 0 ], getpos ( "']" )) 1174bw ! 1175endfunc 1176 1177func Test_insert_small_delete_linewise () 1178new 1179call setline ( 1 , [ 'foo' ]) 1180call cursor ( 1 , 1 ) 1181exe ":norm! \"-cc\<C-R>-" 1182call assert_equal ([ 'foo' , '' ], getline ( 1 , '$' )) 1183bwipe ! 1184endfunc 1185 1186func Test_writing_readonly_regs () 1187call assert_fails ( 'let @. = "foo"' , 'E354:' ) 1188call assert_fails ( 'let @% = "foo"' , 'E354:' ) 1189call assert_fails ( 'let @: = "foo"' , 'E354:' ) 1190call assert_fails ( 'let @~ = "foo"' , 'E354:' ) 1191endfunc 1192 1193" vim: shiftwidth=2 sts=2 expandtab