File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -710,10 +710,11 @@ H.create_default_hl =
710710
711711-- Evaluate -------------------------------------------------------------------
712712H .eval_lua_lines = function (lines )
713- local n = # lines
714- lines [n ] = (lines [n ]:find (' ^%s*return%s+' ) == nil and ' return ' or ' ' ) .. lines [n ]
713+ -- Copy to not modify input
714+ local lines_copy , n = vim .deepcopy (lines ), # lines
715+ lines_copy [n ] = (lines_copy [n ]:find (' ^%s*return%s+' ) == nil and ' return ' or ' ' ) .. lines_copy [n ]
715716
716- local str_to_eval = table.concat (lines , ' \n ' )
717+ local str_to_eval = table.concat (lines_copy , ' \n ' )
717718
718719 -- Allow returning tuple with any value(s) being `nil`
719720 return H .inspect_objects (assert (loadstring (str_to_eval ))())
Original file line number Diff line number Diff line change @@ -338,6 +338,22 @@ T['default_evaluate_func()']['works for blockwise'] = function()
338338 validate ({ ' _G.y + 1' }, { ' 2' })
339339end
340340
341+ T [' default_evaluate_func()' ][' does not modify input' ] = function ()
342+ local validate = function (content )
343+ local lua_cmd = string.format (
344+ [[ _G.content = %s
345+ MiniOperators.default_evaluate_func(_G.content)]] ,
346+ vim .inspect (content )
347+ )
348+ child .lua (lua_cmd )
349+ eq (child .lua_get (' _G.content' ), content )
350+ end
351+
352+ validate ({ lines = { ' 1 + 1' }, submode = ' v' })
353+ validate ({ lines = { ' 1 + 1' }, submode = ' V' })
354+ validate ({ lines = { ' 1 + 1' , ' 1 + 2' }, submode = ' \22 ' })
355+ end
356+
341357T [' default_evaluate_func()' ][' validates arguments' ] = function ()
342358 expect .error (default_evaluate_func , ' `content`' , 1 )
343359 expect .error (default_evaluate_func , ' `content`' , {})
You can’t perform that action at this time.
0 commit comments