blob: b7d31583d4c7f0d39fcf79c5c22a1ae56670b383 [file] [log] [blame]
Bram Moolenaar7dd48502017-03-19 20:04:22 +01001" *-register (quotestar) tests
2
3if !has('clipboard')
4 finish
5endif
6
7source shared.vim
8
Bram Moolenaar7dd48502017-03-19 20:04:22 +01009func 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
Bram Moolenaara2845b82017-03-25 15:20:06 +010042 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 Moolenaar7dd48502017-03-19 20:04:22 +010051
Bram Moolenaar7dd48502017-03-19 20:04:22 +010052 let name = 'XVIMCLIPBOARD'
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020053
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 Moolenaar7dd48502017-03-19 20:04:22 +010062 let cmd .= ' --servername ' . name
63 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
64 call WaitFor('job_status(g:job) == "run"')
65 if job_status(g:job) != 'run'
66 call assert_report('Cannot run the Vim server')
67 return ''
68 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +010069
70 " Takes a short while for the server to be active.
71 call WaitFor('serverlist() =~ "' . name . '"')
72 call assert_match(name, serverlist())
Bram Moolenaar7dd48502017-03-19 20:04:22 +010073
Bram Moolenaar4889ad72017-03-21 18:02:41 +010074 " Wait for the server to be up and answering requests. One second is not
75 " always sufficient.
76 call WaitFor('remote_expr("' . name . '", "v:version", "", 2) != ""')
77
Bram Moolenaar7dd48502017-03-19 20:04:22 +010078 " Clear the *-register of this vim instance.
79 let @* = ''
80
81 " Try to change the *-register of the server.
82 call remote_foreground(name)
Bram Moolenaar7dd48502017-03-19 20:04:22 +010083 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +010084 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"')
85 call assert_equal('yes', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +010086
87 " Check that the *-register of this vim instance is changed as expected.
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020088 call WaitFor('@* == "yes"')
Bram Moolenaar7dd48502017-03-19 20:04:22 +010089 call assert_equal('yes', @*)
90
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020091 " Handle the large selection over 262040 byte.
92 let length = 262044
93 let sample = 'a' . repeat('b', length - 2) . 'c'
94 let @* = sample
95 call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)', 3000)
96 let res = remote_expr(name, "@*", "", 2)
97 call assert_equal(length, len(res))
98 " Check length to prevent a large amount of output at assertion failure.
99 if length == len(res)
100 call assert_equal(sample, res)
101 endif
102
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100103 if has('unix') && has('gui') && !has('gui_running')
104 let @* = ''
105
106 " Running in a terminal and the GUI is avaiable: Tell the server to open
107 " the GUI and check that the remote command still works.
108 " Need to wait for the GUI to start up, otherwise the send hangs in trying
109 " to send to the terminal window.
110 if has('gui_athena') || has('gui_motif')
111 " For those GUIs, ignore the 'failed to create input context' error.
112 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
113 else
114 call remote_send(name, ":gui -f\<CR>")
115 endif
Bram Moolenaar4889ad72017-03-21 18:02:41 +0100116 " Wait for the server in the GUI to be up and answering requests.
117 call WaitFor('remote_expr("' . name . '", "has(\"gui_running\")", "", 1) =~ "1"')
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100118
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100119 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100120 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"')
121 call assert_equal('maybe', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100122
123 call assert_equal('maybe', @*)
124 endif
125
126 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100127 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100128 if job_status(g:job) != 'dead'
129 call assert_report('Server did not exit')
130 call job_stop(g:job, 'kill')
131 endif
132
133 return ''
134endfunc
135
136func Test_quotestar()
137 let skipped = ''
138
139 let quotestar_saved = @*
140
141 if has('macunix')
142 let skipped = Do_test_quotestar_for_macunix()
Bram Moolenaara683ec42017-03-25 20:14:34 +0100143 elseif has('x11')
144 if empty($DISPLAY)
145 let skipped = "Test can only run when $DISPLAY is set."
146 else
147 let skipped = Do_test_quotestar_for_x11()
148 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100149 else
150 let skipped = "Test is not implemented yet for this platform."
151 endif
152
153 let @* = quotestar_saved
154
155 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100156 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100157 endif
158endfunc