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