diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-02-27 09:59:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-27 09:59:58 +0100 |
commit | e502cca010357773252c686ef535bb2998aeb50b (patch) | |
tree | 8533cb3229c0de3e8e99b9ce1aff5660fa91277a /test/functional/terminal/scrollback_spec.lua | |
parent | 73a054d84427191f70ea59fc6dc34314b28ad07c (diff) | |
parent | c484323dc67fbca10a2f3da3d6e65efdb3c678c3 (diff) | |
download | rneovim-e502cca010357773252c686ef535bb2998aeb50b.tar.gz rneovim-e502cca010357773252c686ef535bb2998aeb50b.tar.bz2 rneovim-e502cca010357773252c686ef535bb2998aeb50b.zip |
Merge #6142 from justinmk/term-modifiable
terminal: 'modifiable'; 'scrollback'; follow output only if cursor is on last line
Diffstat (limited to 'test/functional/terminal/scrollback_spec.lua')
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 385 |
1 files changed, 237 insertions, 148 deletions
diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index d60819af65..930d0cf58b 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 @@ -13,14 +17,14 @@ describe('terminal scrollback', function() before_each(function() clear() - screen = thelpers.screen_setup() + screen = thelpers.screen_setup(nil, nil, 30) end) after_each(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 @@ -29,26 +33,26 @@ describe('terminal scrollback', function() table.insert(lines, '') feed_data(lines) screen:expect([[ - line26 | - line27 | - line28 | - line29 | - line30 | - {1: } | - {3:-- TERMINAL --} | + line26 | + line27 | + line28 | + line29 | + line30 | + {1: } | + {3:-- TERMINAL --} | ]]) end) it('will delete extra lines at the top', function() feed('<c-\\><c-n>gg') screen:expect([[ - ^line16 | - line17 | - line18 | - line19 | - line20 | - line21 | - | + ^line16 | + line17 | + line18 | + line19 | + line20 | + line21 | + | ]]) end) end) @@ -57,13 +61,13 @@ describe('terminal scrollback', function() before_each(function() feed_data({'line1', 'line2', 'line3', 'line4', ''}) screen:expect([[ - tty ready | - line1 | - line2 | - line3 | - line4 | - {1: } | - {3:-- TERMINAL --} | + tty ready | + line1 | + line2 | + line3 | + line4 | + {1: } | + {3:-- TERMINAL --} | ]]) end) @@ -72,13 +76,13 @@ describe('terminal scrollback', function() it('will hide the top line', function() screen:expect([[ - line1 | - line2 | - line3 | - line4 | - line5 | - {1: } | - {3:-- TERMINAL --} | + line1 | + line2 | + line3 | + line4 | + line5 | + {1: } | + {3:-- TERMINAL --} | ]]) eq(7, curbuf('line_count')) end) @@ -88,46 +92,46 @@ describe('terminal scrollback', function() it('will hide the top 4 lines', function() screen:expect([[ - line3 | - line4 | - line5 | - line6 | - line7 | - line8{1: } | - {3:-- TERMINAL --} | + line3 | + line4 | + line5 | + line6 | + line7 | + line8{1: } | + {3:-- TERMINAL --} | ]]) feed('<c-\\><c-n>6k') screen:expect([[ - ^line2 | - line3 | - line4 | - line5 | - line6 | - line7 | - | + ^line2 | + line3 | + line4 | + line5 | + line6 | + line7 | + | ]]) feed('gg') screen:expect([[ - ^tty ready | - line1 | - line2 | - line3 | - line4 | - line5 | - | + ^tty ready | + line1 | + line2 | + line3 | + line4 | + line5 | + | ]]) feed('G') screen:expect([[ - line3 | - line4 | - line5 | - line6 | - line7 | - ^line8{2: } | - | + line3 | + line4 | + line5 | + line6 | + line7 | + ^line8{2: } | + | ]]) end) end) @@ -138,12 +142,12 @@ describe('terminal scrollback', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) screen:expect([[ - line2 | - line3 | - line4 | - rows: 5, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + line2 | + line3 | + line4 | + rows: 5, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) end @@ -157,18 +161,18 @@ describe('terminal scrollback', function() it('will hide the top 3 lines', function() screen:expect([[ - rows: 5, cols: 50 | - rows: 3, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + rows: 5, cols: 30 | + rows: 3, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) eq(8, curbuf('line_count')) feed('<c-\\><c-n>3k') screen:expect([[ - ^line4 | - rows: 5, cols: 50 | - rows: 3, cols: 50 | - | + ^line4 | + rows: 5, cols: 30 | + rows: 3, cols: 30 | + | ]]) end) end) @@ -183,11 +187,11 @@ describe('terminal scrollback', function() local function will_delete_last_two_lines() screen:expect([[ - tty ready | - rows: 4, cols: 50 | - {1: } | - | - {3:-- TERMINAL --} | + tty ready | + rows: 4, cols: 30 | + {1: } | + | + {3:-- TERMINAL --} | ]]) eq(4, curbuf('line_count')) end @@ -202,25 +206,25 @@ describe('terminal scrollback', function() it('will delete the last line and hide the first', function() screen:expect([[ - rows: 4, cols: 50 | - rows: 3, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + rows: 4, cols: 30 | + rows: 3, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) eq(4, curbuf('line_count')) feed('<c-\\><c-n>gg') screen:expect([[ - ^tty ready | - rows: 4, cols: 50 | - rows: 3, cols: 50 | - | + ^tty ready | + rows: 4, cols: 30 | + rows: 3, cols: 30 | + | ]]) feed('a') screen:expect([[ - rows: 4, cols: 50 | - rows: 3, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + rows: 4, cols: 30 | + rows: 3, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) end) end) @@ -231,20 +235,20 @@ describe('terminal scrollback', function() before_each(function() feed_data({'line1', 'line2', 'line3', 'line4', ''}) screen:expect([[ - tty ready | - line1 | - line2 | - line3 | - line4 | - {1: } | - {3:-- TERMINAL --} | + tty ready | + line1 | + line2 | + line3 | + line4 | + {1: } | + {3:-- TERMINAL --} | ]]) screen:try_resize(screen._width, screen._height - 3) screen:expect([[ - line4 | - rows: 3, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + line4 | + rows: 3, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) eq(7, curbuf('line_count')) end) @@ -253,11 +257,11 @@ describe('terminal scrollback', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) screen:expect([[ - line4 | - rows: 3, cols: 50 | - rows: 4, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + line4 | + rows: 3, cols: 30 | + rows: 4, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) end @@ -272,26 +276,26 @@ describe('terminal scrollback', function() local function pop3_then_push1() screen:expect([[ - line2 | - line3 | - line4 | - rows: 3, cols: 50 | - rows: 4, cols: 50 | - rows: 7, cols: 50 | - {1: } | - {3:-- TERMINAL --} | + line2 | + line3 | + line4 | + rows: 3, cols: 30 | + rows: 4, cols: 30 | + rows: 7, cols: 30 | + {1: } | + {3:-- TERMINAL --} | ]]) eq(9, curbuf('line_count')) feed('<c-\\><c-n>gg') screen:expect([[ - ^tty ready | - line1 | - line2 | - line3 | - line4 | - rows: 3, cols: 50 | - rows: 4, cols: 50 | - | + ^tty ready | + line1 | + line2 | + line3 | + line4 | + rows: 3, cols: 30 | + rows: 4, cols: 30 | + | ]]) end @@ -306,18 +310,18 @@ describe('terminal scrollback', function() it('will show all lines and leave a blank one at the end', function() screen:expect([[ - tty ready | - line1 | - line2 | - line3 | - line4 | - rows: 3, cols: 50 | - rows: 4, cols: 50 | - rows: 7, cols: 50 | - rows: 11, cols: 50 | - {1: } | - | - {3:-- TERMINAL --} | + tty ready | + line1 | + line2 | + line3 | + line4 | + rows: 3, cols: 30 | + rows: 4, cols: 30 | + rows: 7, cols: 30 | + rows: 11, cols: 30 | + {1: } | + | + {3:-- TERMINAL --} | ]]) -- since there's an empty line after the cursor, the buffer line -- count equals the terminal screen height @@ -332,30 +336,115 @@ end) describe('terminal prints more lines than the screen height and exits', function() it('will push extra lines to scrollback', function() clear() - local screen = Screen.new(50, 7) + local screen = Screen.new(30, 7) screen:attach({rgb=false}) execute('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert') wait() screen:expect([[ - line6 | - line7 | - line8 | - line9 | - | - [Process exited 0] | - -- TERMINAL -- | + line6 | + line7 | + line8 | + line9 | + | + [Process exited 0] | + -- TERMINAL -- | ]]) feed('<cr>') -- closes the buffer correctly after pressing a key screen:expect([[ - ^ | - ~ | - ~ | - ~ | - ~ | - ~ | - | + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + | ]]) 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) |