blob: d21ab35fcc19e035bb4df6c4341435a5a63f54be [file] [log] [blame]
Bram Moolenaar7dd48502017-03-19 20:04:22 +01001" *-register (quotestar) tests
2
Bram Moolenaar564344a2019-04-28 13:00:12 +02003source shared.vim
4if !WorkingClipboard()
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02005 throw 'Skipped: no working clipboard'
Bram Moolenaar7dd48502017-03-19 20:04:22 +01006endif
7
8source shared.vim
9
Bram Moolenaar7dd48502017-03-19 20:04:22 +010010func 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
Bram Moolenaara2845b82017-03-25 15:20:06 +010043 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
Bram Moolenaar7dd48502017-03-19 20:04:22 +010052
Bram Moolenaar7dd48502017-03-19 20:04:22 +010053 let name = 'XVIMCLIPBOARD'
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020054
55 " Make sure a previous server has exited
56 try
57 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020058 catch /E241:/
59 endtry
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020060 call WaitForAssert({-> assert_notmatch(name, serverlist())})
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020061
Bram Moolenaar7dd48502017-03-19 20:04:22 +010062 let cmd .= ' --servername ' . name
Bram Moolenaarab8b1c12017-11-04 19:24:31 +010063 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020064 call WaitForAssert({-> assert_equal("run", job_status(job))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010065
66 " Takes a short while for the server to be active.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020067 call WaitForAssert({-> assert_match(name, serverlist())})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010068
Bram Moolenaar4889ad72017-03-21 18:02:41 +010069 " Wait for the server to be up and answering requests. One second is not
70 " always sufficient.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020071 call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
Bram Moolenaar4889ad72017-03-21 18:02:41 +010072
Bram Moolenaar791010e2018-02-24 17:42:28 +010073 " Clear the *-register of this vim instance and wait for it to be picked up
74 " by the server.
75 let @* = 'no'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010076 call remote_foreground(name)
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020077 call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
Bram Moolenaar791010e2018-02-24 17:42:28 +010078
79 " Set the * register on the server.
Bram Moolenaar7dd48502017-03-19 20:04:22 +010080 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020081 call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010082
83 " Check that the *-register of this vim instance is changed as expected.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020084 call WaitForAssert({-> assert_equal("yes", @*)})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010085
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020086 " Handle the large selection over 262040 byte.
87 let length = 262044
88 let sample = 'a' . repeat('b', length - 2) . 'c'
89 let @* = sample
Bram Moolenaar769e9d22018-04-11 20:53:49 +020090 call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020091 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 Moolenaar7dd48502017-03-19 20:04:22 +010098 if has('unix') && has('gui') && !has('gui_running')
99 let @* = ''
100
Bram Moolenaar037c54f2019-04-20 23:47:46 +0200101 " Running in a terminal and the GUI is available: Tell the server to open
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100102 " 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 Moolenaar4889ad72017-03-21 18:02:41 +0100111 " Wait for the server in the GUI to be up and answering requests.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200112 call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))})
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100113
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100114 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200115 call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100116
117 call assert_equal('maybe', @*)
118 endif
119
120 call remote_send(name, ":qa!\<CR>")
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100121 try
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200122 call WaitForAssert({-> assert_equal("dead", job_status(job))})
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100123 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
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100129
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()
Bram Moolenaara683ec42017-03-25 20:14:34 +0100140 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
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100146 else
147 let skipped = "Test is not implemented yet for this platform."
148 endif
149
150 let @* = quotestar_saved
151
152 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100153 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100154 endif
155endfunc