neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

mode_cmdline_spec.lua (4451B)


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