Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 1 | " *-register (quotestar) tests |
| 2 | |
| 3 | if !has('clipboard') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source shared.vim |
| 8 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 9 | func 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 '' |
| 31 | endfunc |
| 32 | |
| 33 | func 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 |
Bram Moolenaar | a2845b8 | 2017-03-25 15:20:06 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 51 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 52 | let name = 'XVIMCLIPBOARD' |
Bram Moolenaar | 1c13c0f | 2017-06-10 16:30:32 +0200 | [diff] [blame] | 53 | |
| 54 | " Make sure a previous server has exited |
| 55 | try |
| 56 | call remote_send(name, ":qa!\<CR>") |
| 57 | call WaitFor('serverlist() !~ "' . name . '"') |
| 58 | catch /E241:/ |
| 59 | endtry |
| 60 | call assert_notmatch(name, serverlist()) |
| 61 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 62 | let cmd .= ' --servername ' . name |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 63 | let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) |
| 64 | call WaitFor({-> job_status(job) == "run"}) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 65 | |
| 66 | " Takes a short while for the server to be active. |
| 67 | call WaitFor('serverlist() =~ "' . name . '"') |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 68 | |
Bram Moolenaar | 4889ad7 | 2017-03-21 18:02:41 +0100 | [diff] [blame] | 69 | " Wait for the server to be up and answering requests. One second is not |
| 70 | " always sufficient. |
| 71 | call WaitFor('remote_expr("' . name . '", "v:version", "", 2) != ""') |
| 72 | |
Bram Moolenaar | 791010e | 2018-02-24 17:42:28 +0100 | [diff] [blame] | 73 | " Clear the *-register of this vim instance and wait for it to be picked up |
| 74 | " by the server. |
| 75 | let @* = 'no' |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 76 | call remote_foreground(name) |
Bram Moolenaar | 791010e | 2018-02-24 17:42:28 +0100 | [diff] [blame] | 77 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "no"', 3000) |
| 78 | |
| 79 | " Set the * register on the server. |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 80 | call remote_send(name, ":let @* = 'yes'\<CR>") |
Bram Moolenaar | 791010e | 2018-02-24 17:42:28 +0100 | [diff] [blame] | 81 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"', 3000) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 82 | |
| 83 | " Check that the *-register of this vim instance is changed as expected. |
Bram Moolenaar | 791010e | 2018-02-24 17:42:28 +0100 | [diff] [blame] | 84 | call WaitFor('@* == "yes"', 3000) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 85 | |
Bram Moolenaar | cdb7e1b | 2017-07-19 19:55:58 +0200 | [diff] [blame] | 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)', 3000) |
| 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 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 98 | if has('unix') && has('gui') && !has('gui_running') |
| 99 | let @* = '' |
| 100 | |
| 101 | " Running in a terminal and the GUI is avaiable: 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 |
Bram Moolenaar | 4889ad7 | 2017-03-21 18:02:41 +0100 | [diff] [blame] | 111 | " Wait for the server in the GUI to be up and answering requests. |
| 112 | call WaitFor('remote_expr("' . name . '", "has(\"gui_running\")", "", 1) =~ "1"') |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 113 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 114 | call remote_send(name, ":let @* = 'maybe'\<CR>") |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 115 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"') |
| 116 | call assert_equal('maybe', remote_expr(name, "@*", "", 2)) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 117 | |
| 118 | call assert_equal('maybe', @*) |
| 119 | endif |
| 120 | |
| 121 | call remote_send(name, ":qa!\<CR>") |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 122 | try |
| 123 | call WaitFor({-> job_status(job) == "dead"}) |
| 124 | finally |
| 125 | if job_status(job) != 'dead' |
| 126 | call assert_report('Server did not exit') |
| 127 | call job_stop(job, 'kill') |
| 128 | endif |
| 129 | endtry |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 130 | |
| 131 | return '' |
| 132 | endfunc |
| 133 | |
| 134 | func Test_quotestar() |
| 135 | let skipped = '' |
| 136 | |
| 137 | let quotestar_saved = @* |
| 138 | |
| 139 | if has('macunix') |
| 140 | let skipped = Do_test_quotestar_for_macunix() |
Bram Moolenaar | a683ec4 | 2017-03-25 20:14:34 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 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) |
Bram Moolenaar | bfd830d | 2017-03-19 21:01:14 +0100 | [diff] [blame] | 154 | throw 'Skipped: ' . skipped |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 155 | endif |
| 156 | endfunc |