comparison src/testdir/test_channel.vim @ 8094:18a3f0f05244 v7.4.1341

commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 16 21:03:07 2016 +0100 patch 7.4.1341 Problem: It's difficult to add more arguments to ch_sendraw() and ch_sendexpr(). Solution: Make the third option a dictionary.
author Christian Brabandt <cb@256bit.org>
date Tue, 16 Feb 2016 21:15:05 +0100
parents 3ea56a74077f
children 882ba5080c5c
comparison
equal deleted inserted replaced
8093:4ffd0f8167f8 8094:18a3f0f05244
115 call assert_equal('ok', ch_sendexpr(handle, 'do normal')) 115 call assert_equal('ok', ch_sendexpr(handle, 'do normal'))
116 sleep 10m 116 sleep 10m
117 call assert_equal('added more', getline('$')) 117 call assert_equal('added more', getline('$'))
118 118
119 " Send a request with a specific handler. 119 " Send a request with a specific handler.
120 call ch_sendexpr(handle, 'hello!', 's:RequestHandler') 120 call ch_sendexpr(handle, 'hello!', {'callback': 's:RequestHandler'})
121 sleep 10m 121 sleep 10m
122 if !exists('s:responseHandle') 122 if !exists('s:responseHandle')
123 call assert_false(1, 's:responseHandle was not set') 123 call assert_false(1, 's:responseHandle was not set')
124 else 124 else
125 call assert_equal(handle, s:responseHandle) 125 call assert_equal(handle, s:responseHandle)
126 endif 126 endif
127 call assert_equal('got it', s:responseMsg) 127 call assert_equal('got it', s:responseMsg)
128 128
129 unlet s:responseHandle 129 unlet s:responseHandle
130 let s:responseMsg = '' 130 let s:responseMsg = ''
131 call ch_sendexpr(handle, 'hello!', function('s:RequestHandler')) 131 call ch_sendexpr(handle, 'hello!', {'callback': function('s:RequestHandler')})
132 sleep 10m 132 sleep 10m
133 if !exists('s:responseHandle') 133 if !exists('s:responseHandle')
134 call assert_false(1, 's:responseHandle was not set') 134 call assert_false(1, 's:responseHandle was not set')
135 else 135 else
136 call assert_equal(handle, s:responseHandle) 136 call assert_equal(handle, s:responseHandle)
169 call assert_equal('ok', ch_sendexpr(handle, 'redraw!')) 169 call assert_equal('ok', ch_sendexpr(handle, 'redraw!'))
170 170
171 call assert_equal('ok', ch_sendexpr(handle, 'empty-request')) 171 call assert_equal('ok', ch_sendexpr(handle, 'empty-request'))
172 172
173 " make the server quit, can't check if this works, should not hang. 173 " make the server quit, can't check if this works, should not hang.
174 call ch_sendexpr(handle, '!quit!', 0) 174 call ch_sendexpr(handle, '!quit!', {'callback': 0})
175 endfunc 175 endfunc
176 176
177 func Test_communicate() 177 func Test_communicate()
178 call s:run_server('s:communicate') 178 call s:run_server('s:communicate')
179 endfunc 179 endfunc
240 call assert_equal('ok', ch_sendexpr(handle, 'call me')) 240 call assert_equal('ok', ch_sendexpr(handle, 'call me'))
241 sleep 10m 241 sleep 10m
242 call assert_equal('we called you', s:reply) 242 call assert_equal('we called you', s:reply)
243 243
244 " Test that it works while not waiting on a numbered message. 244 " Test that it works while not waiting on a numbered message.
245 call ch_sendexpr(handle, 'call me again', 0) 245 call ch_sendexpr(handle, 'call me again', {'callback': 0})
246 sleep 10m 246 sleep 10m
247 call assert_equal('we did call you', s:reply) 247 call assert_equal('we did call you', s:reply)
248 endfunc 248 endfunc
249 249
250 func Test_channel_handler() 250 func Test_channel_handler()
290 endif 290 endif
291 let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'}) 291 let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'})
292 call assert_equal("run", job_status(job)) 292 call assert_equal("run", job_status(job))
293 try 293 try
294 let handle = job_getchannel(job) 294 let handle = job_getchannel(job)
295 call ch_sendraw(handle, "echo something\n", 0) 295 call ch_sendraw(handle, "echo something\n", {'callback': 0})
296 let msg = ch_readraw(handle) 296 let msg = ch_readraw(handle)
297 call assert_equal("something\n", substitute(msg, "\r", "", 'g')) 297 call assert_equal("something\n", substitute(msg, "\r", "", 'g'))
298 298
299 call ch_sendraw(handle, "double this\n", 0) 299 call ch_sendraw(handle, "double this\n", {'callback': 0})
300 let msg = ch_readraw(handle) 300 let msg = ch_readraw(handle)
301 call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g')) 301 call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g'))
302 302
303 let reply = ch_sendraw(handle, "quit\n") 303 let reply = ch_sendraw(handle, "quit\n")
304 call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) 304 call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
313 endif 313 endif
314 let job = job_start(s:python . " test_channel_pipe.py") 314 let job = job_start(s:python . " test_channel_pipe.py")
315 call assert_equal("run", job_status(job)) 315 call assert_equal("run", job_status(job))
316 try 316 try
317 let handle = job_getchannel(job) 317 let handle = job_getchannel(job)
318 call ch_sendraw(handle, "echo something\n", 0) 318 call ch_sendraw(handle, "echo something\n", {'callback': 0})
319 call assert_equal("something", ch_readraw(handle)) 319 call assert_equal("something", ch_readraw(handle))
320 320
321 call ch_sendraw(handle, "double this\n", 0) 321 call ch_sendraw(handle, "double this\n", {'callback': 0})
322 call assert_equal("this", ch_readraw(handle)) 322 call assert_equal("this", ch_readraw(handle))
323 call assert_equal("AND this", ch_readraw(handle)) 323 call assert_equal("AND this", ch_readraw(handle))
324 324
325 let reply = ch_sendraw(handle, "quit\n") 325 let reply = ch_sendraw(handle, "quit\n")
326 call assert_equal("Goodbye!", reply) 326 call assert_equal("Goodbye!", reply)
338 endfunc 338 endfunc
339 339
340 " Test that "unlet handle" in a handler doesn't crash Vim. 340 " Test that "unlet handle" in a handler doesn't crash Vim.
341 func s:unlet_handle(port) 341 func s:unlet_handle(port)
342 let s:channelfd = ch_open('localhost:' . a:port, s:chopt) 342 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
343 call ch_sendexpr(s:channelfd, "test", function('s:UnletHandler')) 343 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
344 sleep 10m 344 sleep 10m
345 call assert_equal('what?', s:unletResponse) 345 call assert_equal('what?', s:unletResponse)
346 endfunc 346 endfunc
347 347
348 func Test_unlet_handle() 348 func Test_unlet_handle()
358 endfunc 358 endfunc
359 359
360 " Test that "unlet handle" in a handler doesn't crash Vim. 360 " Test that "unlet handle" in a handler doesn't crash Vim.
361 func s:close_handle(port) 361 func s:close_handle(port)
362 let s:channelfd = ch_open('localhost:' . a:port, s:chopt) 362 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
363 call ch_sendexpr(s:channelfd, "test", function('s:CloseHandler')) 363 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:CloseHandler')})
364 sleep 10m 364 sleep 10m
365 call assert_equal('what?', s:unletResponse) 365 call assert_equal('what?', s:unletResponse)
366 endfunc 366 endfunc
367 367
368 func Test_close_handle() 368 func Test_close_handle()