aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-18 15:57:42 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-18 15:57:42 -0300
commit9e37c1d3b6b9d0d35d7f7558d3efb555757278c0 (patch)
treeabff58ba79dddfbf4d3667c7fdcf1642546f4c51 /test
parenta67fd6f21378bc01b41e5349abff2eb214f6c288 (diff)
parentd971cb169184a1fa59e93a5216635261d8c47e11 (diff)
downloadrneovim-9e37c1d3b6b9d0d35d7f7558d3efb555757278c0.tar.gz
rneovim-9e37c1d3b6b9d0d35d7f7558d3efb555757278c0.tar.bz2
rneovim-9e37c1d3b6b9d0d35d7f7558d3efb555757278c0.zip
Merge PR #1454 'Refactor plugin system'
Diffstat (limited to 'test')
-rw-r--r--test/functional/runtime/autoload/provider/python_spec.lua93
-rw-r--r--test/functional/runtime/autoload/rpc/define_spec.lua365
2 files changed, 458 insertions, 0 deletions
diff --git a/test/functional/runtime/autoload/provider/python_spec.lua b/test/functional/runtime/autoload/provider/python_spec.lua
new file mode 100644
index 0000000000..1a726652d6
--- /dev/null
+++ b/test/functional/runtime/autoload/provider/python_spec.lua
@@ -0,0 +1,93 @@
+do
+ local proc =
+ io.popen([[python -c 'import neovim, sys; sys.stdout.write("ok")' 2> /dev/null]])
+ if proc:read() ~= 'ok' then
+ -- Don't run these tests if python is not available
+ return
+ end
+end
+
+
+local helpers = require('test.functional.helpers')
+local eval, command, feed = helpers.eval, helpers.command, helpers.feed
+local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
+local expect = helpers.expect
+
+
+describe('python commands and functions', function()
+ before_each(function()
+ clear()
+ command('python import vim')
+ end)
+
+ describe('feature test', function()
+ it('ok', function()
+ eq(1, eval('has("python")'))
+ end)
+ end)
+
+ describe('python_execute', function()
+ it('ok', function()
+ command('python vim.vars["set_by_python"] = [100, 0]')
+ eq({100, 0}, eval('g:set_by_python'))
+ end)
+ end)
+
+ describe('python_execute with nested commands', function()
+ it('ok', function()
+ command([[python vim.command('python vim.command("python vim.command(\'let set_by_nested_python = 555\')")')]])
+ eq(555, eval('g:set_by_nested_python'))
+ end)
+ end)
+
+ describe('python_execute with range', function()
+ it('ok', function()
+ insert([[
+ line1
+ line2
+ line3
+ line4]])
+ feed('ggjvj:python vim.vars["range"] = vim.current.range[:]<CR>')
+ eq({'line2', 'line3'}, eval('g:range'))
+ end)
+ end)
+
+ describe('pyfile', function()
+ it('ok', function()
+ local fname = 'pyfile.py'
+ local F = io.open(fname, 'w')
+ F:write('vim.command("let set_by_pyfile = 123")')
+ F:close()
+ command('pyfile pyfile.py')
+ eq(123, eval('g:set_by_pyfile'))
+ os.remove(fname)
+ end)
+ end)
+
+ describe('pydo', function()
+ it('ok', function()
+ -- :pydo 42 returns None for all lines,
+ -- the buffer should not be changed
+ command('normal :pydo 42')
+ eq(0, eval('&mod'))
+ -- insert some text
+ insert('abc\ndef\nghi')
+ expect([[
+ abc
+ def
+ ghi]])
+ -- go to top and select and replace the first two lines
+ feed('ggvj:pydo return str(linenr)<CR>')
+ expect([[
+ 1
+ 2
+ ghi]])
+ end)
+ end)
+
+ describe('pyeval', function()
+ it('ok', function()
+ eq({1, 2, {['key'] = 'val'}}, eval([[pyeval('[1, 2, {"key": "val"}]')]]))
+ end)
+ end)
+end)
diff --git a/test/functional/runtime/autoload/rpc/define_spec.lua b/test/functional/runtime/autoload/rpc/define_spec.lua
new file mode 100644
index 0000000000..a85ba4d37b
--- /dev/null
+++ b/test/functional/runtime/autoload/rpc/define_spec.lua
@@ -0,0 +1,365 @@
+local helpers = require('test.functional.helpers')
+local eval, command, nvim = helpers.eval, helpers.command, helpers.nvim
+local eq, run, stop = helpers.eq, helpers.run, helpers.stop
+local clear, feed = helpers.clear, helpers.feed
+
+
+local function get_prefix(sync)
+ if sync then
+ return 'sync'
+ end
+ return 'async'
+end
+
+
+local function call(fn, args)
+ command('call '..fn..'('..args..')')
+end
+
+
+local function clear_and_init(init)
+ return function()
+ clear()
+ if init then
+ init()
+ end
+ end
+end
+
+
+local function runx(sync, handler, on_setup)
+ local function setup_cb(...)
+ on_setup(...)
+ -- need to stop on setup callback because there's two session:request
+ -- calls in `request/helpers.lua`. The second call will always return
+ -- after pending notification/request callbacks are processed
+ stop()
+ end
+ local function handler_cb(...)
+ return handler(...)
+ end
+ if sync then
+ run(handler_cb, nil, setup_cb)
+ else
+ run(nil, handler_cb, setup_cb)
+ end
+end
+
+local function command_specs_for(fn, sync, first_arg_factory, init)
+ local prefix = get_prefix(sync)
+
+ describe(prefix..' command created by', function()
+ before_each(clear_and_init(init))
+
+ describe(fn, function()
+ local args
+
+ before_each(function()
+ args = first_arg_factory()..', "test-handler", '
+ if sync then
+ args = args .. '1'
+ else
+ args = args .. '0'
+ end
+ args = args..', "RpcCommand"'
+ end)
+
+ describe('without options', function()
+ it('ok', function()
+ call(fn, args..', {}')
+ local function on_setup()
+ command('RpcCommand')
+ end
+
+ local function handler(method)
+ eq('test-handler', method)
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "*"}')
+ local function on_setup()
+ command('RpcCommand arg1 arg2 arg3')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg1', 'arg2', 'arg3'}, args[1])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with range', function()
+ it('ok', function()
+ call(fn,args..', {"range": ""}')
+ local function on_setup()
+ command('1,1RpcCommand')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({1, 1}, args[1])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs/range', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "1", "range": ""}')
+ local function on_setup()
+ command('1,1RpcCommand arg')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg'}, args[1])
+ eq({1, 1}, args[2])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs/count', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "1", "range": "5"}')
+ local function on_setup()
+ command('5RpcCommand arg')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg'}, args[1])
+ eq(5, args[2])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs/count/bang', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}')
+ local function on_setup()
+ command('5RpcCommand! arg')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg'}, args[1])
+ eq(5, args[2])
+ eq(1, args[3])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs/count/bang/register', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'..
+ ' "register": ""}')
+ local function on_setup()
+ command('5RpcCommand! b arg')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg'}, args[1])
+ eq(5, args[2])
+ eq(1, args[3])
+ eq('b', args[4])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with nargs/count/bang/register/eval', function()
+ it('ok', function()
+ call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'..
+ ' "register": "", "eval": "@<reg>"}')
+ local function on_setup()
+ command('let @b = "regb"')
+ command('5RpcCommand! b arg')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({'arg'}, args[1])
+ eq(5, args[2])
+ eq(1, args[3])
+ eq('b', args[4])
+ eq('regb', args[5])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+ end)
+ end)
+end
+
+
+local function autocmd_specs_for(fn, sync, first_arg_factory, init)
+ local prefix = get_prefix(sync)
+
+ describe(prefix..' autocmd created by', function()
+ before_each(clear_and_init(init))
+
+ describe(fn, function()
+ local args
+
+ before_each(function()
+ args = first_arg_factory()..', "test-handler", '
+ if sync then
+ args = args .. '1'
+ else
+ args = args .. '0'
+ end
+ args = args..', "BufEnter"'
+ end)
+
+ describe('without options', function()
+ it('ok', function()
+ call(fn, args..', {}')
+ local function on_setup()
+ command('doautocmd BufEnter x.c')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with eval', function()
+ it('ok', function()
+ call(fn, args..[[, {'eval': 'expand("<afile>")'}]])
+ local function on_setup()
+ command('doautocmd BufEnter x.c')
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq('x.c', args[1])
+ return ''
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+ end)
+ end)
+end
+
+
+local function function_specs_for(fn, sync, first_arg_factory, init)
+ local prefix = get_prefix(sync)
+
+ describe(prefix..' function created by', function()
+ before_each(clear_and_init(init))
+
+ describe(fn, function()
+ local args
+
+ before_each(function()
+ args = first_arg_factory()..', "test-handler", '
+ if sync then
+ args = args .. '1'
+ else
+ args = args .. '0'
+ end
+ args = args..', "TestFunction"'
+ end)
+
+ describe('without options', function()
+ it('ok', function()
+ call(fn, args..', {}')
+ local function on_setup()
+ if sync then
+ eq('rv', eval('TestFunction(1, "a", ["b", "c"])'))
+ else
+ eq(1, eval('TestFunction(1, "a", ["b", "c"])'))
+ end
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({{1, 'a', {'b', 'c'}}}, args)
+ return 'rv'
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+
+ describe('with eval', function()
+ it('ok', function()
+ call(fn, args..[[, {'eval': '2 + 2'}]])
+ local function on_setup()
+ if sync then
+ eq('rv', eval('TestFunction(1, "a", ["b", "c"])'))
+ else
+ eq(1, eval('TestFunction(1, "a", ["b", "c"])'))
+ end
+ end
+
+ local function handler(method, args)
+ eq('test-handler', method)
+ eq({{1, 'a', {'b', 'c'}}, 4}, args)
+ return 'rv'
+ end
+
+ runx(sync, handler, on_setup)
+ end)
+ end)
+ end)
+ end)
+end
+
+local function channel()
+ return nvim('get_api_info')[1]
+end
+
+local function host()
+ return '"busted"'
+end
+
+local function register()
+ eval('rpc#host#Register("busted", '..channel()..')')
+end
+
+command_specs_for('rpc#define#CommandOnChannel', true, channel)
+command_specs_for('rpc#define#CommandOnChannel', false, channel)
+command_specs_for('rpc#define#CommandOnHost', true, host, register)
+command_specs_for('rpc#define#CommandOnHost', false, host, register)
+
+autocmd_specs_for('rpc#define#AutocmdOnChannel', true, channel)
+autocmd_specs_for('rpc#define#AutocmdOnChannel', false, channel)
+autocmd_specs_for('rpc#define#AutocmdOnHost', true, host, register)
+autocmd_specs_for('rpc#define#AutocmdOnHost', false, host, register)
+
+function_specs_for('rpc#define#FunctionOnChannel', true, channel)
+function_specs_for('rpc#define#FunctionOnChannel', false, channel)
+function_specs_for('rpc#define#FunctionOnHost', true, host, register)
+function_specs_for('rpc#define#FunctionOnHost', false, host, register)