aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-21 17:08:29 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-21 17:08:29 -0300
commitaf5eaf22c529205ea75665df4a917b9294419f12 (patch)
treed204eca11f8ea4fa128016f68a1bc0f8af62ff18 /test
parent2c29b20af767bd7ebebeb41da14df4d66a19d5a0 (diff)
parentf09a33bbc131138f67aa13752559ade2d4e577c2 (diff)
downloadrneovim-af5eaf22c529205ea75665df4a917b9294419f12.tar.gz
rneovim-af5eaf22c529205ea75665df4a917b9294419f12.tar.bz2
rneovim-af5eaf22c529205ea75665df4a917b9294419f12.zip
Merge PR #1518 'Improve functional tests and perform explicit K_EVENT handling'
Diffstat (limited to 'test')
-rw-r--r--test/functional/helpers.lua50
-rw-r--r--test/functional/job/job_spec.lua11
-rw-r--r--test/functional/legacy/004_bufenter_with_modelines_spec.lua4
-rw-r--r--test/functional/legacy/101_hlsearch_spec.lua3
-rw-r--r--test/functional/shell/viml_system_spec.lua1
5 files changed, 35 insertions, 34 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 2c08fb7818..4a98056104 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -42,7 +42,6 @@ local function request(method, ...)
if not loop_stopped then
-- Except when the loop has been stopped by a notification triggered
-- by the initial request, for example.
- session:request('vim_eval', '1')
end
return rv
end
@@ -99,25 +98,20 @@ local function nvim_eval(expr)
return request('vim_eval', expr)
end
-local function nvim_feed(input, mode)
- mode = mode or ''
- request('vim_feedkeys', input, mode)
-end
-
-local function buffer_slice(start, stop, buffer_idx)
- local include_end = false
- if not stop then
- stop = -1
- include_end = true
+local function nvim_feed(input)
+ while #input > 0 do
+ local written = request('vim_input', input)
+ input = input:sub(written + 1)
end
- local buffer = request('vim_get_buffers')[buffer_idx or 1]
- local slice = request('buffer_get_line_slice', buffer, start or 0, stop,
- true, include_end)
- return table.concat(slice, '\n')
end
local function nvim_replace_termcodes(input)
- return request('vim_replace_termcodes', input, false, true, true)
+ -- small hack to stop <C-@> from being replaced by the internal
+ -- representation(which is different and won't work for vim_input)
+ local temp_replacement = 'CCCCCCCCC@@@@@@@@@@'
+ input = input:gsub('<[Cc][-]@>', temp_replacement)
+ local rv = request('vim_replace_termcodes', input, false, true, true)
+ return rv:gsub(temp_replacement, '\000')
end
local function dedent(str)
@@ -150,7 +144,7 @@ end
local function rawfeed(...)
for _, v in ipairs({...}) do
- nvim_feed(dedent(v), 'nt')
+ nvim_feed(dedent(v))
end
end
@@ -166,19 +160,19 @@ local function clear()
end
local function insert(...)
- nvim_feed('i', 'nt')
+ nvim_feed('i')
rawfeed(...)
- nvim_feed(nvim_replace_termcodes('<ESC>'), 'nt')
+ nvim_feed(nvim_replace_termcodes('<ESC>'))
end
local function execute(...)
for _, v in ipairs({...}) do
if v:sub(1, 1) ~= '/' then
-- not a search command, prefix with colon
- nvim_feed(':', 'nt')
+ nvim_feed(':')
end
- nvim_feed(v, 'nt')
- nvim_feed(nvim_replace_termcodes('<CR>'), 'nt')
+ nvim_feed(v)
+ nvim_feed(nvim_replace_termcodes('<CR>'))
end
end
@@ -200,10 +194,6 @@ local function neq(expected, actual)
return assert.are_not.same(expected, actual)
end
-local function expect(contents, first, last, buffer_index)
- return eq(dedent(contents), buffer_slice(first, last, buffer_index))
-end
-
local function ok(expr)
assert.is_true(expr)
end
@@ -233,6 +223,10 @@ local function curbuf(method, ...)
end
local function curbuf_contents()
+ -- Before inspecting the buffer, execute 'vim_eval' to wait until all
+ -- previously sent keys are processed(vim_eval is a deferred function, and
+ -- only processed after all input)
+ session:request('vim_eval', '1')
return table.concat(curbuf('get_line_slice', 0, -1, true, true), '\n')
end
@@ -252,6 +246,10 @@ local function curtab(method, ...)
return tabpage(method, tab, ...)
end
+local function expect(contents)
+ return eq(dedent(contents), curbuf_contents())
+end
+
clear()
return {
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua
index 85a1e92e38..07ca0c0058 100644
--- a/test/functional/job/job_spec.lua
+++ b/test/functional/job/job_spec.lua
@@ -37,7 +37,7 @@ describe('jobs', function()
end)
it('allows interactive commands', function()
- nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
+ nvim('command', notify_str('v:job_data[1]', 'get(v:job_data, 2)'))
nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
neq(0, eval('j'))
nvim('command', 'call jobsend(j, "abc\\n")')
@@ -46,9 +46,8 @@ describe('jobs', function()
eq({'notification', 'stdout', {{'123', 'xyz'}}}, next_message())
nvim('command', 'call jobsend(j, [123, "xyz"])')
eq({'notification', 'stdout', {{'123', 'xyz'}}}, next_message())
- nvim('command', notify_str('v:job_data[1])'))
nvim('command', "call jobstop(j)")
- eq({'notification', 'exit', {}}, next_message())
+ eq({'notification', 'exit', {0}}, next_message())
end)
it('preserves NULs', function()
@@ -59,9 +58,10 @@ describe('jobs', function()
file:close()
-- v:job_data preserves NULs.
- nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
+ nvim('command', notify_str('v:job_data[1]', 'get(v:job_data, 2)'))
nvim('command', "let j = jobstart('xxx', 'cat', ['"..filename.."'])")
eq({'notification', 'stdout', {{'abc\ndef'}}}, next_message())
+ eq({'notification', 'exit', {0}}, next_message())
os.remove(filename)
-- jobsend() preserves NULs.
@@ -72,12 +72,13 @@ describe('jobs', function()
end)
it('will hold data if it does not end in a newline', function()
- nvim('command', notify_str('v:job_data[1]', 'v:job_data[2]'))
+ nvim('command', notify_str('v:job_data[1]', 'get(v:job_data, 2)'))
nvim('command', "let j = jobstart('xxx', 'cat', ['-'])")
nvim('command', 'call jobsend(j, "abc\\nxyz")')
eq({'notification', 'stdout', {{'abc'}}}, next_message())
nvim('command', "call jobstop(j)")
eq({'notification', 'stdout', {{'xyz'}}}, next_message())
+ eq({'notification', 'exit', {0}}, next_message())
end)
it('will not allow jobsend/stop on a non-existent job', function()
diff --git a/test/functional/legacy/004_bufenter_with_modelines_spec.lua b/test/functional/legacy/004_bufenter_with_modelines_spec.lua
index f1222700a7..6f009b52dd 100644
--- a/test/functional/legacy/004_bufenter_with_modelines_spec.lua
+++ b/test/functional/legacy/004_bufenter_with_modelines_spec.lua
@@ -31,7 +31,7 @@ describe('BufEnter with modelines', function()
execute('sp Xxx')
-- Append text with autoindent to this file
- feed('G?this is a<Esc>')
+ feed('G?this is a<CR>')
feed('othis should be auto-indented<Esc>')
-- Go to Xxx, no autocmd anymore
@@ -39,7 +39,7 @@ describe('BufEnter with modelines', function()
execute('buf Xxx')
-- Append text without autoindent to Xxx
- feed('G?this is a<Esc>')
+ feed('G?this is a<CR>')
feed('othis should be in column 1<Esc>')
execute('wq')
diff --git a/test/functional/legacy/101_hlsearch_spec.lua b/test/functional/legacy/101_hlsearch_spec.lua
index 4a3abb19ce..3c44f02edb 100644
--- a/test/functional/legacy/101_hlsearch_spec.lua
+++ b/test/functional/legacy/101_hlsearch_spec.lua
@@ -3,6 +3,7 @@
local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect
+local eval = helpers.eval
describe('v:hlsearch', function()
setup(clear)
@@ -44,7 +45,7 @@ describe('v:hlsearch', function()
execute('$put=r')
execute('call garbagecollect(1)')
execute('call getchar()')
- execute('1d')
+ execute('1d', '1d')
-- Assert buffer contents.
expect([[
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua
index 91e115aedf..84c8765b48 100644
--- a/test/functional/shell/viml_system_spec.lua
+++ b/test/functional/shell/viml_system_spec.lua
@@ -10,6 +10,7 @@ local eq, clear, eval, feed, nvim =
local function create_file_with_nuls(name)
return function()
feed('ipart1<C-V>000part2<C-V>000part3<ESC>:w '..name..'<CR>')
+ eval('1') -- wait for the file to be created
end
end