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