diff options
author | ZyX <kp-pav@yandex.ru> | 2017-01-29 19:26:22 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-03-27 00:12:42 +0300 |
commit | e1bbaca7acf7fc498da49081d069b00aa05506df (patch) | |
tree | 4937daf77bbfdb7389c81b9342f157be29c83c17 /test/functional/lua/commands_spec.lua | |
parent | 9114d9be778b07f4a49edc078f1c159aa51320d8 (diff) | |
download | rneovim-e1bbaca7acf7fc498da49081d069b00aa05506df.tar.gz rneovim-e1bbaca7acf7fc498da49081d069b00aa05506df.tar.bz2 rneovim-e1bbaca7acf7fc498da49081d069b00aa05506df.zip |
executor,functests: Add tests for :luado, also some fixes
Fixes:
1. Allocate space for the NUL byte.
2. Do not exclude last line from range.
3. Remove code for sandbox: it is handled earlier.
4. Fix index in new_line_transformed when converting NULs to NLs.
5. Always allocate new_line_transformed, but save allocated value.
Diffstat (limited to 'test/functional/lua/commands_spec.lua')
-rw-r--r-- | test/functional/lua/commands_spec.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index c607889edb..f1d430b34c 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -63,3 +63,48 @@ describe(':lua command', function() eq(42, funcs.luaeval('gvar')) end) end) + +describe(':luado command', function() + it('works', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('', redir_exec('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) + eq({'ABC', 'def', 'gHi'}, curbufmeths.get_lines(0, -1, false)) + eq({{1, 'ABC'}, {2, 'def'}, {3, 'gHi'}}, funcs.luaeval('lines')) + + -- Automatic transformation of numbers + eq('', redir_exec('luado return linenr')) + eq({'1', '2', '3'}, curbufmeths.get_lines(0, -1, false)) + + eq('', redir_exec('luado return ("<%02x>"):format(line:byte())')) + eq({'<31>', '<32>', '<33>'}, curbufmeths.get_lines(0, -1, false)) + end) + it('stops processing lines when suddenly out of lines', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('', redir_exec('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) + eq({''}, curbufmeths.get_lines(0, -1, false)) + eq(1, funcs.luaeval('runs')) + end) + it('works correctly when changing lines out of range', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('\nE322: line number out of range: 1 past the end\nE320: Cannot find line 2', + redir_exec('2,$luado vim.api.nvim_command("%d") return linenr')) + eq({''}, curbufmeths.get_lines(0, -1, false)) + end) + it('fails on errors', function() + eq([[Vim(luado):E5109: Error while creating lua chunk: [string "<VimL compiled string>"]:1: unexpected symbol near ')']], + exc_exec('luado ()')) + eq([[Vim(luado):E5111: Error while calling lua function: [string "<VimL compiled string>"]:1: attempt to perform arithmetic on global 'liness' (a nil value)]], + exc_exec('luado return liness + 1')) + end) + it('fails in sandbox when needed', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('\nE48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', + redir_exec('sandbox luado runs = (runs or 0) + 1')) + eq(NIL, funcs.luaeval('runs')) + end) + it('works with long strings', function() + local s = ('x'):rep(100500) + eq('', redir_exec(('luado return "%s"'):format(s))) + eq({s}, curbufmeths.get_lines(0, -1, false)) + end) +end) |