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 funcs, meths, exec_lua = helpers.funcs, helpers.meths, helpers.exec_lua
local is_os = helpers.is_os
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)
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)
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 = (is_os('win') and 'myfile (C:\\mydir) - NVIM' or 'myfile (/mydir) - NVIM')
command('set title')
command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
screen:expect(function()
eq(expected, screen.title)
end)
end)
describe('is not changed by', function()
local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2'
local expected = (is_os('win') and 'myfile1 (C:\\mydir) - NVIM' or 'myfile1 (/mydir) - NVIM')
local buf2
before_each(function()
command('edit '..file1)
buf2 = funcs.bufadd(file2)
command('set title')
end)
it('calling setbufvar() to set an option in a hidden buffer from i_CTRL-R', function()
command([[inoremap <F2> <C-R>=setbufvar(]]..buf2..[[, '&autoindent', 1) ? '' : ''<CR>]])
feed('i<F2><Esc>')
command('redraw!')
screen:expect(function()
eq(<
|