blob: 432862e875398b6d1f2a852304bf4be9ea816693 [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
Bram Moolenaar52992fe2019-08-12 14:20:33 +02004source check.vim
Bram Moolenaar7dd48502017-03-19 20:04:22 +01005
Bram Moolenaar52992fe2019-08-12 14:20:33 +02006CheckFeature clipboard_working
Bram Moolenaar7dd48502017-03-19 20:04:22 +01007
Bram Moolenaar7dd48502017-03-19 20:04:22 +01008func Do_test_quotestar_for_macunix()
9 if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
10 return 'Test requires pbcopy(1) and pbpaste(1)'
11 endif
12
13 let @* = ''
14
15 " Test #1: Pasteboard to Vim
16 let test_msg = "text from pasteboard to vim via quotestar"
17 " Write a piece of text to the pasteboard.
18 call system('/bin/echo -n "' . test_msg . '" | pbcopy')
19 " See if the *-register is changed as expected.
20 call assert_equal(test_msg, @*)
21
22 " Test #2: Vim to Pasteboard
23 let test_msg = "text from vim to pasteboard via quotestar"
24 " Write a piece of text to the *-register.
25 let @* = test_msg
26 " See if the pasteboard is changed as expected.
27 call assert_equal(test_msg, system('pbpaste'))
28
29 return ''
30endfunc
31
32func Do_test_quotestar_for_x11()
33 if !has('clientserver') || !has('job')
34 return 'Test requires the client-server and job features'
35 endif
36
37 let cmd = GetVimCommand()
38 if cmd == ''
39 return 'GetVimCommand() failed'
40 endif
Bram Moolenaara2845b82017-03-25 15:20:06 +010041 try
42 call remote_send('xxx', '')
43 catch
44 if v:exception =~ 'E240:'
45 " No connection to the X server, give up.
46 return
47 endif
48 " ignore other errors
49 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +010050
Bram Moolenaar7dd48502017-03-19 20:04:22 +010051 let name = 'XVIMCLIPBOARD'
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020052
53 " Make sure a previous server has exited
54 try
55 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020056 catch /E241:/
57 endtry
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020058 call WaitForAssert({-> assert_notmatch(name, serverlist())})
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020059
Bram Moolenaar7dd48502017-03-19 20:04:22 +010060 let cmd .= ' --servername ' . name
Bram Moolenaarab8b1c12017-11-04 19:24:31 +010061 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020062 call WaitForAssert({-> assert_equal("run", job_status(job))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010063
64 " Takes a short while for the server to be active.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020065 call WaitForAssert({-> assert_match(name, serverlist())})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010066
Bram Moolenaar4889ad72017-03-21 18:02:41 +010067 " Wait for the server to be up and answering requests. One second is not
68 " always sufficient.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020069 call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
Bram Moolenaar4889ad72017-03-21 18:02:41 +010070
Bram Moolenaar791010e2018-02-24 17:42:28 +010071 " Clear the *-register of this vim instance and wait for it to be picked up
72 " by the server.
73 let @* = 'no'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010074 call remote_foreground(name)
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020075 call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
Bram Moolenaar791010e2018-02-24 17:42:28 +010076
77 " Set the * register on the server.
Bram Moolenaar7dd48502017-03-19 20:04:22 +010078 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020079 call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010080
81 " Check that the *-register of this vim instance is changed as expected.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020082 call WaitForAssert({-> assert_equal("yes", @*)})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010083
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020084 " Handle the large selection over 262040 byte.
85 let length = 262044
86 let sample = 'a' . repeat('b', length - 2) . 'c'
87 let @* = sample
Bram Moolenaar769e9d22018-04-11 20:53:49 +020088 call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020089 let res = remote_expr(name, "@*", "", 2)
90 call assert_equal(length, len(res))
91 " Check length to prevent a large amount of output at assertion failure.
92 if length == len(res)
93 call assert_equal(sample, res)
94 endif
95
Bram Moolenaar7dd48502017-03-19 20:04:22 +010096 if has('unix') && has('gui') && !has('gui_running')
97 let @* = ''
98
Bram Moolenaar037c54f2019-04-20 23:47:46 +020099 " Running in a terminal and the GUI is available: Tell the server to open
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100100 " the GUI and check that the remote command still works.
101 " Need to wait for the GUI to start up, otherwise the send hangs in trying
102 " to send to the terminal window.
103 if has('gui_athena') || has('gui_motif')
104 " For those GUIs, ignore the 'failed to create input context' error.
105 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
106 else
107 call remote_send(name, ":gui -f\<CR>")
108 endif
Bram Moolenaar4889ad72017-03-21 18:02:41 +0100109 " Wait for the server in the GUI to be up and answering requests.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200110 call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))})
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100111
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100112 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200113 call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100114
115 call assert_equal('maybe', @*)
116 endif
117
118 call remote_send(name, ":qa!\<CR>")
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100119 try
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200120 call WaitForAssert({-> assert_equal("dead", job_status(job))})
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100121 finally
122 if job_status(job) != 'dead'
123 call assert_report('Server did not exit')
124 call job_stop(job, 'kill')
125 endif
126 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100127
128 return ''
129endfunc
130
131func Test_quotestar()
132 let skipped = ''
133
134 let quotestar_saved = @*
135
136 if has('macunix')
137 let skipped = Do_test_quotestar_for_macunix()
Bram Moolenaara683ec42017-03-25 20:14:34 +0100138 elseif has('x11')
139 if empty($DISPLAY)
140 let skipped = "Test can only run when $DISPLAY is set."
141 else
142 let skipped = Do_test_quotestar_for_x11()
143 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100144 else
145 let skipped = "Test is not implemented yet for this platform."
146 endif
147
148 let @* = quotestar_saved
149
150 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100151 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100152 endif
153endfunc