From c2433589dca022a7f40cdcbd0cd1ad8aba6ee4a9 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Sat, 27 Jan 2024 02:00:50 +0100 Subject: feat(ex_cmds): ranged :lua #27167 :{range}lua executes the specified lines in the current buffer as Lua code, regardless of its extension or 'filetype'. Close #27103 --- test/functional/lua/commands_spec.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/functional/lua/commands_spec.lua') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 28a99a86f8..083f6f3541 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -55,6 +55,12 @@ describe(':lua command', function() ) end) it('throws catchable errors', function() + for _, cmd in ipairs({ 'lua', '1lua chunk' }) do + eq( + 'Vim(lua):E475: Invalid argument: exactly one of {chunk} and {range} required', + pcall_err(command, cmd) + ) + end eq( [[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']], pcall_err(command, 'lua ()') @@ -192,6 +198,25 @@ describe(':lua command', function() exec_capture('=x(false)') ) end) + + it('works with range in current buffer', function() + local screen = Screen.new(40, 10) + screen:attach() + api.nvim_buf_set_lines(0, 0, 0, 0, { 'function x() print "hello" end', 'x()' }) + feed(':1,2lua') + screen:expect { + grid = [[ + function x() print "hello" end | + x() | + ^ | + {1:~ }|*6 + hello | + ]], + attr_ids = { + [1] = { foreground = Screen.colors.Blue, bold = true }, + }, + } + end) end) describe(':luado command', function() -- cgit