mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #20493 from bfredl/windowtest
test(api): migrate screenchar() test in in window API to screen test
This commit is contained in:
commit
f572718480
@ -15,25 +15,6 @@ local command = helpers.command
|
|||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
local assert_alive = helpers.assert_alive
|
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()
|
describe('API/win', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@ -79,27 +60,61 @@ describe('API/win', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('updates the screen, and also when the window is unfocused', function()
|
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")
|
insert("prologue")
|
||||||
feed('100o<esc>')
|
feed('100o<esc>')
|
||||||
insert("epilogue")
|
insert("epilogue")
|
||||||
local win = curwin()
|
local win = curwin()
|
||||||
feed('gg')
|
feed('gg')
|
||||||
poke_eventloop() -- let nvim process the 'gg' command
|
|
||||||
|
|
||||||
|
screen:expect{grid=[[
|
||||||
|
^prologue |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
]]}
|
||||||
-- cursor position is at beginning
|
-- cursor position is at beginning
|
||||||
eq({1, 0}, window('get_cursor', win))
|
eq({1, 0}, window('get_cursor', win))
|
||||||
eq(true, is_visible("prologue"))
|
|
||||||
eq(false, is_visible("epilogue"))
|
|
||||||
|
|
||||||
-- move cursor to end
|
-- move cursor to end
|
||||||
window('set_cursor', win, {101, 0})
|
window('set_cursor', win, {101, 0})
|
||||||
eq(false, is_visible("prologue"))
|
screen:expect{grid=[[
|
||||||
eq(true, is_visible("epilogue"))
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
^epilogue |
|
||||||
|
|
|
||||||
|
]]}
|
||||||
|
|
||||||
-- move cursor to the beginning again
|
-- move cursor to the beginning again
|
||||||
window('set_cursor', win, {1, 0})
|
window('set_cursor', win, {1, 0})
|
||||||
eq(true, is_visible("prologue"))
|
screen:expect{grid=[[
|
||||||
eq(false, is_visible("epilogue"))
|
^prologue |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
]]}
|
||||||
|
|
||||||
-- move focus to new window
|
-- move focus to new window
|
||||||
nvim('command',"new")
|
nvim('command',"new")
|
||||||
@ -107,18 +122,45 @@ describe('API/win', function()
|
|||||||
|
|
||||||
-- sanity check, cursor position is kept
|
-- sanity check, cursor position is kept
|
||||||
eq({1, 0}, window('get_cursor', win))
|
eq({1, 0}, window('get_cursor', win))
|
||||||
eq(true, is_visible("prologue"))
|
screen:expect{grid=[[
|
||||||
eq(false, is_visible("epilogue"))
|
^ |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
prologue |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
{3:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]]}
|
||||||
|
|
||||||
-- move cursor to end
|
-- move cursor to end
|
||||||
window('set_cursor', win, {101, 0})
|
window('set_cursor', win, {101, 0})
|
||||||
eq(false, is_visible("prologue"))
|
screen:expect{grid=[[
|
||||||
eq(true, is_visible("epilogue"))
|
^ |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
epilogue |
|
||||||
|
{3:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]]}
|
||||||
|
|
||||||
-- move cursor to the beginning again
|
-- move cursor to the beginning again
|
||||||
window('set_cursor', win, {1, 0})
|
window('set_cursor', win, {1, 0})
|
||||||
eq(true, is_visible("prologue"))
|
screen:expect{grid=[[
|
||||||
eq(false, is_visible("epilogue"))
|
^ |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
prologue |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
{3:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]]}
|
||||||
|
|
||||||
-- curwin didn't change back
|
-- curwin didn't change back
|
||||||
neq(win, curwin())
|
neq(win, curwin())
|
||||||
|
Loading…
Reference in New Issue
Block a user