mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 06:58:35 +00:00
test: update writefile test for invalid list items
It validates list items with tv_check_str_on_nr() to catch invalid types (ex. E745, E805). If there is an invalid item, it does not write to the file.
This commit is contained in:
@@ -21,7 +21,7 @@ func Test_writefile_fails_gently()
|
|||||||
call assert_false(filereadable("Xfile"))
|
call assert_false(filereadable("Xfile"))
|
||||||
call delete("Xfile")
|
call delete("Xfile")
|
||||||
|
|
||||||
call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:')
|
call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E745:')
|
||||||
call assert_false(filereadable("Xfile"))
|
call assert_false(filereadable("Xfile"))
|
||||||
call delete("Xfile")
|
call delete("Xfile")
|
||||||
|
|
||||||
|
@@ -127,23 +127,20 @@ describe('writefile()', function()
|
|||||||
eq('TEST', read_file(fname))
|
eq('TEST', read_file(fname))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('stops writing to file after error in list', function()
|
it('does not write to file if error in list', function()
|
||||||
local args = '["tset"] + repeat([%s], 3), "' .. fname .. '"'
|
local args = '["tset"] + repeat([%s], 3), "' .. fname .. '"'
|
||||||
eq('\nE806: using Float as a String',
|
eq('\nE805: Expected a Number or a String, Float found',
|
||||||
redir_exec(('call writefile(%s)'):format(args:format('0.0'))))
|
redir_exec(('call writefile(%s)'):format(args:format('0.0'))))
|
||||||
eq('tset\n', read_file(fname))
|
eq(nil, read_file(fname))
|
||||||
write_file(fname, 'TEST')
|
write_file(fname, 'TEST')
|
||||||
eq('\nE730: using List as a String',
|
eq('\nE745: Expected a Number or a String, List found',
|
||||||
redir_exec(('call writefile(%s)'):format(args:format('[]'))))
|
redir_exec(('call writefile(%s)'):format(args:format('[]'))))
|
||||||
eq('tset\n', read_file(fname))
|
eq('TEST', read_file(fname))
|
||||||
write_file(fname, 'TEST')
|
eq('\nE728: Expected a Number or a String, Dictionary found',
|
||||||
eq('\nE731: using Dictionary as a String',
|
|
||||||
redir_exec(('call writefile(%s)'):format(args:format('{}'))))
|
redir_exec(('call writefile(%s)'):format(args:format('{}'))))
|
||||||
eq('tset\n', read_file(fname))
|
eq('TEST', read_file(fname))
|
||||||
write_file(fname, 'TEST')
|
eq('\nE703: Expected a Number or a String, Funcref found',
|
||||||
eq('\nE729: using Funcref as a String',
|
|
||||||
redir_exec(('call writefile(%s)'):format(args:format('function("tr")'))))
|
redir_exec(('call writefile(%s)'):format(args:format('function("tr")'))))
|
||||||
eq('tset\n', read_file(fname))
|
eq('TEST', read_file(fname))
|
||||||
write_file(fname, 'TEST')
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user