robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
dc01d68f27
master
1" *-register (quotestar) tests 2 3source shared.vim 4source check.vim 5 6CheckFeature clipboard_working 7 8func Do_test_quotestar_for_macunix () 9if empty ( exepath ( 'pbcopy' )) || empty ( exepath ( 'pbpaste' )) 10return 'Test requires pbcopy(1) and pbpaste(1)' 11endif 12 13let @*= '' 14 15" Test #1: Pasteboard to Vim 16let test_msg = "text from pasteboard to vim via quotestar" 17" Write a piece of text to the pasteboard. 18call system ( '/bin/echo -n "' . test_msg . '" | pbcopy' ) 19" See if the *-register is changed as expected. 20call assert_equal ( test_msg , @*) 21 22" Test #2: Vim to Pasteboard 23let test_msg = "text from vim to pasteboard via quotestar" 24" Write a piece of text to the *-register. 25let @*= test_msg 26" See if the pasteboard is changed as expected. 27call assert_equal ( test_msg , system ( 'pbpaste' )) 28 29return '' 30endfunc 31 32func Do_test_quotestar_for_x11 () 33if ! has ( 'clientserver' ) || ! has ( 'job' ) 34return 'Test requires the client-server and job features' 35endif 36 37let cmd = GetVimCommand () 38if cmd == '' 39return 'GetVimCommand() failed' 40endif 41try 42call remote_send ( 'xxx' , '' ) 43catch 44if v: exception =~ 'E240:' 45" No connection to the X server, give up. 46return 47endif 48" ignore other errors 49endtry 50 51let name = 'XVIMCLIPBOARD' 52 53" Make sure a previous server has exited 54try 55call remote_send ( name , ":qa!\<CR>" ) 56catch /E241:/ 57endtry 58call WaitForAssert ({ ->assert_notmatch ( name , serverlist ())}) 59 60let cmd .= ' --servername ' . name 61let job = job_start ( cmd , { 'stoponexit' : 'kill' , 'out_io' : 'null' }) 62call WaitForAssert ({ ->assert_equal ( "run" , job_status ( job ))}) 63 64" Takes a short while for the server to be active. 65call WaitForAssert ({ ->assert_match ( name , serverlist ())}) 66 67" Wait for the server to be up and answering requests. One second is not 68" always sufficient. 69call WaitForAssert ({ ->assert_notequal ( '' , remote_expr ( name , "v:version" , "" , 2 ))}) 70 71" Clear the *-register of this vim instance and wait for it to be picked up 72" by the server. 73let @*= 'no' 74call remote_foreground ( name ) 75call WaitForAssert ({ ->assert_equal ( "no" , remote_expr ( name , "@*" , "" , 1 ))}) 76 77" Set the * register on the server. 78call remote_send ( name , ":let @* = 'yes'\<CR>" ) 79call WaitForAssert ({ ->assert_equal ( "yes" , remote_expr ( name , "@*" , "" , 1 ))}) 80 81" Check that the *-register of this vim instance is changed as expected. 82call WaitForAssert ({ ->assert_equal ( "yes" , @*)}) 83 84" Handle the large selection over 262040 byte. 85let length = 262044 86let sample = 'a' . repeat ( 'b' , length - 2 ) . 'c' 87let @*= sample 88call WaitFor ( 'remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)' ) 89let res = remote_expr ( name , "@*" , "" , 2 ) 90call assert_equal ( length , len ( res )) 91" Check length to prevent a large amount of output at assertion failure. 92if length == len ( res ) 93call assert_equal ( sample , res ) 94endif 95 96if has ( 'unix' ) && has ( 'gui' ) && ! has ( 'gui_running' ) 97let @*= '' 98 99" Running in a terminal and the GUI is available: Tell the server to open 100" the GUI and check that the remote command still works. 101if has ( 'gui_motif' ) 102" For those GUIs, ignore the 'failed to create input context' error. 103call remote_send ( name , ":call test_ignore_error('E285') | gui -f\<CR>" ) 104else 105call remote_send ( name , ":gui -f\<CR>" ) 106endif 107" Wait for the server in the GUI to be up and answering requests. 108" First need to wait for the GUI to start up, otherwise the send hangs in 109" trying to send to the terminal window. 110" On some systems and with valgrind this can be very slow. 111sleep 1 112call WaitForAssert ({ ->assert_match ( "1" , remote_expr ( name , "has('gui_running')" , "" , 1 ))}, 10000 ) 113 114call remote_send ( name , ":let @* = 'maybe'\<CR>" ) 115call WaitForAssert ({ ->assert_equal ( "maybe" , remote_expr ( name , "@*" , "" , 2 ))}) 116 117call assert_equal ( 'maybe' , @*) 118endif 119 120call remote_send ( name , ":qa!\<CR>" ) 121try 122call WaitForAssert ({ ->assert_equal ( "dead" , job_status ( job ))}) 123finally 124if job_status ( job ) != 'dead' 125call assert_report ( 'Server did not exit' ) 126call job_stop ( job , 'kill' ) 127endif 128endtry 129 130return '' 131endfunc 132 133func Test_quotestar () 134let g: test_is_flaky = 1 135let skipped = '' 136 137let quotestar_saved = @* 138 139if has ( 'macunix' ) 140let skipped = Do_test_quotestar_for_macunix () 141elseif has ( 'x11' ) 142if empty ( $ DISPLAY ) 143let skipped = "Test can only run when $DISPLAY is set." 144else 145let skipped = Do_test_quotestar_for_x11 () 146endif 147else 148let skipped = "Test is not implemented yet for this platform." 149endif 150 151let @*= quotestar_saved 152 153if ! empty ( skipped ) 154throw 'Skipped: ' . skipped 155endif 156endfunc