diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
commit | 9243becbedbb6a1592208051f8fa2b090dcc5e7d (patch) | |
tree | 607c2a862ec3f4399b8766383f6f8e04c4aa43b4 /test/functional/api/window_spec.lua | |
parent | 9e40b6e9e1bc67f2d856adb837ee64dd0e25b717 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-9243becbedbb6a1592208051f8fa2b090dcc5e7d.tar.gz rneovim-9243becbedbb6a1592208051f8fa2b090dcc5e7d.tar.bz2 rneovim-9243becbedbb6a1592208051f8fa2b090dcc5e7d.zip |
Merge remote-tracking branch 'upstream/master' into usermarksusermarks
Diffstat (limited to 'test/functional/api/window_spec.lua')
-rw-r--r-- | test/functional/api/window_spec.lua | 183 |
1 files changed, 150 insertions, 33 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 901d24327c..ecab6a4713 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -7,6 +7,7 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, helpers.tabpage local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths +local exec = helpers.exec local funcs = helpers.funcs local request = helpers.request local NIL = helpers.NIL @@ -15,25 +16,6 @@ local command = helpers.command local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive --- check if str is visible at the beginning of some line -local function is_visible(str) - local slen = string.len(str) - local nlines = eval("&lines") - for i = 1,nlines do - local iseq = true - for j = 1,slen do - if string.byte(str,j) ~= eval("screenchar("..i..","..j..")") then - iseq = false - break - end - end - if iseq then - return true - end - end - return false -end - describe('API/win', function() before_each(clear) @@ -79,27 +61,61 @@ describe('API/win', function() end) it('updates the screen, and also when the window is unfocused', function() + local screen = Screen.new(30, 9) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, + [2] = {bold = true, reverse = true}; + [3] = {reverse = true}; + }) + screen:attach() + insert("prologue") feed('100o<esc>') insert("epilogue") local win = curwin() feed('gg') - poke_eventloop() -- let nvim process the 'gg' command + screen:expect{grid=[[ + ^prologue | + | + | + | + | + | + | + | + | + ]]} -- cursor position is at beginning eq({1, 0}, window('get_cursor', win)) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) -- move cursor to end window('set_cursor', win, {101, 0}) - eq(false, is_visible("prologue")) - eq(true, is_visible("epilogue")) + screen:expect{grid=[[ + | + | + | + | + | + | + | + ^epilogue | + | + ]]} -- move cursor to the beginning again window('set_cursor', win, {1, 0}) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^prologue | + | + | + | + | + | + | + | + | + ]]} -- move focus to new window nvim('command',"new") @@ -107,18 +123,45 @@ describe('API/win', function() -- sanity check, cursor position is kept eq({1, 0}, window('get_cursor', win)) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + prologue | + | + | + {3:[No Name] [+] }| + | + ]]} -- move cursor to end window('set_cursor', win, {101, 0}) - eq(false, is_visible("prologue")) - eq(true, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + | + | + epilogue | + {3:[No Name] [+] }| + | + ]]} -- move cursor to the beginning again window('set_cursor', win, {1, 0}) - eq(true, is_visible("prologue")) - eq(false, is_visible("epilogue")) + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {2:[No Name] }| + prologue | + | + | + {3:[No Name] [+] }| + | + ]]} -- curwin didn't change back neq(win, curwin()) @@ -187,6 +230,46 @@ describe('API/win', function() | ]]) end) + + it('updates cursorcolumn in non-current window', function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {background = Screen.colors.Grey90}, -- CursorColumn + [3] = {bold = true, reverse = true}, -- StatusLine + [4] = {reverse = true}, -- StatusLineNC + }) + screen:attach() + command('set cursorcolumn') + insert([[ + aaa + bbb + ccc + ddd]]) + local oldwin = curwin() + command('vsplit') + screen:expect([[ + aa{2:a} │aa{2:a} | + bb{2:b} │bb{2:b} | + cc{2:c} │cc{2:c} | + dd^d │ddd | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {3:[No Name] [+] }{4:[No Name] [+] }| + | + ]]) + window('set_cursor', oldwin, {2, 0}) + screen:expect([[ + aa{2:a} │{2:a}aa | + bb{2:b} │bbb | + cc{2:c} │{2:c}cc | + dd^d │{2:d}dd | + {1:~ }│{1:~ }| + {1:~ }│{1:~ }| + {3:[No Name] [+] }{4:[No Name] [+] }| + | + ]]) + end) end) describe('{get,set}_height', function() @@ -201,6 +284,22 @@ describe('API/win', function() window('set_height', nvim('list_wins')[2], 2) eq(2, window('get_height', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + new + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_height(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set}_width', function() @@ -215,6 +314,22 @@ describe('API/win', function() window('set_width', nvim('list_wins')[2], 2) eq(2, window('get_width', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + vnew + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_width(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set,del}_var', function() @@ -408,6 +523,8 @@ describe('API/win', function() it('closing current (float) window of another tabpage #15313', function() command('tabedit') + command('botright split') + local prevwin = curwin().id eq(2, eval('tabpagenr()')) local win = meths.open_win(0, true, { relative='editor', row=10, col=10, width=50, height=10 @@ -417,7 +534,7 @@ describe('API/win', function() eq(1, eval('tabpagenr()')) meths.win_close(win, false) - eq(1001, meths.tabpage_get_win(tab).id) + eq(prevwin, meths.tabpage_get_win(tab).id) assert_alive() end) end) |