From ce17d031805ab548f26f5b2d519fb8e3bf1bbff1 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 20 Apr 2016 13:44:12 +0200 Subject: eval: let getreg() return valid list for an undefined register vim-patch:7.4.1755 this prevents a crash when the list is used in setreg() later --- test/functional/legacy/eval_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/functional/legacy/eval_spec.lua') diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index d1ed96cc2e..3ff1092a4b 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -495,6 +495,28 @@ describe('eval', function() ' abcE4b10-4\000abcE4b10-4-2') end) + it('getreg("a",1,1) returns a valid list when "a is unset', function() + -- Precondition: "a is actually unset and "0 is nonempty + eq('', eval("getregtype('a')")) + eq('', eval("getreg('a')")) + execute("call setreg('0','text')") + + -- This used to return a NULL list + -- which setreg didn't handle + execute("let x = getreg('a',1,1)") + execute("call setreg('0',x)") + + -- nvim didn't crash and "0 was emptied + eq(2, eval("1+1")) + eq({}, eval("getreg('0',1,1)")) + + -- x is a mutable list + execute("let y = x") + eq({}, eval("y")) + execute("call add(x, 'item')") + eq({'item'}, eval("y")) + end) + it('search and expressions', function() execute('so test_eval_setup.vim') execute([=[call SetReg('/', ['abc/'])]=]) -- cgit