mirror of
https://github.com/neovim/neovim.git
synced 2025-12-10 16:42:42 +00:00
refactor: format test/*
This commit is contained in:
@@ -28,7 +28,7 @@ describe(':terminal scrollback', function()
|
||||
before_each(function()
|
||||
local lines = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(lines, 'line'..tostring(i))
|
||||
table.insert(lines, 'line' .. tostring(i))
|
||||
end
|
||||
table.insert(lines, '')
|
||||
feed_data(lines)
|
||||
@@ -59,7 +59,7 @@ describe(':terminal scrollback', function()
|
||||
|
||||
describe('with cursor at last row', function()
|
||||
before_each(function()
|
||||
feed_data({'line1', 'line2', 'line3', 'line4', ''})
|
||||
feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
|
||||
screen:expect([[
|
||||
tty ready |
|
||||
line1 |
|
||||
@@ -72,7 +72,9 @@ describe(':terminal scrollback', function()
|
||||
end)
|
||||
|
||||
describe('and 1 line is printed', function()
|
||||
before_each(function() feed_data({'line5', ''}) end)
|
||||
before_each(function()
|
||||
feed_data({ 'line5', '' })
|
||||
end)
|
||||
|
||||
it('will hide the top line', function()
|
||||
screen:expect([[
|
||||
@@ -88,7 +90,9 @@ describe(':terminal scrollback', function()
|
||||
end)
|
||||
|
||||
describe('and then 3 more lines are printed', function()
|
||||
before_each(function() feed_data({'line6', 'line7', 'line8'}) end)
|
||||
before_each(function()
|
||||
feed_data({ 'line6', 'line7', 'line8' })
|
||||
end)
|
||||
|
||||
it('will hide the top 4 lines', function()
|
||||
screen:expect([[
|
||||
@@ -137,7 +141,6 @@ describe(':terminal scrollback', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
describe('and height decreased by 1', function()
|
||||
local function will_hide_top_line()
|
||||
feed([[<C-\><C-N>]])
|
||||
@@ -184,7 +187,9 @@ describe(':terminal scrollback', function()
|
||||
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
|
||||
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
|
||||
-- See also: https://github.com/rprichard/winpty/issues/110
|
||||
if skip(is_os('win')) then return end
|
||||
if skip(is_os('win')) then
|
||||
return
|
||||
end
|
||||
|
||||
describe('and the height is decreased by 2', function()
|
||||
before_each(function()
|
||||
@@ -239,7 +244,7 @@ describe(':terminal scrollback', function()
|
||||
|
||||
describe('with 4 lines hidden in the scrollback', function()
|
||||
before_each(function()
|
||||
feed_data({'line1', 'line2', 'line3', 'line4', ''})
|
||||
feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
|
||||
screen:expect([[
|
||||
tty ready |
|
||||
line1 |
|
||||
@@ -263,7 +268,9 @@ describe(':terminal scrollback', function()
|
||||
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
|
||||
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
|
||||
-- See also: https://github.com/rprichard/winpty/issues/110
|
||||
if skip(is_os('win')) then return end
|
||||
if skip(is_os('win')) then
|
||||
return
|
||||
end
|
||||
local function pop_then_push()
|
||||
screen:try_resize(screen._width, screen._height + 1)
|
||||
screen:expect([[
|
||||
@@ -347,7 +354,7 @@ describe(':terminal prints more lines than the screen height and exits', functio
|
||||
it('will push extra lines to scrollback', function()
|
||||
clear()
|
||||
local screen = Screen.new(30, 7)
|
||||
screen:attach({rgb=false})
|
||||
screen:attach({ rgb = false })
|
||||
command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
|
||||
screen:expect([[
|
||||
line6 |
|
||||
@@ -381,7 +388,7 @@ describe("'scrollback' option", function()
|
||||
local ep = epsilon and epsilon or 0
|
||||
local actual = eval("line('$')")
|
||||
if expected > actual + ep and expected < actual - ep then
|
||||
error('expected (+/- '..ep..'): '..expected..', actual: '..tostring(actual))
|
||||
error('expected (+/- ' .. ep .. '): ' .. expected .. ', actual: ' .. tostring(actual))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -395,8 +402,10 @@ describe("'scrollback' option", function()
|
||||
|
||||
meths.set_option_value('scrollback', 0, {})
|
||||
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
||||
screen:expect{any='30: line '}
|
||||
retry(nil, nil, function() expect_lines(7) end)
|
||||
screen:expect { any = '30: line ' }
|
||||
retry(nil, nil, function()
|
||||
expect_lines(7)
|
||||
end)
|
||||
end)
|
||||
|
||||
it('deletes lines (only) if necessary', function()
|
||||
@@ -412,24 +421,31 @@ describe("'scrollback' option", function()
|
||||
meths.set_option_value('scrollback', 200, {})
|
||||
|
||||
-- Wait for prompt.
|
||||
screen:expect{any='%$'}
|
||||
screen:expect { any = '%$' }
|
||||
|
||||
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
||||
screen:expect{any='30: line '}
|
||||
screen:expect { any = '30: line ' }
|
||||
|
||||
retry(nil, nil, function() expect_lines(33, 2) end)
|
||||
retry(nil, nil, function()
|
||||
expect_lines(33, 2)
|
||||
end)
|
||||
meths.set_option_value('scrollback', 10, {})
|
||||
poke_eventloop()
|
||||
retry(nil, nil, function() expect_lines(16) end)
|
||||
retry(nil, nil, function()
|
||||
expect_lines(16)
|
||||
end)
|
||||
meths.set_option_value('scrollback', 10000, {})
|
||||
retry(nil, nil, function() expect_lines(16) end)
|
||||
retry(nil, nil, function()
|
||||
expect_lines(16)
|
||||
end)
|
||||
-- Terminal job data is received asynchronously, may happen before the
|
||||
-- 'scrollback' option is synchronized with the internal sb_buffer.
|
||||
command('sleep 100m')
|
||||
|
||||
feed_data(('%s REP 41 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
||||
if is_os('win') then
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
37: line |
|
||||
38: line |
|
||||
39: line |
|
||||
@@ -437,9 +453,11 @@ describe("'scrollback' option", function()
|
||||
|
|
||||
${1: } |
|
||||
{3:-- TERMINAL --} |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
else
|
||||
screen:expect{grid=[[
|
||||
screen:expect {
|
||||
grid = [[
|
||||
36: line |
|
||||
37: line |
|
||||
38: line |
|
||||
@@ -447,7 +465,8 @@ describe("'scrollback' option", function()
|
||||
40: line |
|
||||
{MATCH:.*}|
|
||||
{3:-- TERMINAL --} |
|
||||
]]}
|
||||
]],
|
||||
}
|
||||
end
|
||||
expect_lines(58)
|
||||
|
||||
@@ -461,11 +480,11 @@ describe("'scrollback' option", function()
|
||||
local screen = thelpers.screen_setup(nil, nil, 30)
|
||||
local lines = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(lines, 'line'..tostring(i))
|
||||
table.insert(lines, 'line' .. tostring(i))
|
||||
end
|
||||
table.insert(lines, '')
|
||||
feed_data(lines)
|
||||
screen:expect([[
|
||||
screen:expect([[
|
||||
line26 |
|
||||
line27 |
|
||||
line28 |
|
||||
@@ -474,7 +493,7 @@ describe("'scrollback' option", function()
|
||||
{1: } |
|
||||
{3:-- TERMINAL --} |
|
||||
]])
|
||||
local term_height = 6 -- Actual terminal screen height, not the scrollback
|
||||
local term_height = 6 -- Actual terminal screen height, not the scrollback
|
||||
-- Initial
|
||||
local scrollback = meths.get_option_value('scrollback', {})
|
||||
eq(scrollback + term_height, eval('line("$")'))
|
||||
@@ -491,10 +510,11 @@ describe("'scrollback' option", function()
|
||||
end)
|
||||
|
||||
it('error if set to invalid value', function()
|
||||
eq('Vim(set):E474: Invalid argument: scrollback=-2',
|
||||
pcall_err(command, 'set scrollback=-2'))
|
||||
eq('Vim(set):E474: Invalid argument: scrollback=100001',
|
||||
pcall_err(command, 'set scrollback=100001'))
|
||||
eq('Vim(set):E474: Invalid argument: scrollback=-2', pcall_err(command, 'set scrollback=-2'))
|
||||
eq(
|
||||
'Vim(set):E474: Invalid argument: scrollback=100001',
|
||||
pcall_err(command, 'set scrollback=100001')
|
||||
)
|
||||
end)
|
||||
|
||||
it('defaults to -1 on normal buffers', function()
|
||||
@@ -512,7 +532,7 @@ describe("'scrollback' option", function()
|
||||
|
||||
-- _Local_ scrollback=-1 in :terminal forces the _maximum_.
|
||||
command('setlocal scrollback=-1')
|
||||
retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
|
||||
retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
|
||||
eq(100000, meths.get_option_value('scrollback', {}))
|
||||
end)
|
||||
|
||||
@@ -535,23 +555,22 @@ describe("'scrollback' option", function()
|
||||
|
||||
it(':set updates local value and global default', function()
|
||||
set_fake_shell()
|
||||
command('set scrollback=42') -- set global value
|
||||
command('set scrollback=42') -- set global value
|
||||
eq(42, meths.get_option_value('scrollback', {}))
|
||||
command('terminal')
|
||||
eq(42, meths.get_option_value('scrollback', {})) -- inherits global default
|
||||
command('setlocal scrollback=99')
|
||||
eq(99, meths.get_option_value('scrollback', {}))
|
||||
command('set scrollback<') -- reset to global default
|
||||
command('set scrollback<') -- reset to global default
|
||||
eq(42, meths.get_option_value('scrollback', {}))
|
||||
command('setglobal scrollback=734') -- new global default
|
||||
command('setglobal scrollback=734') -- new global default
|
||||
eq(42, meths.get_option_value('scrollback', {})) -- local value did not change
|
||||
command('terminal')
|
||||
eq(734, meths.get_option_value('scrollback', {}))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe("pending scrollback line handling", function()
|
||||
describe('pending scrollback line handling', function()
|
||||
local screen
|
||||
|
||||
before_each(function()
|
||||
@@ -559,9 +578,9 @@ describe("pending scrollback line handling", function()
|
||||
screen = Screen.new(30, 7)
|
||||
screen:attach()
|
||||
screen:set_default_attr_ids {
|
||||
[1] = {foreground = Screen.colors.Brown},
|
||||
[2] = {reverse = true},
|
||||
[3] = {bold = true},
|
||||
[1] = { foreground = Screen.colors.Brown },
|
||||
[2] = { reverse = true },
|
||||
[3] = { bold = true },
|
||||
}
|
||||
end)
|
||||
|
||||
@@ -597,7 +616,8 @@ describe("pending scrollback line handling", function()
|
||||
end)
|
||||
|
||||
it('does not crash after nvim_buf_call #14891', function()
|
||||
exec_lua([[
|
||||
exec_lua(
|
||||
[[
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
local args = ...
|
||||
vim.api.nvim_buf_call(bufnr, function()
|
||||
@@ -605,9 +625,9 @@ describe("pending scrollback line handling", function()
|
||||
end)
|
||||
vim.api.nvim_win_set_buf(0, bufnr)
|
||||
vim.cmd('startinsert')
|
||||
]], is_os('win')
|
||||
and {'cmd.exe', '/c', 'for /L %I in (1,1,12) do @echo hi'}
|
||||
or {'printf', ('hi\n'):rep(12)}
|
||||
]],
|
||||
is_os('win') and { 'cmd.exe', '/c', 'for /L %I in (1,1,12) do @echo hi' }
|
||||
or { 'printf', ('hi\n'):rep(12) }
|
||||
)
|
||||
screen:expect [[
|
||||
hi |*4
|
||||
|
||||
Reference in New Issue
Block a user