aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/scrollback_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal/scrollback_spec.lua')
-rw-r--r--test/functional/terminal/scrollback_spec.lua211
1 files changed, 113 insertions, 98 deletions
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index 1e278e4cff..858e23984d 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -1,14 +1,13 @@
local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
-local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
+local clear, eq = helpers.clear, helpers.eq
local feed, testprg = helpers.feed, helpers.testprg
local eval = helpers.eval
local command = helpers.command
local poke_eventloop = helpers.poke_eventloop
local retry = helpers.retry
-local meths = helpers.meths
-local nvim = helpers.nvim
+local api = helpers.api
local feed_data = thelpers.feed_data
local pcall_err = helpers.pcall_err
local exec_lua = helpers.exec_lua
@@ -28,7 +27,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 +58,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 +71,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([[
@@ -84,11 +85,13 @@ describe(':terminal scrollback', function()
{1: } |
{3:-- TERMINAL --} |
]])
- eq(7, curbuf('line_count'))
+ eq(7, api.nvim_buf_line_count(0))
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 +140,6 @@ describe(':terminal scrollback', function()
end)
end)
-
describe('and height decreased by 1', function()
local function will_hide_top_line()
feed([[<C-\><C-N>]])
@@ -167,7 +169,7 @@ describe(':terminal scrollback', function()
{2:^ } |
|
]])
- eq(8, curbuf('line_count'))
+ eq(8, api.nvim_buf_line_count(0))
feed([[3k]])
screen:expect([[
^line4 |
@@ -184,7 +186,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()
@@ -199,7 +203,7 @@ describe(':terminal scrollback', function()
|
{3:-- TERMINAL --} |
]])
- eq(4, curbuf('line_count'))
+ eq(4, api.nvim_buf_line_count(0))
end
it('will delete the last two empty lines', will_delete_last_two_lines)
@@ -217,7 +221,7 @@ describe(':terminal scrollback', function()
{1: } |
{3:-- TERMINAL --} |
]])
- eq(4, curbuf('line_count'))
+ eq(4, api.nvim_buf_line_count(0))
feed('<c-\\><c-n>gg')
screen:expect([[
^tty ready |
@@ -239,7 +243,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 |
@@ -256,14 +260,16 @@ describe(':terminal scrollback', function()
{1: } |
{3:-- TERMINAL --} |
]])
- eq(7, curbuf('line_count'))
+ eq(7, api.nvim_buf_line_count(0))
end)
describe('and the height is increased by 1', 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([[
@@ -280,7 +286,7 @@ describe(':terminal scrollback', function()
describe('and then by 3', function()
before_each(function()
pop_then_push()
- eq(8, curbuf('line_count'))
+ eq(8, api.nvim_buf_line_count(0))
screen:try_resize(screen._width, screen._height + 3)
end)
@@ -295,7 +301,7 @@ describe(':terminal scrollback', function()
{1: } |
{3:-- TERMINAL --} |
]])
- eq(9, curbuf('line_count'))
+ eq(9, api.nvim_buf_line_count(0))
feed('<c-\\><c-n>gg')
screen:expect([[
^tty ready |
@@ -335,7 +341,7 @@ describe(':terminal scrollback', function()
]])
-- since there's an empty line after the cursor, the buffer line
-- count equals the terminal screen height
- eq(11, curbuf('line_count'))
+ eq(11, api.nvim_buf_line_count(0))
end)
end)
end)
@@ -347,7 +353,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 |
@@ -362,11 +368,7 @@ describe(':terminal prints more lines than the screen height and exits', functio
-- closes the buffer correctly after pressing a key
screen:expect([[
^ |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ ~ |*5
|
]])
end)
@@ -378,62 +380,71 @@ describe("'scrollback' option", function()
end)
local function set_fake_shell()
- nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
+ api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
end
local function expect_lines(expected, epsilon)
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
it('set to 0 behaves as 1', function()
local screen
if is_os('win') then
- screen = thelpers.screen_setup(nil, "['cmd.exe']", 30)
+ screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30)
else
- screen = thelpers.screen_setup(nil, "['sh']", 30)
+ screen = thelpers.screen_setup(nil, { 'sh' }, 30)
end
- meths.set_option_value('scrollback', 0, {})
+ api.nvim_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()
local screen
if is_os('win') then
command([[let $PROMPT='$$']])
- screen = thelpers.screen_setup(nil, "['cmd.exe']", 30)
+ screen = thelpers.screen_setup(nil, { 'cmd.exe' }, 30)
else
command('let $PS1 = "$"')
- screen = thelpers.screen_setup(nil, "['sh']", 30)
+ screen = thelpers.screen_setup(nil, { 'sh' }, 30)
end
- meths.set_option_value('scrollback', 200, {})
+ api.nvim_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)
- meths.set_option_value('scrollback', 10, {})
+ retry(nil, nil, function()
+ expect_lines(33, 2)
+ end)
+ api.nvim_set_option_value('scrollback', 10, {})
poke_eventloop()
- 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)
+ api.nvim_set_option_value('scrollback', 10000, {})
+ 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 |
@@ -441,9 +452,11 @@ describe("'scrollback' option", function()
|
${1: } |
{3:-- TERMINAL --} |
- ]]}
+ ]],
+ }
else
- screen:expect{grid=[[
+ screen:expect {
+ grid = [[
36: line |
37: line |
38: line |
@@ -451,7 +464,8 @@ describe("'scrollback' option", function()
40: line |
{MATCH:.*}|
{3:-- TERMINAL --} |
- ]]}
+ ]],
+ }
end
expect_lines(58)
@@ -465,11 +479,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 |
@@ -478,32 +492,33 @@ 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', {})
+ local scrollback = api.nvim_get_option_value('scrollback', {})
eq(scrollback + term_height, eval('line("$")'))
-- Reduction
scrollback = scrollback - 2
- meths.set_option_value('scrollback', scrollback, {})
+ api.nvim_set_option_value('scrollback', scrollback, {})
eq(scrollback + term_height, eval('line("$")'))
end)
it('defaults to 10000 in :terminal buffers', function()
set_fake_shell()
command('terminal')
- eq(10000, meths.get_option_value('scrollback', {}))
+ eq(10000, api.nvim_get_option_value('scrollback', {}))
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()
command('new')
- eq(-1, meths.get_option_value('scrollback', {}))
+ eq(-1, api.nvim_get_option_value('scrollback', {}))
end)
it(':setlocal in a :terminal buffer', function()
@@ -512,50 +527,49 @@ describe("'scrollback' option", function()
-- _Global_ scrollback=-1 defaults :terminal to 10_000.
command('setglobal scrollback=-1')
command('terminal')
- eq(10000, meths.get_option_value('scrollback', {}))
+ eq(10000, api.nvim_get_option_value('scrollback', {}))
-- _Local_ scrollback=-1 in :terminal forces the _maximum_.
command('setlocal scrollback=-1')
- retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
- eq(100000, meths.get_option_value('scrollback', {}))
+ retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
+ eq(100000, api.nvim_get_option_value('scrollback', {}))
end)
-- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605
command('setglobal scrollback=-1')
command('autocmd TermOpen * setlocal scrollback=-1')
command('terminal')
- eq(100000, meths.get_option_value('scrollback', {}))
+ eq(100000, api.nvim_get_option_value('scrollback', {}))
end)
it(':setlocal in a normal buffer', function()
command('new')
-- :setlocal to -1.
command('setlocal scrollback=-1')
- eq(-1, meths.get_option_value('scrollback', {}))
+ eq(-1, api.nvim_get_option_value('scrollback', {}))
-- :setlocal to anything except -1. Currently, this just has no effect.
command('setlocal scrollback=42')
- eq(42, meths.get_option_value('scrollback', {}))
+ eq(42, api.nvim_get_option_value('scrollback', {}))
end)
it(':set updates local value and global default', function()
set_fake_shell()
- command('set scrollback=42') -- set global value
- eq(42, meths.get_option_value('scrollback', {}))
+ command('set scrollback=42') -- set global value
+ eq(42, api.nvim_get_option_value('scrollback', {}))
command('terminal')
- eq(42, meths.get_option_value('scrollback', {})) -- inherits global default
+ eq(42, api.nvim_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
- eq(42, meths.get_option_value('scrollback', {}))
- command('setglobal scrollback=734') -- new global default
- eq(42, meths.get_option_value('scrollback', {})) -- local value did not change
+ eq(99, api.nvim_get_option_value('scrollback', {}))
+ command('set scrollback<') -- reset to global default
+ eq(42, api.nvim_get_option_value('scrollback', {}))
+ command('setglobal scrollback=734') -- new global default
+ eq(42, api.nvim_get_option_value('scrollback', {})) -- local value did not change
command('terminal')
- eq(734, meths.get_option_value('scrollback', {}))
+ eq(734, api.nvim_get_option_value('scrollback', {}))
end)
-
end)
-describe("pending scrollback line handling", function()
+describe('pending scrollback line handling', function()
local screen
before_each(function()
@@ -563,9 +577,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)
@@ -580,41 +594,42 @@ describe("pending scrollback line handling", function()
]]
screen:expect [[
{1: 1 }^a |
- {1: 2 } a |
- {1: 3 } a |
- {1: 4 } a |
- {1: 5 } a |
- {1: 6 } a |
+ {1: 2 }a |
+ {1: 3 }a |
+ {1: 4 }a |
+ {1: 5 }a |
+ {1: 6 }a |
|
]]
feed('G')
screen:expect [[
- {1: 7 } a |
- {1: 8 } a |
- {1: 9 } a |
- {1: 10 } a |
- {1: 11 } a |
- {1: 12 } ^a |
+ {1: 7 }a |
+ {1: 8 }a |
+ {1: 9 }a |
+ {1: 10 }a |
+ {1: 11 }a |
+ {1: 12 }^a |
|
]]
assert_alive()
end)
- it("does not crash after nvim_buf_call #14891", function()
- skip(is_os('win'))
- exec_lua [[
+ it('does not crash after nvim_buf_call #14891', function()
+ exec_lua(
+ [[
local bufnr = vim.api.nvim_create_buf(false, true)
+ local args = ...
vim.api.nvim_buf_call(bufnr, function()
- vim.fn.termopen({"echo", ("hi\n"):rep(11)})
+ vim.fn.termopen(args)
end)
vim.api.nvim_win_set_buf(0, bufnr)
- vim.cmd("startinsert")
- ]]
+ 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) }
+ )
screen:expect [[
- hi |
- hi |
- hi |
- |
+ hi |*4
|
[Process exited 0]{2: } |
{3:-- TERMINAL --} |