patch 7.4.1373
Problem: Calling a Vim function over a channel requires turning the
arguments into a string.
Solution: Add the "call" command. (Damien) Also merge "expr" and "eval"
into one.
diff --git a/src/testdir/test_channel.py b/src/testdir/test_channel.py
index 66fd48f..26c7dea 100644
--- a/src/testdir/test_channel.py
+++ b/src/testdir/test_channel.py
@@ -78,26 +78,26 @@
response = "ok"
elif decoded[1] == 'eval-works':
# Send an eval request. We ignore the response.
- cmd = '["eval","\\"foo\\" . 123", -1]'
+ cmd = '["expr","\\"foo\\" . 123", -1]'
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
elif decoded[1] == 'eval-fails':
# Send an eval request that will fail.
- cmd = '["eval","xxx", -2]'
+ cmd = '["expr","xxx", -2]'
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
elif decoded[1] == 'eval-error':
# Send an eval request that works but the result can't
# be encoded.
- cmd = '["eval","function(\\"tr\\")", -3]'
+ cmd = '["expr","function(\\"tr\\")", -3]'
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
elif decoded[1] == 'eval-bad':
# Send an eval request missing the third argument.
- cmd = '["eval","xxx"]'
+ cmd = '["expr","xxx"]'
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
@@ -107,6 +107,11 @@
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = "ok"
+ elif decoded[1] == 'call-func':
+ cmd = '["call","MyFunction",[1,2,3], 0]'
+ print("sending: {}".format(cmd))
+ self.request.sendall(cmd.encode('utf-8'))
+ response = "ok"
elif decoded[1] == 'redraw':
cmd = '["redraw",""]'
print("sending: {}".format(cmd))
@@ -135,6 +140,9 @@
print("sending: {}".format(cmd))
self.request.sendall(cmd.encode('utf-8'))
response = ""
+ elif decoded[1] == 'wait a bit':
+ time.sleep(0.2)
+ response = "waited"
elif decoded[1] == '!quit!':
# we're done
self.server.shutdown()
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index cfe3250..4d3b359 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -431,3 +431,26 @@
" The server will wait half a second before creating the port.
call s:run_server('s:open_delay', 'delay')
endfunc
+
+"""""""""
+
+function MyFunction(a,b,c)
+ let s:call_ret = [a:a, a:b, a:c]
+endfunc
+
+function s:test_call(port)
+ let handle = ch_open('localhost:' . a:port, s:chopt)
+ if ch_status(handle) == "fail"
+ call assert_false(1, "Can't open channel")
+ return
+ endif
+
+ call assert_equal('ok', ch_sendexpr(handle, 'call-func'))
+ sleep 20m
+ call assert_equal([1, 2, 3], s:call_ret)
+endfunc
+
+func Test_call()
+ call ch_log('Test_call()')
+ call s:run_server('s:test_call')
+endfunc