local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local set_session, clear, assert_alive = n.set_session, n.clear, n.assert_alive
local feed, command = n.feed, n.command
local exec, exec_lua = n.exec, n.exec_lua
local insert = n.insert
local eq = t.eq
local fn, api = n.fn, n.api
describe('screen', function()
local screen
local nvim_argv = {
n.nvim_prog,
'-u',
'NONE',
'-i',
'NONE',
'-n',
'--cmd',
'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
'--cmd',
'colorscheme vim',
'--embed',
}
before_each(function()
local screen_nvim = n.new_session(false, { args = nvim_argv, merge = false })
set_session(screen_nvim)
screen = Screen.new()
end)
it('default initial screen', function()
screen:expect([[
^ |
{1:~ }|*11
{3:[No Name] }|
|
]])
end)
end)
local function screen_tests(linegrid)
local screen
before_each(function()
clear()
screen = Screen.new(53, 14, { rgb = true, ext_linegrid = linegrid })
screen:add_extra_attr_ids({
[100] = {
background = Screen.colors.LightGrey,
underline = true,
bold = true,
foreground = Screen.colors.Fuchsia,
},
[101] = { bold = true, foreground = Screen.colors.Magenta1 },
})
end)
describe('bell/visual bell', function()
it('is forwarded to the UI', function()
feed('<left>')
screen:expect(function()
eq(true, screen.bell)
eq(false, screen.visual_bell)
end)
screen.bell = false
command('set visualbell')
feed('<left>')
screen:expect(function()
eq(true, screen.visual_bell)
eq(false, screen.bell)
end)
end)
end)
describe(':set title', function()
it('is forwarded to the UI', function()
local expected = 'test-title'
command('set titlestring=' .. expected)
command('set title')
screen:expect(function()
eq(expected, screen.title)
end)
screen:detach()
screen.title = nil
screen:attach()
screen:expect(function()
eq(expected, screen.title)
end)
end)
end)
describe(':set icon', function()
it('is forwarded to the UI', function()
local expected = 'test-icon'
command('set iconstring=' .. expected)
command('set icon')
screen:expect(function()
eq(expected, screen.icon)
end)
screen:detach()
screen.icon = nil
screen:attach()
screen:expect(function()
eq(expected, screen.icon)
end)
end)
end)
describe('statusline', function()
it('is redrawn after <c-l>', function()
command('set laststatus=2')
screen:expect([[
^ |
{1:~ }|*11
{3:[No Name] }|
|
]])
feed('<c-l>')
screen:expect {
grid = [[
^ |
{1:~ }|*11
{3:[No Name] }|
|
]],
reset = true,
}
command('split')
screen:expect([[
^ |
{1:~ }|*5
{3:[No Name] }|
|
{1:~ }|*4
{2:[No Name] }|
|
]])
feed('<c-l>')
screen:expect {
grid = [[
^ |
{1:~ }|*5
{3:[No Name] }|
|
{1:~ }|*4
{2:[No Name] }|
|
]],
reset = true,
}
end)
end)
describe('window', function()
describe('split', function()
it('horizontal', function()
command('sp')
screen:expect([[
^ |
{1:~ }|*5
{3:[No Name] }|
|
{1:~ }|*4
{2:[No Name] }|
|
]])
end)
it('horizontal and resize', function()
command('sp')
command('resize 8')
screen:expect([[
^ |
{1:~ }|*7
{3:[No Name] }|
|
{1:~ }|*2
{2:[No Name] }|
|
]])
end)
it('horizontal and vertical', function()
command('sp')
command('vsp')
command('vsp')
screen:expect([[
^ │ │ |
{1:~ }│{1:~ }│{1:~ }|*5
{3:[No Name] }{2:[No Name] [No Name] }|
|
{1:~ }|*4
{2:[No Name] }|
|
]])
insert('hello')
screen:expect([[
hell^o │hello │hello |
{1:~ }│{1:~ }│{1:~ }|*5
{3:[No Name] [+] }{2:[No Name] [+] [No Name] [+] }|
hello |
{1:~ }|*4
{2:[No Name] [+] }|
|
]])
end)
end)
end)
describe('tabs', function()
it('tabnew creates a new buffer', function()
command('sp')
command('vsp')
command('vsp')
insert('hello')
screen:expect([[
hell^o │hello │hello |
{1:~ }│{1:~ }│{1:~ }|*5
{3:[No Name] [+] }{2:[No Name] [+] [No Name] [+] }|
hello |
{1:~ }|*4
{2:[No Name] [+] }|
|
]])
command('tabnew')
insert('hello2')
feed('h')
screen:expect([[
{24: }{100:4}{24:+ [No Name] }{5: + [No Name] }{2: }{24:X}|
|