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