Mercurial > vim
diff src/testdir/test_channel.vim @ 15454:1d2b5c016f17 v8.1.0735
patch 8.1.0735: cannot handle binary data
commit https://github.com/vim/vim/commit/6e5ea8d2a995b32bbc5972edc4f827b959f2702f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 12 22:47:31 2019 +0100
patch 8.1.0735: cannot handle binary data
Problem: Cannot handle binary data.
Solution: Add the Blob type. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/3638)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Jan 2019 23:00:06 +0100 |
parents | 440e5071f3f8 |
children | 3137345451a4 |
line wrap: on
line diff
--- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -516,6 +516,51 @@ func Test_raw_pipe() call assert_equal(1, found) endfunc +func Test_raw_pipe_blob() + if !has('job') + return + endif + call ch_log('Test_raw_pipe_blob()') + " Add a dummy close callback to avoid that messages are dropped when calling + " ch_canread(). + " Also test the non-blocking option. + let job = job_start(s:python . " test_channel_pipe.py", + \ {'mode': 'raw', 'drop': 'never', 'noblock': 1}) + call assert_equal(v:t_job, type(job)) + call assert_equal("run", job_status(job)) + + call assert_equal("open", ch_status(job)) + call assert_equal("open", ch_status(job), {"part": "out"}) + + try + " Create a blob with the echo command and write it. + let blob = 0z00 + let cmd = "echo something\n" + for i in range(0, len(cmd) - 1) + let blob[i] = char2nr(cmd[i]) + endfor + call assert_equal(len(cmd), len(blob)) + call ch_sendraw(job, blob) + + " Read a blob with the reply. + let msg = ch_readblob(job) + let expected = 'something' + for i in range(0, len(expected) - 1) + call assert_equal(char2nr(expected[i]), msg[i]) + endfor + + let reply = ch_evalraw(job, "quit\n", {'timeout': 100}) + call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) + finally + call job_stop(job) + endtry + + let g:Ch_job = job + call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))}) + let info = job_info(job) + call assert_equal("dead", info.status) +endfunc + func Test_nl_pipe() if !has('job') return