robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
4.4 KiB123 linesraw
1-- Cmdline-mode tests.
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local clear, insert, fn, eq, feed = n.clear, n.insert, n.fn, t.eq, n.feed
9local eval = n.eval
10local command = n.command
11local api = n.api
12
13describe('cmdline', function()
14  before_each(clear)
15
16  describe('Ctrl-R', function()
17    it('pasting non-special register inserts <CR> *between* lines', function()
18      insert([[
19      line1abc
20      line2somemoretext
21      ]])
22      -- Yank 2 lines linewise, then paste to cmdline.
23      feed([[<C-\><C-N>gg0yj:<C-R>0]])
24      -- <CR> inserted between lines, NOT after the final line.
25      eq('line1abc\rline2somemoretext', fn.getcmdline())
26
27      -- Yank 2 lines charwise, then paste to cmdline.
28      feed([[<C-\><C-N>gg05lyvj:<C-R>0]])
29      -- <CR> inserted between lines, NOT after the final line.
30      eq('abc\rline2', fn.getcmdline())
31
32      -- Yank 1 line linewise, then paste to cmdline.
33      feed([[<C-\><C-N>ggyy:<C-R>0]])
34      -- No <CR> inserted.
35      eq('line1abc', fn.getcmdline())
36    end)
37
38    it('pasting special register inserts <CR>, <NL>', function()
39      feed([[:<C-R>="foo\nbar\rbaz"<CR>]])
40      eq('foo\nbar\rbaz', fn.getcmdline())
41    end)
42
43    it('pasting handles composing chars properly', function()
44      local screen = Screen.new(60, 4)
45      -- 'arabicshape' cheats and always redraws everything which trivially works,
46      -- this test is for partial redraws in 'noarabicshape' mode.
47      command('set noarabicshape')
48      fn.setreg('a', '💻')
49      feed(':test 🧑‍')
50      screen:expect([[
51                                                                    |
52        {1:~                                                           }|*2
53        :test 🧑‍^                                                    |
54      ]])
55      feed('<c-r><c-r>a')
56      screen:expect([[
57                                                                    |
58        {1:~                                                           }|*2
59        :test 🧑‍💻^                                                    |
60      ]])
61    end)
62  end)
63
64  it('Ctrl-Shift-V supports entering unsimplified key notations', function()
65    feed(':"<C-S-V><C-J><C-S-V><C-@><C-S-V><C-[><C-S-V><C-S-M><C-S-V><M-C-I><C-S-V><C-D-J><CR>')
66
67    eq('"<C-J><C-@><C-[><C-S-M><M-C-I><C-D-J>', eval('@:'))
68  end)
69
70  it('redraws statusline when toggling overstrike', function()
71    local screen = Screen.new(60, 4)
72    command('set laststatus=2 statusline=%!mode(1)')
73    feed(':')
74    screen:expect {
75      grid = [[
76                                                                  |
77      {1:~                                                           }|
78      {3:c                                                           }|
79      :^                                                           |
80    ]],
81    }
82    feed('<Insert>')
83    screen:expect {
84      grid = [[
85                                                                  |
86      {1:~                                                           }|
87      {3:cr                                                          }|
88      :^                                                           |
89    ]],
90    }
91  end)
92
93  describe('history', function()
94    it('correctly clears start of the history', function()
95      -- Regression test: check absence of the memory leak when clearing start of
96      -- the history using cmdhist.c/clr_history().
97      eq(1, fn.histadd(':', 'foo'))
98      eq(1, fn.histdel(':'))
99      eq('', fn.histget(':', -1))
100    end)
101
102    it('correctly clears end of the history', function()
103      -- Regression test: check absence of the memory leak when clearing end of
104      -- the history using cmdhist.c/clr_history().
105      api.nvim_set_option_value('history', 1, {})
106      eq(1, fn.histadd(':', 'foo'))
107      eq(1, fn.histdel(':'))
108      eq('', fn.histget(':', -1))
109    end)
110
111    it('correctly removes item from history', function()
112      -- Regression test: check that cmdhist.c/del_history_idx() correctly clears
113      -- history index after removing history entry. If it does not then deleting
114      -- history will result in a double free.
115      eq(1, fn.histadd(':', 'foo'))
116      eq(1, fn.histadd(':', 'bar'))
117      eq(1, fn.histadd(':', 'baz'))
118      eq(1, fn.histdel(':', -2))
119      eq(1, fn.histdel(':'))
120      eq('', fn.histget(':', -1))
121    end)
122  end)
123end)