append_spec.lua (2769B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local Screen = require('test.functional.ui.screen') 4 5 local eq = t.eq 6 local dedent = t.dedent 7 local exec = n.exec 8 local feed = n.feed 9 local clear = n.clear 10 local fn = n.fn 11 local command = n.command 12 local api = n.api 13 14 local cmdtest = function(cmd, prep, ret1) 15 describe(':' .. cmd, function() 16 before_each(function() 17 clear() 18 api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' }) 19 end) 20 21 local buffer_contents = function() 22 return api.nvim_buf_get_lines(0, 0, -1, false) 23 end 24 25 it(cmd .. 's' .. prep .. ' the current line by default', function() 26 command(cmd .. '\nabc\ndef') 27 eq(ret1, buffer_contents()) 28 end) 29 -- Used to crash because this invokes history processing which uses 30 -- hist_char2type which after fdb68e35e4c729c7ed097d8ade1da29e5b3f4b31 31 -- crashed. 32 it(cmd .. 's' .. prep .. ' the current line by default when feeding', function() 33 feed(':' .. cmd .. '\nabc\ndef\n.\n') 34 eq(ret1, buffer_contents()) 35 end) 36 -- This used to crash since that commit as well. 37 it('opens empty cmdline window', function() 38 local hisline = '" Some comment to be stored in history' 39 feed(':' .. hisline .. '<CR>') 40 feed(':' .. cmd .. '<CR>abc<CR>def<C-f>') 41 eq({ 'def' }, buffer_contents()) 42 eq(hisline, fn.histget(':', -2)) 43 eq(cmd, fn.histget(':')) 44 -- Test that command-line window was launched 45 eq('nofile', api.nvim_get_option_value('buftype', {})) 46 eq('n', fn.mode(1)) 47 feed('<CR>') 48 eq('c', fn.mode(1)) 49 feed('.<CR>') 50 eq('n', fn.mode(1)) 51 eq(ret1, buffer_contents()) 52 end) 53 end) 54 end 55 cmdtest('insert', ' before', { 'abc', 'def', 'foo', 'bar', 'baz' }) 56 cmdtest('append', ' after', { 'foo', 'abc', 'def', 'bar', 'baz' }) 57 cmdtest('change', '', { 'abc', 'def', 'bar', 'baz' }) 58 59 describe('the first line is redrawn correctly after inserting text in an empty buffer', function() 60 local screen 61 before_each(function() 62 clear() 63 screen = Screen.new(20, 8) 64 screen:set_default_attr_ids({ 65 [1] = { bold = true, foreground = Screen.colors.Blue }, 66 [2] = { bold = true, reverse = true }, 67 }) 68 end) 69 70 it('using :append', function() 71 exec(dedent([[ 72 append 73 aaaaa 74 bbbbb 75 .]])) 76 screen:expect([[ 77 aaaaa | 78 ^bbbbb | 79 {1:~ }|*5 80 | 81 ]]) 82 end) 83 84 it('using :insert', function() 85 exec(dedent([[ 86 insert 87 aaaaa 88 bbbbb 89 .]])) 90 screen:expect([[ 91 aaaaa | 92 ^bbbbb | 93 {1:~ }|*5 94 | 95 ]]) 96 end) 97 end)