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 return '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 " Need to wait for the GUI to start up, otherwise the send hangs in trying 102 " to send to the terminal window. 103 if has('gui_athena') || has('gui_motif') 104 " For those GUIs, ignore the 'failed to create input context' error. 105 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") 106 else 107 call remote_send(name, ":gui -f\<CR>") 108 endif 109 " Wait for the server in the GUI to be up and answering requests. 110 " On some systems and with valgrind this can be very slow. 111 call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}, 10000) 112 113 call remote_send(name, ":let @* = 'maybe'\<CR>") 114 call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))}) 115 116 call assert_equal('maybe', @*) 117 endif 118 119 call remote_send(name, ":qa!\<CR>") 120 try 121 call WaitForAssert({-> assert_equal("dead", job_status(job))}) 122 finally 123 if job_status(job) != 'dead' 124 call assert_report('Server did not exit') 125 call job_stop(job, 'kill') 126 endif 127 endtry 128 129 return '' 130endfunc 131 132func Test_quotestar() 133 let skipped = '' 134 135 let quotestar_saved = @* 136 137 if has('macunix') 138 let skipped = Do_test_quotestar_for_macunix() 139 elseif has('x11') 140 if empty($DISPLAY) 141 let skipped = "Test can only run when $DISPLAY is set." 142 else 143 let skipped = Do_test_quotestar_for_x11() 144 endif 145 else 146 let skipped = "Test is not implemented yet for this platform." 147 endif 148 149 let @* = quotestar_saved 150 151 if !empty(skipped) 152 throw 'Skipped: ' . skipped 153 endif 154endfunc 155