robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.1 KiB80 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local eq = t.eq
7local dedent = t.dedent
8local exec = n.exec
9local feed = n.feed
10local clear = n.clear
11local command = n.command
12local api = n.api
13
14local 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  end)
37end
38cmdtest('insert', ' before', { 'abc', 'def', 'foo', 'bar', 'baz' })
39cmdtest('append', ' after', { 'foo', 'abc', 'def', 'bar', 'baz' })
40cmdtest('change', '', { 'abc', 'def', 'bar', 'baz' })
41
42describe('first line is redrawn correctly after :append/:insert in an empty buffer', function()
43  local screen
44  before_each(function()
45    clear()
46    screen = Screen.new(20, 8)
47    screen:set_default_attr_ids({
48      [1] = { bold = true, foreground = Screen.colors.Blue },
49      [2] = { bold = true, reverse = true },
50    })
51  end)
52
53  it('using :append', function()
54    exec(dedent([[
55      append
56      aaaaa
57      bbbbb
58      .]]))
59    screen:expect([[
60      aaaaa               |
61      ^bbbbb               |
62      {1:~                   }|*5
63                          |
64    ]])
65  end)
66
67  it('using :insert', function()
68    exec(dedent([[
69      insert
70      aaaaa
71      bbbbb
72      .]]))
73    screen:expect([[
74      aaaaa               |
75      ^bbbbb               |
76      {1:~                   }|*5
77                          |
78    ]])
79  end)
80end)