aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-02-21 15:16:48 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-02-26 11:57:52 +0100
commite7bbd35c812d338918d1c23692c70b403205fb30 (patch)
tree21dcf24c9e1c759fd9cf984c76ec40a51b94dbfc /test
parent300eca3d301e407adadc017e71502d20a4b207e8 (diff)
downloadrneovim-e7bbd35c812d338918d1c23692c70b403205fb30.tar.gz
rneovim-e7bbd35c812d338918d1c23692c70b403205fb30.tar.bz2
rneovim-e7bbd35c812d338918d1c23692c70b403205fb30.zip
terminal: 'scrollback'
Closes #2637
Diffstat (limited to 'test')
-rw-r--r--test/functional/terminal/edit_spec.lua35
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua10
-rw-r--r--test/functional/terminal/helpers.lua5
-rw-r--r--test/functional/terminal/scrollback_spec.lua91
4 files changed, 111 insertions, 30 deletions
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index 8edcfa56b7..9795e7957d 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -31,45 +31,40 @@ describe(':edit term://*', function()
eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$'))
end)
- it('runs TermOpen early enough to respect terminal_scrollback_buffer_size', function()
+ it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
local columns, lines = 20, 4
local scr = get_screen(columns, lines)
local rep = 'a'
meths.set_option('shellcmdflag', 'REP ' .. rep)
- local rep_size = rep:byte()
+ local rep_size = rep:byte() -- 'a' => 97
local sb = 10
- local gsb = 20
- meths.set_var('terminal_scrollback_buffer_size', gsb)
- command('autocmd TermOpen * :let b:terminal_scrollback_buffer_size = '
- .. tostring(sb))
+ command('autocmd TermOpen * :setlocal scrollback='..tostring(sb))
command('edit term://foobar')
+
local bufcontents = {}
local winheight = curwinmeths.get_height()
- -- I have no idea why there is + 4 needed. But otherwise it works fine with
- -- different scrollbacks.
- local shift = -4
- local buf_cont_start = rep_size - 1 - sb - winheight - shift
- local bufline = function(i) return ('%d: foobar'):format(i) end
+ local buf_cont_start = rep_size - sb - winheight + 2
+ local function bufline (i)
+ return ('%d: foobar'):format(i)
+ end
for i = buf_cont_start,(rep_size - 1) do
bufcontents[#bufcontents + 1] = bufline(i)
end
bufcontents[#bufcontents + 1] = ''
bufcontents[#bufcontents + 1] = '[Process exited 0]'
- -- Do not ask me why displayed screen is one line *before* buffer
- -- contents: buffer starts with 87:, screen with 86:.
+
local exp_screen = '\n'
- local did_cursor = false
- for i = 0,(winheight - 1) do
- local line = bufline(buf_cont_start + i - 1)
+ for i = 1,(winheight - 1) do
+ local line = bufcontents[#bufcontents - winheight + i]
exp_screen = (exp_screen
- .. (did_cursor and '' or '^')
.. line
.. (' '):rep(columns - #line)
.. '|\n')
- did_cursor = true
end
- exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
+ exp_screen = exp_screen..'^[Process exited 0] |\n'
+
+ exp_screen = exp_screen..(' '):rep(columns)..'|\n'
scr:expect(exp_screen)
- eq(bufcontents, curbufmeths.get_lines(1, -1, true))
+ eq(bufcontents, curbufmeths.get_lines(0, -1, true))
end)
end)
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 7c391db18c..dc2535bade 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -20,22 +20,18 @@ describe(':terminal', function()
source([[
echomsg "msg1"
echomsg "msg2"
+ echomsg "msg3"
]])
-- Invoke a command that emits frequent terminal activity.
execute([[terminal while true; do echo X; done]])
helpers.feed([[<C-\><C-N>]])
- screen:expect([[
- X |
- X |
- ^X |
- |
- ]])
+ wait()
helpers.sleep(10) -- Let some terminal activity happen.
execute("messages")
screen:expect([[
- X |
msg1 |
msg2 |
+ msg3 |
Press ENTER or type command to continue^ |
]])
end)
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index ae5e6d4b1f..8c31a300dd 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -37,7 +37,6 @@ local default_command = '["'..nvim_dir..'/tty-test'..'"]'
local function screen_setup(extra_height, command)
nvim('command', 'highlight TermCursor cterm=reverse')
nvim('command', 'highlight TermCursorNC ctermbg=11')
- nvim('set_var', 'terminal_scrollback_buffer_size', 10)
if not extra_height then extra_height = 0 end
if not command then command = default_command end
local screen = Screen.new(50, 7 + extra_height)
@@ -58,7 +57,9 @@ local function screen_setup(extra_height, command)
-- tty-test puts the terminal into raw mode and echoes all input. tests are
-- done by feeding it with terminfo codes to control the display and
-- verifying output with screen:expect.
- execute('enew | call termopen('..command..') | startinsert')
+ execute('enew | call termopen('..command..')')
+ execute('setlocal scrollback=10')
+ execute('startinsert')
if command == default_command then
-- wait for "tty ready" to be printed before each test or the terminal may
-- still be in canonical mode(will echo characters for example)
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua
index d60819af65..74d44649a8 100644
--- a/test/functional/terminal/scrollback_spec.lua
+++ b/test/functional/terminal/scrollback_spec.lua
@@ -3,7 +3,11 @@ 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 feed, nvim_dir, execute = helpers.feed, helpers.nvim_dir, helpers.execute
+local eval = helpers.eval
+local command = helpers.command
local wait = helpers.wait
+local retry = helpers.retry
+local curbufmeths = helpers.curbufmeths
local feed_data = thelpers.feed_data
if helpers.pending_win32(pending) then return end
@@ -20,7 +24,7 @@ describe('terminal scrollback', function()
screen:detach()
end)
- describe('when the limit is crossed', function()
+ describe('when the limit is exceeded', function()
before_each(function()
local lines = {}
for i = 1, 30 do
@@ -359,3 +363,88 @@ describe('terminal prints more lines than the screen height and exits', function
end)
end)
+describe("'scrollback' option", function()
+ before_each(function()
+ clear()
+ end)
+
+ local function expect_lines(expected)
+ local actual = eval("line('$')")
+ if expected ~= actual then
+ error('expected: '..expected..', actual: '..tostring(actual))
+ end
+ end
+
+ it('set to 0 behaves as 1', function()
+ local screen = thelpers.screen_setup(nil, "['sh']", 30)
+
+ curbufmeths.set_option('scrollback', 0)
+ feed_data('for i in $(seq 1 30); do echo "line$i"; done\n')
+ screen:expect('line30 ', nil, nil, nil, true)
+ retry(nil, nil, function() expect_lines(7) end)
+
+ screen:detach()
+ end)
+
+ it('deletes lines (only) if necessary', function()
+ local screen = thelpers.screen_setup(nil, "['sh']", 30)
+
+ curbufmeths.set_option('scrollback', 200)
+
+ -- Wait for prompt.
+ screen:expect('$', nil, nil, nil, true)
+
+ wait()
+ feed_data('for i in $(seq 1 30); do echo "line$i"; done\n')
+
+ screen:expect('line30 ', nil, nil, nil, true)
+
+ retry(nil, nil, function() expect_lines(33) end)
+ curbufmeths.set_option('scrollback', 10)
+ wait()
+ retry(nil, nil, function() expect_lines(16) end)
+ curbufmeths.set_option('scrollback', 10000)
+ eq(16, eval("line('$')"))
+ -- Terminal job data is received asynchronously, may happen before the
+ -- 'scrollback' option is synchronized with the internal sb_buffer.
+ command('sleep 100m')
+ feed_data('for i in $(seq 1 40); do echo "line$i"; done\n')
+
+ screen:expect('line40 ', nil, nil, nil, true)
+
+ retry(nil, nil, function() expect_lines(58) end)
+ -- Verify off-screen state
+ eq('line35', eval("getline(line('w0') - 1)"))
+ eq('line26', eval("getline(line('w0') - 10)"))
+
+ screen:detach()
+ end)
+
+ it('defaults to 1000', function()
+ execute('terminal')
+ eq(1000, curbufmeths.get_option('scrollback'))
+ end)
+
+ it('error if set to invalid values', function()
+ local status, rv = pcall(command, 'set scrollback=-2')
+ eq(false, status) -- assert failure
+ eq('E474:', string.match(rv, "E%d*:"))
+
+ status, rv = pcall(command, 'set scrollback=100001')
+ eq(false, status) -- assert failure
+ eq('E474:', string.match(rv, "E%d*:"))
+ end)
+
+ it('defaults to -1 on normal buffers', function()
+ execute('new')
+ eq(-1, curbufmeths.get_option('scrollback'))
+ end)
+
+ it('error if set on a normal buffer', function()
+ command('new')
+ execute('set scrollback=42')
+ feed('<CR>')
+ eq('E474:', string.match(eval("v:errmsg"), "E%d*:"))
+ end)
+
+end)