From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/vimscript/writefile_spec.lua | 138 ++++++++++++++++----------- 1 file changed, 82 insertions(+), 56 deletions(-) (limited to 'test/functional/vimscript/writefile_spec.lua') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 88c19bd839..b83d6c4a25 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -52,125 +52,151 @@ describe('writefile()', function() end) it('writes list with an empty string to a file', function() - eq(0, exc_exec( - ('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s", "b")'):format( - fname))) + eq(0, exc_exec(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s", "b")'):format(fname))) eq('', read_file(fname)) - eq(0, exc_exec(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s")'):format( - fname))) + eq(0, exc_exec(('call writefile([$XXX_NONEXISTENT_VAR_XXX], "%s")'):format(fname))) eq('\n', read_file(fname)) end) it('writes list with a null string to a file', function() - eq(0, exc_exec( - ('call writefile([v:_null_string], "%s", "b")'):format( - fname))) + eq(0, exc_exec(('call writefile([v:_null_string], "%s", "b")'):format(fname))) eq('', read_file(fname)) - eq(0, exc_exec(('call writefile([v:_null_string], "%s")'):format( - fname))) + eq(0, exc_exec(('call writefile([v:_null_string], "%s")'):format(fname))) eq('\n', read_file(fname)) end) it('appends to a file', function() eq(nil, read_file(fname)) - eq(0, funcs.writefile({'abc', 'def', 'ghi'}, fname)) + eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname)) eq('abc\ndef\nghi\n', read_file(fname)) - eq(0, funcs.writefile({'jkl'}, fname, 'a')) + eq(0, funcs.writefile({ 'jkl' }, fname, 'a')) eq('abc\ndef\nghi\njkl\n', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({'abc', 'def', 'ghi'}, fname, 'b')) + eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname, 'b')) eq('abc\ndef\nghi', read_file(fname)) - eq(0, funcs.writefile({'jkl'}, fname, 'ab')) + eq(0, funcs.writefile({ 'jkl' }, fname, 'ab')) eq('abc\ndef\nghijkl', read_file(fname)) end) it('correctly treats NLs', function() - eq(0, funcs.writefile({'\na\nb\n'}, fname, 'b')) + eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({'a\n\n\nb'}, fname, 'b')) + eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'b')) eq('a\0\0\0b', read_file(fname)) end) it('writes with s and S', function() - eq(0, funcs.writefile({'\na\nb\n'}, fname, 'bs')) + eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'bs')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({'a\n\n\nb'}, fname, 'bS')) + eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'bS')) eq('a\0\0\0b', read_file(fname)) end) it('correctly overwrites file', function() - eq(0, funcs.writefile({'\na\nb\n'}, fname, 'b')) + eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({'a\n'}, fname, 'b')) + eq(0, funcs.writefile({ 'a\n' }, fname, 'b')) eq('a\0', read_file(fname)) end) it('shows correct file name when supplied numbers', function() meths.set_current_dir(dname) - eq('Vim(call):E482: Can\'t open file 2 for writing: illegal operation on a directory', - pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail))) + eq( + "Vim(call):E482: Can't open file 2 for writing: illegal operation on a directory", + pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail)) + ) end) it('writefile(..., "p") creates missing parent directories', function() os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({'abc', 'def', 'ghi'}, dfname, 'p')) + eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, dfname, 'p')) eq('abc\ndef\nghi\n', read_file(dfname)) os.remove(dfname) os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({'\na\nb\n'}, dfname, 'pb')) + eq(0, funcs.writefile({ '\na\nb\n' }, dfname, 'pb')) eq('\0a\0b\0', read_file(dfname)) os.remove(dfname) os.remove(dname) - eq('Vim(call):E32: No file name', - pcall_err(command, ('call writefile([], "%s", "p")'):format(dfname .. '.d/'))) - eq(('Vim(call):E482: Can\'t open file ./ for writing: illegal operation on a directory'), - pcall_err(command, 'call writefile([], "./", "p")')) - eq(('Vim(call):E482: Can\'t open file . for writing: illegal operation on a directory'), - pcall_err(command, 'call writefile([], ".", "p")')) + eq( + 'Vim(call):E32: No file name', + pcall_err(command, ('call writefile([], "%s", "p")'):format(dfname .. '.d/')) + ) + eq( + "Vim(call):E482: Can't open file ./ for writing: illegal operation on a directory", + pcall_err(command, 'call writefile([], "./", "p")') + ) + eq( + "Vim(call):E482: Can't open file . for writing: illegal operation on a directory", + pcall_err(command, 'call writefile([], ".", "p")') + ) end) it('errors out with invalid arguments', function() write_file(fname, 'TEST') - eq('Vim(call):E119: Not enough arguments for function: writefile', - pcall_err(command, 'call writefile()')) - eq('Vim(call):E119: Not enough arguments for function: writefile', - pcall_err(command, 'call writefile([])')) - eq('Vim(call):E118: Too many arguments for function: writefile', - pcall_err(command, ('call writefile([], "%s", "b", 1)'):format(fname))) - for _, arg in ipairs({'0', '0.0', 'function("tr")', '{}', '"test"'}) do - eq('Vim(call):E475: Invalid argument: writefile() first argument must be a List or a Blob', - pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname))) + eq( + 'Vim(call):E119: Not enough arguments for function: writefile', + pcall_err(command, 'call writefile()') + ) + eq( + 'Vim(call):E119: Not enough arguments for function: writefile', + pcall_err(command, 'call writefile([])') + ) + eq( + 'Vim(call):E118: Too many arguments for function: writefile', + pcall_err(command, ('call writefile([], "%s", "b", 1)'):format(fname)) + ) + for _, arg in ipairs({ '0', '0.0', 'function("tr")', '{}', '"test"' }) do + eq( + 'Vim(call):E475: Invalid argument: writefile() first argument must be a List or a Blob', + pcall_err(command, ('call writefile(%s, "%s", "b")'):format(arg, fname)) + ) end - for _, args in ipairs({'[], %s, "b"', '[], "' .. fname .. '", %s'}) do - eq('Vim(call):E730: Using a List as a String', - pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) - eq('Vim(call):E731: Using a Dictionary as a String', - pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) - eq('Vim(call):E729: Using a Funcref as a String', - pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) + for _, args in ipairs({ '[], %s, "b"', '[], "' .. fname .. '", %s' }) do + eq( + 'Vim(call):E730: Using a List as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('[]'))) + ) + eq( + 'Vim(call):E731: Using a Dictionary as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('{}'))) + ) + eq( + 'Vim(call):E729: Using a Funcref as a String', + pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")'))) + ) end - eq('Vim(call):E5060: Unknown flag: «»', - pcall_err(command, ('call writefile([], "%s", "bs«»")'):format(fname))) + eq( + 'Vim(call):E5060: Unknown flag: «»', + pcall_err(command, ('call writefile([], "%s", "bs«»")'):format(fname)) + ) eq('TEST', read_file(fname)) end) it('does not write to file if error in list', function() local args = '["tset"] + repeat([%s], 3), "' .. fname .. '"' - eq('Vim(call):E805: Expected a Number or a String, Float found', - pcall_err(command, ('call writefile(%s)'):format(args:format('0.0')))) + eq( + 'Vim(call):E805: Expected a Number or a String, Float found', + pcall_err(command, ('call writefile(%s)'):format(args:format('0.0'))) + ) eq(nil, read_file(fname)) write_file(fname, 'TEST') - eq('Vim(call):E745: Expected a Number or a String, List found', - pcall_err(command, ('call writefile(%s)'):format(args:format('[]')))) + eq( + 'Vim(call):E745: Expected a Number or a String, List found', + pcall_err(command, ('call writefile(%s)'):format(args:format('[]'))) + ) eq('TEST', read_file(fname)) - eq('Vim(call):E728: Expected a Number or a String, Dictionary found', - pcall_err(command, ('call writefile(%s)'):format(args:format('{}')))) + eq( + 'Vim(call):E728: Expected a Number or a String, Dictionary found', + pcall_err(command, ('call writefile(%s)'):format(args:format('{}'))) + ) eq('TEST', read_file(fname)) - eq('Vim(call):E703: Expected a Number or a String, Funcref found', - pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")')))) + eq( + 'Vim(call):E703: Expected a Number or a String, Funcref found', + pcall_err(command, ('call writefile(%s)'):format(args:format('function("tr")'))) + ) eq('TEST', read_file(fname)) end) end) -- cgit From 284e0ad26dd9de90c3a813dd1b357a425eca6bad Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:03:25 +0000 Subject: test: use vim.mpack and vim.uv directly --- test/functional/vimscript/writefile_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/vimscript/writefile_spec.lua') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index b83d6c4a25..f03baa6ddd 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local mkdir = helpers.mkdir local clear = helpers.clear @@ -28,8 +27,8 @@ end) after_each(function() os.remove(fname) os.remove(dfname) - luv.fs_rmdir(ddname) - luv.fs_rmdir(dname) + vim.uv.fs_rmdir(ddname) + vim.uv.fs_rmdir(dname) end) describe('writefile()', function() -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/vimscript/writefile_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript/writefile_spec.lua') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index f03baa6ddd..4de542f293 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -100,7 +100,7 @@ describe('writefile()', function() end) it('shows correct file name when supplied numbers', function() - meths.set_current_dir(dname) + meths.nvim_set_current_dir(dname) eq( "Vim(call):E482: Can't open file 2 for writing: illegal operation on a directory", pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail)) -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/vimscript/writefile_spec.lua | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'test/functional/vimscript/writefile_spec.lua') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index 4de542f293..051e3794a3 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local mkdir = helpers.mkdir local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local exc_exec = helpers.exc_exec local read_file = helpers.read_file local write_file = helpers.write_file @@ -34,19 +34,19 @@ end) describe('writefile()', function() it('writes empty list to a file', function() eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname)) + eq(0, fn.writefile({}, fname)) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'b')) + eq(0, fn.writefile({}, fname, 'b')) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'ab')) + eq(0, fn.writefile({}, fname, 'ab')) eq('', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({}, fname, 'a')) + eq(0, fn.writefile({}, fname, 'a')) eq('', read_file(fname)) end) @@ -66,41 +66,41 @@ describe('writefile()', function() it('appends to a file', function() eq(nil, read_file(fname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname)) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, fname)) eq('abc\ndef\nghi\n', read_file(fname)) - eq(0, funcs.writefile({ 'jkl' }, fname, 'a')) + eq(0, fn.writefile({ 'jkl' }, fname, 'a')) eq('abc\ndef\nghi\njkl\n', read_file(fname)) os.remove(fname) eq(nil, read_file(fname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, fname, 'b')) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, fname, 'b')) eq('abc\ndef\nghi', read_file(fname)) - eq(0, funcs.writefile({ 'jkl' }, fname, 'ab')) + eq(0, fn.writefile({ 'jkl' }, fname, 'ab')) eq('abc\ndef\nghijkl', read_file(fname)) end) it('correctly treats NLs', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'b')) + eq(0, fn.writefile({ 'a\n\n\nb' }, fname, 'b')) eq('a\0\0\0b', read_file(fname)) end) it('writes with s and S', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'bs')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'bs')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n\n\nb' }, fname, 'bS')) + eq(0, fn.writefile({ 'a\n\n\nb' }, fname, 'bS')) eq('a\0\0\0b', read_file(fname)) end) it('correctly overwrites file', function() - eq(0, funcs.writefile({ '\na\nb\n' }, fname, 'b')) + eq(0, fn.writefile({ '\na\nb\n' }, fname, 'b')) eq('\0a\0b\0', read_file(fname)) - eq(0, funcs.writefile({ 'a\n' }, fname, 'b')) + eq(0, fn.writefile({ 'a\n' }, fname, 'b')) eq('a\0', read_file(fname)) end) it('shows correct file name when supplied numbers', function() - meths.nvim_set_current_dir(dname) + api.nvim_set_current_dir(dname) eq( "Vim(call):E482: Can't open file 2 for writing: illegal operation on a directory", pcall_err(command, ('call writefile([42], %s)'):format(ddname_tail)) @@ -110,12 +110,12 @@ describe('writefile()', function() it('writefile(..., "p") creates missing parent directories', function() os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({ 'abc', 'def', 'ghi' }, dfname, 'p')) + eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, dfname, 'p')) eq('abc\ndef\nghi\n', read_file(dfname)) os.remove(dfname) os.remove(dname) eq(nil, read_file(dfname)) - eq(0, funcs.writefile({ '\na\nb\n' }, dfname, 'pb')) + eq(0, fn.writefile({ '\na\nb\n' }, dfname, 'pb')) eq('\0a\0b\0', read_file(dfname)) os.remove(dfname) os.remove(dname) -- cgit