From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- test/functional/lua/overrides_spec.lua | 88 +++++----------------------------- 1 file changed, 11 insertions(+), 77 deletions(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index c08f3d06a9..f3ea29b8a7 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -148,9 +148,7 @@ describe('print', function() feed([[:lua print('\na')]]) screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*3 {2: }| | a | @@ -160,8 +158,7 @@ describe('print', function() feed([[:lua print('b\n\nc')]]) screen:expect{grid=[[ | - {0:~ }| - {0:~ }| + {0:~ }|*2 {2: }| b | | @@ -196,16 +193,7 @@ describe('debug.debug', function() feed(':lua Test()\n') screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*10 {1: }| nil | lua_debug> ^ | @@ -213,14 +201,7 @@ describe('debug.debug', function() feed('print("TEST")\n') screen:expect([[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*8 {1: }| nil | lua_debug> print("TEST") | @@ -230,8 +211,7 @@ describe('debug.debug', function() feed('') screen:expect{grid=[[ | - {0:~ }| - {0:~ }| + {0:~ }|*2 {1: }| nil | lua_debug> print("TEST") | @@ -247,16 +227,7 @@ describe('debug.debug', function() feed(':lua Test()\n') screen:expect([[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*10 {1: }| nil | lua_debug> ^ | @@ -264,10 +235,7 @@ describe('debug.debug', function() feed('\n') screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*4 {1: }| nil | lua_debug> | @@ -285,32 +253,14 @@ describe('debug.debug', function() feed(':lua debug.debug() print("x")') screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*12 lua_debug> ^ | ]]} feed("conttt") -- misspelled cont; invalid syntax screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*8 {1: }| lua_debug> conttt | {E:E5115: Error while loading debug string: (debug comma}| @@ -321,12 +271,7 @@ describe('debug.debug', function() feed("cont") -- exactly "cont", exit now screen:expect{grid=[[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*6 {1: }| lua_debug> conttt | {E:E5115: Error while loading debug string: (debug comma}| @@ -339,18 +284,7 @@ describe('debug.debug', function() feed('') screen:expect{grid=[[ ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*12 | ]]} end) -- cgit 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/lua/overrides_spec.lua | 156 +++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 58 deletions(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index f3ea29b8a7..0f1c7d8a51 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -42,25 +42,36 @@ describe('print', function() eq('abc', exec_capture('luafile ' .. fname)) end) it('handles errors in __tostring', function() - write_file(fname, [[ + write_file( + fname, + [[ local meta_nilerr = { __tostring = function() error(nil) end } local meta_abcerr = { __tostring = function() error("abc") end } local meta_tblout = { __tostring = function() return {"TEST"} end } v_nilerr = setmetatable({}, meta_nilerr) v_abcerr = setmetatable({}, meta_abcerr) v_tblout = setmetatable({}, meta_tblout) - ]]) + ]] + ) eq('', exec_capture('luafile ' .. fname)) -- TODO(bfredl): these look weird, print() should not use "E5114:" style errors.. - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]', - pcall_err(command, 'lua print("foo", v_nilerr, "bar")')) - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', - pcall_err(command, 'lua print("foo", v_abcerr, "bar")')) - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: ', - pcall_err(command, 'lua print("foo", v_tblout, "bar")')) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]', + pcall_err(command, 'lua print("foo", v_nilerr, "bar")') + ) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', + pcall_err(command, 'lua print("foo", v_abcerr, "bar")') + ) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: ', + pcall_err(command, 'lua print("foo", v_tblout, "bar")') + ) end) it('coerces error values into strings', function() - write_file(fname, [[ + write_file( + fname, + [[ function string_error() error("my mistake") end function number_error() error(1234) end function nil_error() error(nil) end @@ -82,27 +93,35 @@ describe('print', function() }) error(err) end - ]]) + ]] + ) eq('', exec_capture('luafile ' .. fname)) - eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake', - pcall_err(command, 'lua string_error()')) - eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234', - pcall_err(command, 'lua number_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua nil_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua table_error()')) - eq('Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake', - pcall_err(command, 'lua custom_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua bad_custom_error()')) + eq( + 'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake', + pcall_err(command, 'lua string_error()') + ) + eq( + 'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234', + pcall_err(command, 'lua number_error()') + ) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua nil_error()')) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua table_error()')) + eq( + 'Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake', + pcall_err(command, 'lua custom_error()') + ) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()')) end) it('prints strings with NULs and NLs correctly', function() meths.set_option_value('more', true, {}) - eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', - exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]])) - eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', - exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]])) + eq( + 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', + exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]) + ) + eq( + 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', + exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]]) + ) eq('T^@', exec_capture([[lua print("T\0")]])) eq('T\n', exec_capture([[lua print("T\n")]])) end) @@ -114,7 +133,8 @@ describe('print', function() eq('abc def', exec_capture('lua print("abc", "", "def")')) end) it('defers printing in luv event handlers', function() - exec_lua([[ + exec_lua( + [[ local cmd = ... function test() local timer = vim.uv.new_timer() @@ -133,7 +153,9 @@ describe('print', function() print("very slow") vim.api.nvim_command("sleep 1m") -- force deferred event processing end - ]], (is_os('win') and "timeout 1") or "sleep 0.1") + ]], + (is_os('win') and 'timeout 1') or 'sleep 0.1' + ) eq('very slow\nvery fast', exec_capture('lua test()')) end) @@ -141,22 +163,25 @@ describe('print', function() local screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ - [0] = {bold = true, foreground=Screen.colors.Blue}, - [1] = {bold = true, foreground = Screen.colors.SeaGreen}, - [2] = {bold = true, reverse = true}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, foreground = Screen.colors.SeaGreen }, + [2] = { bold = true, reverse = true }, }) feed([[:lua print('\na')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*3 {2: }| | a | {1:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('') feed([[:lua print('b\n\nc')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 {2: }| @@ -164,7 +189,8 @@ describe('print', function() | c | {1:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) end) @@ -175,10 +201,10 @@ describe('debug.debug', function() screen = Screen.new() screen:attach() screen:set_default_attr_ids { - [0] = {bold=true, foreground=255}; - [1] = {bold = true, reverse = true}; - E = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}; - cr = {bold = true, foreground = Screen.colors.SeaGreen4}; + [0] = { bold = true, foreground = 255 }, + [1] = { bold = true, reverse = true }, + E = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + cr = { bold = true, foreground = Screen.colors.SeaGreen4 }, } end) @@ -191,13 +217,15 @@ describe('debug.debug', function() end ]]) feed(':lua Test()\n') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*10 {1: }| nil | lua_debug> ^ | - ]]} + ]], + } feed('print("TEST")\n') screen:expect([[ | @@ -209,7 +237,8 @@ describe('debug.debug', function() lua_debug> ^ | ]]) feed('') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 {1: }| @@ -223,7 +252,8 @@ describe('debug.debug', function() {E: [string ":lua"]:5: in function 'Test'} | {E: [string ":lua"]:1: in main chunk} | Interrupt: {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed(':lua Test()\n') screen:expect([[ | @@ -233,7 +263,8 @@ describe('debug.debug', function() lua_debug> ^ | ]]) feed('\n') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*4 {1: }| @@ -245,20 +276,24 @@ describe('debug.debug', function() {E: [string ":lua"]:5: in function 'Test'} | {E: [string ":lua"]:1: in main chunk} | {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) it("can be safely exited with 'cont'", function() feed('') feed(':lua debug.debug() print("x")') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*12 lua_debug> ^ | - ]]} + ]], + } - feed("conttt") -- misspelled cont; invalid syntax - screen:expect{grid=[[ + feed('conttt') -- misspelled cont; invalid syntax + screen:expect { + grid = [[ | {0:~ }|*8 {1: }| @@ -266,10 +301,12 @@ describe('debug.debug', function() {E:E5115: Error while loading debug string: (debug comma}| {E:nd):1: '=' expected near ''} | lua_debug> ^ | - ]]} + ]], + } - feed("cont") -- exactly "cont", exit now - screen:expect{grid=[[ + feed('cont') -- exactly "cont", exit now + screen:expect { + grid = [[ | {0:~ }|*6 {1: }| @@ -279,14 +316,17 @@ describe('debug.debug', function() lua_debug> cont | x | {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*12 | - ]]} + ]], + } end) end) @@ -296,12 +336,12 @@ describe('os.getenv', function() end) it('returns env var set by the parent process', function() local value = 'foo' - clear({env = {['XTEST_1']=value}}) + clear({ env = { ['XTEST_1'] = value } }) eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by let', function() local value = 'foo' - meths.command('let $XTEST_1 = "'..value..'"') + meths.command('let $XTEST_1 = "' .. value .. '"') eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) end) @@ -310,6 +350,6 @@ end) -- luajit or PUC lua 5.1. describe('bit module', function() it('works', function() - eq (9, exec_lua [[ return require'bit'.band(11,13) ]]) + eq(9, exec_lua [[ return require'bit'.band(11,13) ]]) end) end) -- cgit From d33e1da9b7f7e886219cfdd20b9bbfaccdc43be9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:28:20 +0000 Subject: test: do not inject vim module into global helpers --- test/functional/lua/overrides_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 0f1c7d8a51..00458ecc34 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local feed = helpers.feed local clear = helpers.clear local funcs = helpers.funcs -- 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/lua/overrides_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 00458ecc34..1600616724 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -113,7 +113,7 @@ describe('print', function() eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()')) end) it('prints strings with NULs and NLs correctly', function() - meths.set_option_value('more', true, {}) + meths.nvim_set_option_value('more', true, {}) eq( 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]) @@ -341,7 +341,7 @@ describe('os.getenv', function() end) it('returns env var set by let', function() local value = 'foo' - meths.command('let $XTEST_1 = "' .. value .. '"') + meths.nvim_command('let $XTEST_1 = "' .. value .. '"') eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) end) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/lua/overrides_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 1600616724..12110a86c9 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -341,7 +341,7 @@ describe('os.getenv', function() end) it('returns env var set by let', function() local value = 'foo' - meths.nvim_command('let $XTEST_1 = "' .. value .. '"') + command('let $XTEST_1 = "' .. value .. '"') eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) end) -- 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/lua/overrides_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/lua/overrides_spec.lua') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 12110a86c9..ecbdde3bfd 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -6,8 +6,8 @@ local eq = helpers.eq local NIL = vim.NIL local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local write_file = helpers.write_file local exec_capture = helpers.exec_capture @@ -25,15 +25,15 @@ end) describe('print', function() it('returns nothing', function() - eq(NIL, funcs.luaeval('print("abc")')) - eq(0, funcs.luaeval('select("#", print("abc"))')) + eq(NIL, fn.luaeval('print("abc")')) + eq(0, fn.luaeval('select("#", print("abc"))')) end) it('allows catching printed text with :execute', function() - eq('\nabc', funcs.execute('lua print("abc")')) - eq('\nabc', funcs.execute('luado print("abc")')) - eq('\nabc', funcs.execute('call luaeval("print(\'abc\')")')) + eq('\nabc', fn.execute('lua print("abc")')) + eq('\nabc', fn.execute('luado print("abc")')) + eq('\nabc', fn.execute('call luaeval("print(\'abc\')")')) write_file(fname, 'print("abc")') - eq('\nabc', funcs.execute('luafile ' .. fname)) + eq('\nabc', fn.execute('luafile ' .. fname)) eq('abc', exec_capture('lua print("abc")')) eq('abc', exec_capture('luado print("abc")')) @@ -113,7 +113,7 @@ describe('print', function() eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()')) end) it('prints strings with NULs and NLs correctly', function() - meths.nvim_set_option_value('more', true, {}) + api.nvim_set_option_value('more', true, {}) eq( 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]) @@ -332,17 +332,17 @@ end) describe('os.getenv', function() it('returns nothing for undefined env var', function() - eq(NIL, funcs.luaeval('os.getenv("XTEST_1")')) + eq(NIL, fn.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by the parent process', function() local value = 'foo' clear({ env = { ['XTEST_1'] = value } }) - eq(value, funcs.luaeval('os.getenv("XTEST_1")')) + eq(value, fn.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by let', function() local value = 'foo' command('let $XTEST_1 = "' .. value .. '"') - eq(value, funcs.luaeval('os.getenv("XTEST_1")')) + eq(value, fn.luaeval('os.getenv("XTEST_1")')) end) end) -- cgit