local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.clear
local feed, command = helpers.feed, helpers.command
local insert = helpers.insert
local eq = helpers.eq
local eval = helpers.eval
local iswin = helpers.iswin
describe('screen', function()
local screen
local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
'--embed'}
before_each(function()
local screen_nvim = spawn(nvim_argv)
set_session(screen_nvim)
screen = Screen.new()
screen:attach()
screen:set_default_attr_ids( {
[0] = {bold=true, foreground=255},
[1] = {bold=true, reverse=true},
} )
end)
after_each(function()
screen:detach()
end)
it('default initial screen', function()
screen:expect([[
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{1:[No Name] }|
|
]])
end)
end)
local function screen_tests(linegrid)
local screen
before_each(function()
clear()
screen = Screen.new()
screen:attach({rgb=true,ext_linegrid=linegrid})
screen:set_default_attr_ids( {
[0] = {bold=true, foreground=255},
[1] = {bold=true, reverse=true},
[2] = {bold=true},
[3] = {reverse=true},
[4] = {background = Screen.colors.LightGrey, underline = true},
[5] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Fuchsia},
[6] = {bold = true, foreground = Screen.colors.Fuchsia},
[7] = {bold = true, foreground = Screen.colors.SeaGreen},
} )
end)
after_each(function()
screen:detach()
end)
describe(':suspend', function()
it('is forwarded to the UI', function()
local function check()
eq(true, screen.suspended)
end
command('let g:ev = []')
command('autocmd VimResume * :call add(g:ev, "r")')
command('autocmd VimSuspend * :call add(g:ev, "s")')
eq(false, screen.suspended)
command('suspend')
eq({ 's', 'r' }, eval('g:ev'))
screen:expect(check)
screen.suspended = false
feed('<c-z>')
eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
screen:expect(check)
screen.suspended = false
command('suspend')
eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
end)
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)
end)
it('has correct default title with unnamed file', function()
local expected = '[No Name] - NVIM'
command('set title')
screen:expect(function()
eq(expected, screen.title)
end)
end)
it('has correct default title with named file', function()
local expected = (iswin() and 'myfile (C:\\mydir) - NVIM'
or 'myfile (/mydir) - NVIM')
command('set title')
command(iswin() and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
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)
end)
end)
describe('statusline', function()
it('is redrawn after <c-l>', function()
command('set laststatus=2')
screen:expect([[
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{1:[No Name] }|
|
]])
feed('<c-l>')
screen:expect{grid=[[
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{1:[No Name] }|
|
]], reset=true}
command('split')
screen:expect([[
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{1:[No Name] }|
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{3:[No Name] }|
|
]])
feed('<c-l>')
screen:expect{grid=[[
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0
|