From e61228a214ebda9845db9462dad0a8c362d3963f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Nov 2024 22:15:19 +0100 Subject: fix(tests): needing two calls to setup a screen is cringe Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session. --- test/functional/editor/completion_spec.lua | 1 - test/functional/editor/ctrl_c_spec.lua | 1 - test/functional/editor/defaults_spec.lua | 3 --- test/functional/editor/jump_spec.lua | 6 ------ test/functional/editor/mark_spec.lua | 4 ---- test/functional/editor/mode_cmdline_spec.lua | 2 -- test/functional/editor/mode_insert_spec.lua | 24 +++++++----------------- test/functional/editor/mode_normal_spec.lua | 2 -- test/functional/editor/put_spec.lua | 1 - test/functional/editor/tabpage_spec.lua | 1 - 10 files changed, 7 insertions(+), 38 deletions(-) (limited to 'test/functional/editor') diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index d543de4acd..030181764d 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -17,7 +17,6 @@ describe('completion', function() before_each(function() clear() screen = Screen.new(60, 8) - screen:attach() screen:add_extra_attr_ids { [100] = { foreground = Screen.colors.Gray0, background = Screen.colors.Yellow }, [101] = { background = Screen.colors.Gray0 }, diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index e1258c7df8..cb6bc57681 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -13,7 +13,6 @@ describe('CTRL-C (mapped)', function() before_each(function() clear() screen = Screen.new(52, 6) - screen:attach() end) it('interrupts :global', function() diff --git a/test/functional/editor/defaults_spec.lua b/test/functional/editor/defaults_spec.lua index 9786bfeaac..7110d216f8 100644 --- a/test/functional/editor/defaults_spec.lua +++ b/test/functional/editor/defaults_spec.lua @@ -35,7 +35,6 @@ describe('default', function() args = { '+autocmd! nvim_popupmenu', '+aunmenu PopUp' }, } local screen = Screen.new(40, 8) - screen:attach() n.insert([[ 1 line 1 2 https://example.com @@ -58,7 +57,6 @@ describe('default', function() it('right-click on URL shows "Open in web browser"', function() n.clear() local screen = Screen.new(40, 8) - screen:attach() n.insert([[ 1 line 1 2 https://example.com @@ -100,7 +98,6 @@ describe('default', function() it('do not show a full stack trace #30625', function() n.clear({ args_rm = { '--cmd' } }) local screen = Screen.new(40, 8) - screen:attach() screen:set_default_attr_ids({ [1] = { foreground = Screen.colors.NvimDarkGray4 }, [2] = { diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index ab4cefaf84..dab8fb3fda 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -56,7 +56,6 @@ describe('jumplist', function() write_file(fname2, 'baz') local screen = Screen.new(5, 25) - screen:attach() command('set number') command('edit ' .. fname1) feed('35gg') @@ -386,7 +385,6 @@ describe('jumpoptions=view', function() it('restores the view', function() local screen = Screen.new(5, 8) - screen:attach() command('edit ' .. file1) feed('12Gztj') feed('gg') @@ -404,7 +402,6 @@ describe('jumpoptions=view', function() it('restores the view across files', function() local screen = Screen.new(5, 5) - screen:attach() command('args ' .. file1 .. ' ' .. file2) feed('12Gzt') command('next') @@ -428,7 +425,6 @@ describe('jumpoptions=view', function() it('restores the view across files with ', function() local screen = Screen.new(5, 5) - screen:attach() command('args ' .. file1 .. ' ' .. file2) feed('12Gzt') command('next') @@ -452,7 +448,6 @@ describe('jumpoptions=view', function() it("falls back to standard behavior when view can't be recovered", function() local screen = Screen.new(5, 8) - screen:attach() command('edit ' .. file1) feed('7GzbG') api.nvim_buf_set_lines(0, 0, 2, true, {}) @@ -477,7 +472,6 @@ describe('jumpoptions=view', function() it('falls back to standard behavior for a mark without a view', function() local screen = Screen.new(5, 8) - screen:attach() command('edit ' .. file1) feed('10ggzzvwy') screen:expect([[ diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 69cb95e1c3..08f90b088d 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -348,7 +348,6 @@ describe('named marks view', function() it('is restored in normal mode but not op-pending mode', function() local screen = Screen.new(5, 8) - screen:attach() command('edit ' .. file1) feed('jWma') feed("G'a") @@ -390,7 +389,6 @@ describe('named marks view', function() it('is restored across files', function() local screen = Screen.new(5, 5) - screen:attach() command('args ' .. file1 .. ' ' .. file2) feed('mA') local mark_view = [[ @@ -415,7 +413,6 @@ describe('named marks view', function() it("fallback to standard behavior when view can't be recovered", function() local screen = Screen.new(10, 10) - screen:attach() command('edit ' .. file1) feed('7GzbmaG') -- Seven lines from the top command('new') -- Screen size for window is now half the height can't be restored @@ -434,7 +431,6 @@ describe('named marks view', function() it('fallback to standard behavior when mark is loaded from shada', function() local screen = Screen.new(10, 6) - screen:attach() command('edit ' .. file1) feed('G') feed('mA') diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index bb74dfe12f..52f2bf7f8c 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -44,7 +44,6 @@ describe('cmdline', function() -- 'arabicshape' cheats and always redraws everything which trivially works, -- this test is for partial redraws in 'noarabicshape' mode. command('set noarabicshape') - screen:attach() fn.setreg('a', 'šŸ’»') feed(':test šŸ§‘ā€') screen:expect([[ @@ -69,7 +68,6 @@ describe('cmdline', function() it('redraws statusline when toggling overstrike', function() local screen = Screen.new(60, 4) - screen:attach() command('set laststatus=2 statusline=%!mode(1)') feed(':') screen:expect { diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index 87d5c46134..a9fa93590f 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -55,7 +55,6 @@ describe('insert-mode', function() it('double quote is removed after hit-enter prompt #22609', function() local screen = Screen.new(50, 6) - screen:attach() feed('i') screen:expect([[ {18:^"} | @@ -180,7 +179,6 @@ describe('insert-mode', function() it('multi-char mapping updates screen properly #25626', function() local screen = Screen.new(60, 6) - screen:attach() command('vnew') insert('foo\nfoo\nfoo') command('wincmd w') @@ -228,8 +226,7 @@ describe('insert-mode', function() end it('works with tabs and spaces', function() - local screen = Screen.new(30, 2) - screen:attach() + local _ = Screen.new(30, 2) command('setl ts=4 sw=4') set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') feed('$i') @@ -246,8 +243,7 @@ describe('insert-mode', function() end) it('works with varsofttabstop', function() - local screen = Screen.new(30, 2) - screen:attach() + local _ = Screen.new(30, 2) command('setl vsts=6,2,5,3') set_lines(0, 1, 'a\t' .. s(4) .. '\t a') feed('$i') @@ -263,8 +259,7 @@ describe('insert-mode', function() end) it('works with tab as ^I', function() - local screen = Screen.new(30, 2) - screen:attach() + local _ = Screen.new(30, 2) command('set list listchars=space:.') command('setl ts=4 sw=4') set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') @@ -280,8 +275,7 @@ describe('insert-mode', function() end) it('works in replace mode', function() - local screen = Screen.new(50, 2) - screen:attach() + local _ = Screen.new(50, 2) command('setl ts=8 sw=8 sts=8') set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') feed('$R') @@ -296,8 +290,7 @@ describe('insert-mode', function() end) it('works with breakindent', function() - local screen = Screen.new(17, 4) - screen:attach() + local _ = Screen.new(17, 4) command('setl ts=4 sw=4 bri briopt=min:5') set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') feed('$i') @@ -314,8 +307,7 @@ describe('insert-mode', function() end) it('works with inline virtual text', function() - local screen = Screen.new(50, 2) - screen:attach() + local _ = Screen.new(50, 2) command('setl ts=4 sw=4') set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') local ns = api.nvim_create_namespace('') @@ -335,8 +327,7 @@ describe('insert-mode', function() end) it("works with 'revins'", function() - local screen = Screen.new(30, 3) - screen:attach() + local _ = Screen.new(30, 3) command('setl ts=4 sw=4 revins') set_lines(0, 1, ('a'):rep(16), s(3) .. '\t' .. s(4) .. '\t a') feed('j$i') @@ -354,7 +345,6 @@ describe('insert-mode', function() it('backspace after replacing multibyte chars', function() local screen = Screen.new(30, 3) - screen:attach() api.nvim_buf_set_lines(0, 0, -1, true, { 'test aĢŸĢ‡ĢšĢœĢĢ…mĢ†Ģ‰ĢĢĢ‡Ģˆ Ć„' }) feed('^Rabcdefghi') screen:expect([[ diff --git a/test/functional/editor/mode_normal_spec.lua b/test/functional/editor/mode_normal_spec.lua index cca244e06c..5237f51237 100644 --- a/test/functional/editor/mode_normal_spec.lua +++ b/test/functional/editor/mode_normal_spec.lua @@ -26,7 +26,6 @@ describe('Normal mode', function() it('&showcmd does not crash with :startinsert #28419', function() local screen = Screen.new(60, 17) - screen:attach() fn.termopen( { n.nvim_prog, '--clean', '--cmd', 'startinsert' }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } } @@ -45,7 +44,6 @@ describe('Normal mode', function() it('replacing with ZWJ emoji sequences', function() local screen = Screen.new(30, 8) - screen:attach() api.nvim_buf_set_lines(0, 0, -1, true, { 'abcdefg' }) feed('05ršŸ§‘ā€šŸŒ¾') -- ZWJ screen:expect([[ diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 0f6936cd31..79f9d97bc5 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -883,7 +883,6 @@ describe('put command', function() local screen setup(function() screen = Screen.new() - screen:attach() end) local function bell_test(actions, should_ring) diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index c20a6e5cb5..b6fbebb20c 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -105,7 +105,6 @@ describe('tabpage', function() screen:add_extra_attr_ids { [100] = { bold = true, foreground = Screen.colors.Fuchsia }, } - screen:attach() command('tabnew') command('tabprev') -- cgit