robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test clipboard provider support 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local clear , feed , insert =n . clear , n . feed , n . insert 9local expect , eq , eval , source =n . expect , t . eq , n . eval , n . source 10local command =n . command 11local api =n . api 12 13local function basic_register_test ( noblock ) 14insert ( 'some words' ) 15 16feed ( '^dwP' ) 17expect ( 'some words' ) 18 19feed ( 'veyP' ) 20expect ( 'some words words' ) 21 22feed ( '^dwywe"-p' ) 23expect ( 'wordssome words' ) 24 25feed ( 'p' ) 26expect ( 'wordssome words words' ) 27 28feed ( 'yyp' ) 29expect ( [[ 30wordssome words words 31wordssome words words]] ) 32feed ( 'd-' ) 33 34insert ( [[ 35some text, and some more 36random text stuff]] ) 37feed ( 'ggtav+2ed$p' ) 38expect ( [[ 39some text, stuff and some more 40random text]] ) 41 42-- deleting line or word uses "1/"- and doesn't clobber "0 43-- and deleting word to unnamed doesn't clobber "1 44feed ( 'ggyyjdddw"0p"1p"-P' ) 45expect ( [[ 46text, stuff and some more 47some text, stuff and some more 48some random text]] ) 49 50-- delete line doesn't clobber "- 51feed ( 'dd"-P' ) 52expect ( [[ 53text, stuff and some more 54some some text, stuff and some more]] ) 55 56-- deleting a word to named ("a) doesn't update "1 or "- 57feed ( 'gg"adwj"1P^"-P' ) 58expect ( [[ 59, stuff and some more 60some some random text 61some some text, stuff and some more]] ) 62 63-- deleting a line does update "" 64feed ( 'ggdd""P' ) 65expect ( [[ 66, stuff and some more 67some some random text 68some some text, stuff and some more]] ) 69 70feed ( 'ggw<c-v>jwyggP' ) 71if noblock then 72expect ( [[ 73stuf 74me s 75, stuff and some more 76some some random text 77some some text, stuff and some more]] ) 78else 79expect ( [[ 80stuf, stuff and some more 81me ssome some random text 82some some text, stuff and some more]] ) 83end 84 85-- pasting in visual does unnamed delete of visual selection 86feed ( 'ggdG' ) 87insert ( 'one and two and three' ) 88feed ( '"ayiwbbviw"ap^viwp$viw"-p' ) 89expect ( 'two and three and one' ) 90end 91 92describe ( 'clipboard' , function () 93local screen 94 95before_each ( function () 96clear () 97screen =Screen . new ( 72 , 4 ) 98end ) 99 100it ( 'unnamed register works without provider' , function () 101eq ( '"' , eval ( 'v:register' )) 102basic_register_test () 103end ) 104 105it ( 'using "+ in Normal mode with invalid g:clipboard always shows error' , function () 106insert ( 'a' ) 107command ( "let g:clipboard = 'bogus'" ) 108feed ( '"+yl' ) 109screen : expect ( [[ 110^a | 111{1:~ }|*2 112clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 113]] ) 114feed ( '"+p' ) 115screen : expect ( [[ 116a^a | 117{1:~ }|*2 118clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 119]] ) 120end ) 121 122it ( 'using clipboard=unnamedplus with invalid g:clipboard shows error once' , function () 123insert ( 'a' ) 124command ( "let g:clipboard = 'bogus'" ) 125command ( 'set clipboard=unnamedplus' ) 126feed ( 'yl' ) 127screen : expect ( [[ 128^a | 129{1:~ }|*2 130clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 131]] ) 132feed ( ':<CR>' ) 133screen : expect ( [[ 134^a | 135{1:~ }|*2 136: | 137]] ) 138feed ( 'p' ) 139screen : expect ( [[ 140a^a | 141{1:~ }|*2 142: | 143]] ) 144end ) 145 146it ( '`:redir @+>` with invalid g:clipboard shows exactly one error #7184' , function () 147command ( "let g:clipboard = 'bogus'" ) 148n . exec ( [[ 149redir @+> 150silent echo system("cat test/functional/fixtures/tty-test.c") 151redir END 152]] ) 153screen : expect ( [[ 154^ | 155{1:~ }|*2 156clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 157]] ) 158end ) 159 160it ( '`:redir @+>|bogus_cmd|redir END` + invalid g:clipboard must not recurse #7184' , function () 161command ( "let g:clipboard = 'bogus'" ) 162feed ( ':redir @+> | bogus_cmd | redir END<cr>' ) 163screen : expect { 164grid =[[ 165{3: }| 166clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 167{9:E492: Not an editor command: bogus_cmd | redir END} | 168{6:Press ENTER or type command to continue}^ | 169]] , 170} 171end ) 172 173it ( 'invalid g:clipboard shows hint if :redir is not active' , function () 174command ( "let g:clipboard = 'bogus'" ) 175eq ( '' , eval ( 'provider#clipboard#Executable()' )) 176eq ( 'clipboard: invalid g:clipboard' , eval ( 'provider#clipboard#Error()' )) 177 178command ( "let g:clipboard = 'bogus'" ) 179-- Explicit clipboard attempt, should show a hint message. 180feed ( ':let @+="foo"<cr>' ) 181screen : expect ( [[ 182^ | 183{1:~ }|*2 184clipboard: No provider. Try ":checkhealth" or ":h clipboard". | 185]] ) 186end ) 187 188it ( 'valid g:clipboard' , function () 189-- provider#clipboard#Executable() only checks the structure. 190api . nvim_set_var ( 'clipboard' , { 191[ 'name' ] ='clippy!' , 192[ 'copy' ] ={ [ '+' ] ='any command' , [ '*' ] ='some other' } , 193[ 'paste' ] ={ [ '+' ] ='any command' , [ '*' ] ='some other' } , 194} ) 195eq ( 'clippy!' , eval ( 'provider#clipboard#Executable()' )) 196eq ( '' , eval ( 'provider#clipboard#Error()' )) 197end ) 198 199it ( 'g:clipboard using lists' , function () 200source ( [[let g:clipboard = { 201\ 'name': 'custom', 202\ 'copy': { '+': ['any', 'command'], '*': ['some', 'other'] }, 203\ 'paste': { '+': ['any', 'command'], '*': ['some', 'other'] }, 204\}]] ) 205eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 206eq ( '' , eval ( 'provider#clipboard#Error()' )) 207end ) 208 209it ( 'g:clipboard using Vimscript functions' , function () 210-- Implements a fake clipboard provider. cache_enabled is meaningless here. 211source ( [[let g:clipboard = { 212\ 'name': 'custom', 213\ 'copy': { 214\ '+': {lines, regtype -> extend(g:, {'dummy_clipboard_plus': [lines, regtype]}) }, 215\ '*': {lines, regtype -> extend(g:, {'dummy_clipboard_star': [lines, regtype]}) }, 216\ }, 217\ 'paste': { 218\ '+': {-> get(g:, 'dummy_clipboard_plus', [])}, 219\ '*': {-> get(g:, 'dummy_clipboard_star', [])}, 220\ }, 221\ 'cache_enabled': 1, 222\}]] ) 223 224eq ( '' , eval ( 'provider#clipboard#Error()' )) 225eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 226 227eq ( '' , eval ( "getreg('*')" )) 228eq ( '' , eval ( "getreg('+')" )) 229 230command ( 'call setreg("*", "star")' ) 231command ( 'call setreg("+", "plus")' ) 232eq ( 'star' , eval ( "getreg('*')" )) 233eq ( 'plus' , eval ( "getreg('+')" )) 234 235command ( 'call setreg("*", "star", "v")' ) 236eq ( { { 'star' } , 'v' } , eval ( 'g:dummy_clipboard_star' )) 237command ( 'call setreg("*", "star", "V")' ) 238eq ( { { 'star' , '' } , 'V' } , eval ( 'g:dummy_clipboard_star' )) 239command ( 'call setreg("*", "star", "b")' ) 240eq ( { { 'star' , '' } , 'b' } , eval ( 'g:dummy_clipboard_star' )) 241end ) 242 243describe ( 'g:clipboard[paste] Vimscript function' , function () 244it ( 'can return empty list for empty clipboard' , function () 245source ( [[let g:dummy_clipboard = [] 246let g:clipboard = { 247\ 'name': 'custom', 248\ 'copy': { '*': {lines, regtype -> 0} }, 249\ 'paste': { '*': {-> g:dummy_clipboard} }, 250\}]] ) 251eq ( '' , eval ( 'provider#clipboard#Error()' )) 252eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 253eq ( '' , eval ( "getreg('*')" )) 254end ) 255 256it ( 'can return a list with a single string' , function () 257source ( [=[let g:dummy_clipboard = ['hello'] 258let g:clipboard = { 259\ 'name': 'custom', 260\ 'copy': { '*': {lines, regtype -> 0} }, 261\ 'paste': { '*': {-> g:dummy_clipboard} }, 262\}]=] ) 263eq ( '' , eval ( 'provider#clipboard#Error()' )) 264eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 265 266eq ( 'hello' , eval ( "getreg('*')" )) 267source ( [[let g:dummy_clipboard = [''] ]] ) 268eq ( '' , eval ( "getreg('*')" )) 269end ) 270 271it ( 'can return a list of lines if a regtype is provided' , function () 272source ( [=[let g:dummy_clipboard = [['hello'], 'v'] 273let g:clipboard = { 274\ 'name': 'custom', 275\ 'copy': { '*': {lines, regtype -> 0} }, 276\ 'paste': { '*': {-> g:dummy_clipboard} }, 277\}]=] ) 278eq ( '' , eval ( 'provider#clipboard#Error()' )) 279eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 280eq ( 'hello' , eval ( "getreg('*')" )) 281end ) 282 283it ( 'can return a list of lines instead of [lines, regtype]' , function () 284source ( [=[let g:dummy_clipboard = ['hello', 'v'] 285let g:clipboard = { 286\ 'name': 'custom', 287\ 'copy': { '*': {lines, regtype -> 0} }, 288\ 'paste': { '*': {-> g:dummy_clipboard} }, 289\}]=] ) 290eq ( '' , eval ( 'provider#clipboard#Error()' )) 291eq ( 'custom' , eval ( 'provider#clipboard#Executable()' )) 292eq ( 'hello\nv' , eval ( "getreg('*')" )) 293end ) 294end ) 295end ) 296 297describe ( 'clipboard (with fake clipboard.vim)' , function () 298local function reset ( ... ) 299clear ( '--cmd' , 'set rtp^=test/functional/fixtures' , ... ) 300end 301 302before_each ( function () 303reset () 304command ( 'call getreg("*")' ) -- force load of provider 305end ) 306 307it ( '`:redir @+>` invokes clipboard once-per-message' , function () 308eq ( 0 , eval ( 'g:clip_called_set' )) 309n . exec ( [[ 310redir @+> 311silent echo system("cat test/functional/fixtures/tty-test.c") 312redir END 313]] ) 314-- Assuming tty-test.c has >100 lines. 315assert ( eval ( 'g:clip_called_set' ) > 100 ) 316end ) 317 318it ( '`:redir @">` does NOT invoke clipboard' , function () 319-- :redir to a non-clipboard register, with `:set clipboard=unnamed` does 320-- NOT propagate to the clipboard. This is consistent with Vim. 321command ( 'set clipboard=unnamedplus' ) 322eq ( 0 , eval ( 'g:clip_called_set' )) 323n . exec ( [[ 324redir @"> 325silent echo system("cat test/functional/fixtures/tty-test.c") 326redir END 327]] ) 328eq ( 0 , eval ( 'g:clip_called_set' )) 329end ) 330 331it ( '`:redir @+>|bogus_cmd|redir END` must not recurse #7184' , function () 332local screen =Screen . new ( 72 , 4 ) 333feed ( ':redir @+> | bogus_cmd | redir END<cr>' ) 334screen : expect ( [[ 335^ | 336{1:~ }|*2 337{9:E492: Not an editor command: bogus_cmd | redir END} | 338]] ) 339end ) 340 341it ( 'has independent "* and unnamed registers by default' , function () 342insert ( 'some words' ) 343feed ( '^"*dwdw"*P' ) 344expect ( 'some ' ) 345eq ( { { 'some ' } , 'v' } , eval ( "g:test_clip['*']" )) 346eq ( 'words' , eval ( "getreg('\"', 1)" )) 347end ) 348 349it ( 'supports separate "* and "+ when the provider supports it' , function () 350insert ( [[ 351text: 352first line 353second line 354third line]] ) 355 356feed ( 'G"+dd"*dddd"+p"*pp' ) 357expect ( [[ 358text: 359third line 360second line 361first line]] ) 362-- linewise selection should be encoded as an extra newline 363eq ( { { 'third line' , '' } , 'V' } , eval ( "g:test_clip['+']" )) 364eq ( { { 'second line' , '' } , 'V' } , eval ( "g:test_clip['*']" )) 365end ) 366 367it ( 'handles null bytes when pasting and in getreg' , function () 368insert ( 'some\022000text\n\022000very binary\022000' ) 369feed ( '"*y-+"*p' ) 370eq ( { { 'some\ntext' , '\nvery binary\n' , '' } , 'V' } , eval ( "g:test_clip['*']" )) 371expect ( 'some\00text\n\00very binary\00\nsome\00text\n\00very binary\00' ) 372 373-- test getreg/getregtype 374eq ( 'some\ntext\n\nvery binary\n\n' , eval ( "getreg('*', 1)" )) 375eq ( 'V' , eval ( "getregtype('*')" )) 376 377-- getreg supports three arguments 378eq ( 'some\ntext\n\nvery binary\n\n' , eval ( "getreg('*', 1, 0)" )) 379eq ( { 'some\ntext' , '\nvery binary\n' } , eval ( "getreg('*', 1, 1)" )) 380end ) 381 382it ( 'autodetects regtype' , function () 383command ( "let g:test_clip['*'] = ['linewise stuff','']" ) 384command ( "let g:test_clip['+'] = ['charwise','stuff']" ) 385eq ( 'V' , eval ( "getregtype('*')" )) 386eq ( 'v' , eval ( "getregtype('+')" )) 387insert ( 'just some text' ) 388feed ( '"*p"+p' ) 389expect ( [[ 390just some text 391lcharwise 392stuffinewise stuff]] ) 393end ) 394 395it ( 'support blockwise operations' , function () 396insert ( [[ 397much 398text]] ) 399command ( "let g:test_clip['*'] = [['very','block'],'b']" ) 400feed ( 'gg"*P' ) 401expect ( [[ 402very much 403blocktext]] ) 404eq ( '\0225' , eval ( "getregtype('*')" )) 405feed ( 'gg4l<c-v>j4l"+ygg"+P' ) 406expect ( [[ 407muchvery much 408ktextblocktext]] ) 409eq ( { { ' much' , 'ktext' , '' } , 'b' } , eval ( "g:test_clip['+']" )) 410end ) 411 412it ( 'supports setreg()' , function () 413command ( 'call setreg("*", "setted\\ntext", "c")' ) 414command ( 'call setreg("+", "explicitly\\nlines", "l")' ) 415feed ( '"+P"*p' ) 416expect ( [[ 417esetted 418textxplicitly 419lines 420]] ) 421command ( 'call setreg("+", "blocky\\nindeed", "b")' ) 422feed ( '"+p' ) 423expect ( [[ 424esblockyetted 425teindeedxtxplicitly 426lines 427]] ) 428end ) 429 430it ( 'supports :let @+ (issue #1427)' , function () 431command ( "let @+ = 'some'" ) 432command ( "let @* = ' other stuff'" ) 433eq ( { { 'some' } , 'v' } , eval ( "g:test_clip['+']" )) 434eq ( { { ' other stuff' } , 'v' } , eval ( "g:test_clip['*']" )) 435feed ( '"+p"*p' ) 436expect ( 'some other stuff' ) 437command ( "let @+ .= ' more'" ) 438feed ( 'dd"+p' ) 439expect ( 'some more' ) 440end ) 441 442it ( 'pastes unnamed register if the provider fails' , function () 443insert ( 'the text' ) 444feed ( 'yy' ) 445command ( 'let g:cliperror = 1' ) 446feed ( '"*p' ) 447expect ( [[ 448the text 449the text]] ) 450end ) 451 452describe ( 'with clipboard=unnamed' , function () 453-- the basic behavior of unnamed register should be the same 454-- even when handled by clipboard provider 455before_each ( function () 456feed ( ':set clipboard=unnamed<cr>' ) 457end ) 458 459it ( 'works' , function () 460basic_register_test () 461end ) 462 463it ( 'works with pure text clipboard' , function () 464command ( 'let g:cliplossy = 1' ) 465-- expect failure for block mode 466basic_register_test ( true ) 467end ) 468 469it ( 'links the "* and unnamed registers' , function () 470-- with cb=unnamed, "* and unnamed will be the same register 471insert ( 'some words' ) 472feed ( '^"*dwdw"*P' ) 473expect ( 'words' ) 474eq ( { { 'words' } , 'v' } , eval ( "g:test_clip['*']" )) 475 476-- "+ shouldn't have changed 477eq ( { '' } , eval ( "g:test_clip['+']" )) 478 479command ( "let g:test_clip['*'] = ['linewise stuff','']" ) 480feed ( 'p' ) 481expect ( [[ 482words 483linewise stuff]] ) 484end ) 485 486it ( 'does not clobber "0 when pasting' , function () 487insert ( 'a line' ) 488feed ( 'yy' ) 489command ( "let g:test_clip['*'] = ['b line','']" ) 490feed ( '"0pp"0p' ) 491expect ( [[ 492a line 493a line 494b line 495a line]] ) 496end ) 497 498it ( 'supports v:register and getreg() without parameters' , function () 499eq ( '*' , eval ( 'v:register' )) 500command ( "let g:test_clip['*'] = [['some block',''], 'b']" ) 501eq ( 'some block' , eval ( 'getreg()' )) 502eq ( '\02210' , eval ( 'getregtype()' )) 503end ) 504 505it ( 'yanks visual selection when pasting' , function () 506insert ( 'indeed visual' ) 507command ( "let g:test_clip['*'] = [['clipboard'], 'c']" ) 508feed ( 'viwp' ) 509eq ( { { 'visual' } , 'v' } , eval ( "g:test_clip['*']" )) 510expect ( 'indeed clipboard' ) 511 512-- explicit "* should do the same 513command ( "let g:test_clip['*'] = [['star'], 'c']" ) 514feed ( 'viw"*p' ) 515eq ( { { 'clipboard' } , 'v' } , eval ( "g:test_clip['*']" )) 516expect ( 'indeed star' ) 517end ) 518 519it ( 'unnamed operations work even if the provider fails' , function () 520insert ( 'the text' ) 521feed ( 'yy' ) 522command ( 'let g:cliperror = 1' ) 523feed ( 'p' ) 524expect ( [[ 525the text 526the text]] ) 527end ) 528 529it ( 'is updated on global changes' , function () 530insert ( [[ 531text 532match 533match 534text 535]] ) 536command ( 'g/match/d' ) 537eq ( 'match\n' , eval ( 'getreg("*")' )) 538feed ( 'u' ) 539eval ( 'setreg("*", "---")' ) 540command ( 'g/test/' ) 541feed ( '<esc>' ) 542eq ( '---' , eval ( 'getreg("*")' )) 543end ) 544 545it ( 'works in the cmdline window' , function () 546feed ( 'q:itext<esc>yy' ) 547eq ( { { 'text' , '' } , 'V' } , eval ( "g:test_clip['*']" )) 548command ( "let g:test_clip['*'] = [['star'], 'c']" ) 549feed ( 'p' ) 550eq ( 'textstar' , api . nvim_get_current_line ()) 551end ) 552 553it ( 'block paste works correctly' , function () 554insert ( [[ 555aabbcc 556ddeeff 557]] ) 558feed ( 'gg^<C-v>' ) -- Goto start of top line enter visual block mode 559feed ( '3ljy^k' ) -- yank 4x2 block & goto initial location 560feed ( 'P' ) -- Paste it before cursor 561expect ( [[ 562aabbaabbcc 563ddeeddeeff 564]] ) 565end ) 566 567it ( 'block paste computes block width correctly #35034' , function () 568insert ( 'あいうえお' ) 569feed ( '0<C-V>ly' ) 570feed ( 'P' ) 571expect ( 'あいあいうえお' ) 572feed ( 'A\nxxx\nxx<Esc>' ) 573feed ( '0<C-V>kkly' ) 574feed ( 'P' ) 575expect ( [[ 576あいあいあいうえお 577xxx xxx 578xx xx]] ) 579feed ( 'G0<C-V>ky' ) 580feed ( 'P' ) 581expect ( [[ 582あいあいあいうえお 583xxxx xxx 584xxx xx]] ) 585end ) 586end ) 587 588describe ( 'clipboard=unnamedplus' , function () 589before_each ( function () 590feed ( ':set clipboard=unnamedplus<cr>' ) 591end ) 592 593it ( 'links the "+ and unnamed registers' , function () 594eq ( '+' , eval ( 'v:register' )) 595insert ( 'one two' ) 596feed ( '^"+dwdw"+P' ) 597expect ( 'two' ) 598eq ( { { 'two' } , 'v' } , eval ( "g:test_clip['+']" )) 599 600-- "* shouldn't have changed 601eq ( { '' } , eval ( "g:test_clip['*']" )) 602 603command ( "let g:test_clip['+'] = ['three']" ) 604feed ( 'p' ) 605expect ( 'twothree' ) 606end ) 607 608it ( 'and unnamed, yanks to both' , function () 609command ( 'set clipboard=unnamedplus,unnamed' ) 610insert ( [[ 611really unnamed 612text]] ) 613feed ( 'ggdd"*p"+p' ) 614expect ( [[ 615text 616really unnamed 617really unnamed]] ) 618eq ( { { 'really unnamed' , '' } , 'V' } , eval ( "g:test_clip['+']" )) 619eq ( { { 'really unnamed' , '' } , 'V' } , eval ( "g:test_clip['*']" )) 620 621-- unnamedplus takes precedence when pasting 622eq ( '+' , eval ( 'v:register' )) 623command ( "let g:test_clip['+'] = ['the plus','']" ) 624command ( "let g:test_clip['*'] = ['the star','']" ) 625feed ( 'p' ) 626expect ( [[ 627text 628really unnamed 629really unnamed 630the plus]] ) 631end ) 632 633it ( 'is updated on global changes' , function () 634insert ( [[ 635text 636match 637match 638text 639]] ) 640command ( 'g/match/d' ) 641eq ( 'match\n' , eval ( 'getreg("+")' )) 642feed ( 'u' ) 643eval ( 'setreg("+", "---")' ) 644command ( 'g/test/' ) 645feed ( '<esc>' ) 646eq ( '---' , eval ( 'getreg("+")' )) 647end ) 648end ) 649 650it ( 'sets v:register after startup' , function () 651reset () 652eq ( '"' , eval ( 'v:register' )) 653reset ( '--cmd' , 'set clipboard=unnamed' ) 654eq ( '*' , eval ( 'v:register' )) 655end ) 656 657it ( 'supports :put' , function () 658insert ( 'a line' ) 659command ( "let g:test_clip['*'] = ['some text']" ) 660command ( "let g:test_clip['+'] = ['more', 'text', '']" ) 661command ( ':put *' ) 662expect ( [[ 663a line 664some text]] ) 665command ( ':put +' ) 666expect ( [[ 667a line 668some text 669more 670text]] ) 671end ) 672 673it ( 'supports "+ and "* in registers' , function () 674local screen =Screen . new ( 60 , 10 ) 675feed ( ":let g:test_clip['*'] = ['some', 'star data','']<cr>" ) 676feed ( ":let g:test_clip['+'] = ['such', 'plus', 'stuff']<cr>" ) 677feed ( ':registers<cr>' ) 678screen : expect ( 679[[ 680| 681{0:~ }|*2 682{4: }| 683:registers | 684{1:Type Name Content} | 685l "* some{2:^J}star data{2:^J} | 686c "+ such{2:^J}plus{2:^J}stuff | 687c ": let g:test_clip['+'] = ['such', 'plus', 'stuff'] | 688{3:Press ENTER or type command to continue}^ | 689]] , 690{ 691[ 0 ] ={ bold =true , foreground =Screen . colors . Blue } , 692[ 1 ] ={ bold =true , foreground =Screen . colors . Fuchsia } , 693[ 2 ] ={ foreground =Screen . colors . Blue } , 694[ 3 ] ={ bold =true , foreground =Screen . colors . SeaGreen } , 695[ 4 ] ={ bold =true , reverse =true } , 696} 697) 698feed ( '<cr>' ) -- clear out of Press ENTER screen 699end ) 700 701it ( 'can paste "* to the commandline' , function () 702insert ( 's/s/t/' ) 703feed ( 'gg"*y$:<c-r>*<cr>' ) 704expect ( 't/s/t/' ) 705command ( "let g:test_clip['*'] = ['s/s/u']" ) 706feed ( ':<c-r>*<cr>' ) 707expect ( 't/u/t/' ) 708end ) 709 710it ( 'supports :redir @*>' , function () 711command ( "let g:test_clip['*'] = ['stuff']" ) 712command ( 'redir @*>' ) 713-- it is made empty 714eq ( { { '' } , 'v' } , eval ( "g:test_clip['*']" )) 715feed ( ':let g:test = doesnotexist<cr>' ) 716feed ( '<cr>' ) 717eq ( 718{ { 719'' , 720'' , 721'E121: Undefined variable: doesnotexist' , 722} , 'v' } , 723eval ( "g:test_clip['*']" ) 724) 725feed ( ':echo "Howdy!"<cr>' ) 726eq ( { 727{ 728'' , 729'' , 730'E121: Undefined variable: doesnotexist' , 731'' , 732'Howdy!' , 733} , 734'v' , 735} , eval ( "g:test_clip['*']" )) 736end ) 737 738it ( 'handles middleclick correctly' , function () 739command ( 'set mouse=a' ) 740 741local screen =Screen . new ( 30 , 5 ) 742insert ( [[ 743the source 744a target]] ) 745feed ( 'gg"*ywwyw' ) 746-- clicking depends on the exact visual layout, so expect it: 747screen : expect ( [[ 748the ^source | 749a target | 750{1:~ }|*2 751| 752]] ) 753 754feed ( '<MiddleMouse><0,1>' ) 755expect ( [[ 756the source 757the a target]] ) 758 759-- on error, fall back to unnamed register 760command ( 'let g:cliperror = 1' ) 761feed ( '<MiddleMouse><6,1>' ) 762expect ( [[ 763the source 764the a sourcetarget]] ) 765end ) 766 767it ( 'setreg("*") with clipboard=unnamed #5646' , function () 768source ( [=[ 769function! Paste_without_yank(direction) range 770let [reg_save,regtype_save] = [getreg('*'), getregtype('*')] 771normal! gvp 772call setreg('*', reg_save, regtype_save) 773endfunction 774xnoremap p :call Paste_without_yank('p')<CR> 775set clipboard=unnamed 776]=] ) 777insert ( 'some words' ) 778feed ( 'gg0yiw' ) 779feed ( 'wviwp' ) 780expect ( 'some some' ) 781eq ( 'some' , eval ( 'getreg("*")' )) 782end ) 783 784it ( 'does not fall back to unnamed register with getreg() #24257' , function () 785eval ( 'setreg("", "wrong")' ) 786command ( 'let g:cliperror = 1' ) 787eq ( '' , eval ( 'getreg("*")' )) 788eq ( '' , eval ( 'getreg("+")' )) 789end ) 790end )