neovim

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

edit_spec.lua (3959B)


      1 local n = require('test.functional.testnvim')()
      2 local Screen = require('test.functional.ui.screen')
      3 
      4 local clear = n.clear
      5 local command = n.command
      6 local expect = n.expect
      7 local feed = n.feed
      8 local sleep = vim.uv.sleep
      9 
     10 before_each(clear)
     11 
     12 describe('edit', function()
     13  -- oldtest: Test_autoindent_remove_indent()
     14  it('autoindent removes indent when Insert mode is stopped', function()
     15    command('set autoindent')
     16    -- leaving insert mode in a new line with indent added by autoindent, should
     17    -- remove the indent.
     18    feed('i<Tab>foo<CR><Esc>')
     19    -- Need to delay for sometime, otherwise the code in getchar.c will not be
     20    -- exercised.
     21    sleep(50)
     22    -- when a line is wrapped and the cursor is at the start of the second line,
     23    -- leaving insert mode, should move the cursor back to the first line.
     24    feed('o' .. ('x'):rep(20) .. '<Esc>')
     25    -- Need to delay for sometime, otherwise the code in getchar.c will not be
     26    -- exercised.
     27    sleep(50)
     28    expect('\tfoo\n\n' .. ('x'):rep(20))
     29  end)
     30 
     31  -- oldtest: Test_edit_insert_reg()
     32  it('inserting a register using CTRL-R', function()
     33    local screen = Screen.new(10, 6)
     34    feed('a<C-R>')
     35    screen:expect([[
     36      {18:^"}           |
     37      {1:~           }|*4
     38      {5:-- INSERT --}|
     39    ]])
     40    feed('=')
     41    screen:expect([[
     42      {18:"}           |
     43      {1:~           }|*4
     44      =^           |
     45    ]])
     46    feed([['r'<CR><Esc>]])
     47    expect('r')
     48    -- Test for inserting null and empty list
     49    feed('a<C-R>=v:_null_list<CR><Esc>')
     50    feed('a<C-R>=[]<CR><Esc>')
     51    expect('r')
     52  end)
     53 
     54  -- oldtest: Test_edit_ctrl_r_failed()
     55  it('positioning cursor after CTRL-R expression failed', function()
     56    local screen = Screen.new(60, 6)
     57 
     58    feed('i<C-R>')
     59    screen:expect([[
     60      {18:^"}                                                           |
     61      {1:~                                                           }|*4
     62      {5:-- INSERT --}                                                |
     63    ]])
     64    feed('=0z')
     65    screen:expect([[
     66      {18:"}                                                           |
     67      {1:~                                                           }|*4
     68      ={26:0}{9:z}^                                                         |
     69    ]])
     70    -- trying to insert a blob produces an error
     71    feed('<CR>')
     72    screen:expect([[
     73      {18:"}                                                           |
     74      {1:~                                                           }|
     75      {3:                                                            }|
     76      ={26:0}{9:z}                                                         |
     77      {9:E976: Using a Blob as a String}                              |
     78      {6:Press ENTER or type command to continue}^                     |
     79    ]])
     80 
     81    feed(':')
     82    screen:expect([[
     83      :^                                                           |
     84      {1:~                                                           }|*4
     85      {5:-- INSERT --}                                                |
     86    ]])
     87    -- ending Insert mode should put the cursor back on the ':'
     88    feed('<Esc>')
     89    screen:expect([[
     90      ^:                                                           |
     91      {1:~                                                           }|*4
     92                                                                  |
     93    ]])
     94  end)
     95 
     96  -- oldtest: Test_edit_CAR()
     97  it('Enter inserts newline with pum at original text after adding leader', function()
     98    local screen = Screen.new(10, 6)
     99    command('set cot=menu,menuone,noselect')
    100    feed('Shello hero<CR>h<C-X><C-N>e')
    101    screen:expect([[
    102      hello hero  |
    103      he^          |
    104      {4:hello       }|
    105      {4:hero        }|
    106      {1:~           }|
    107      {5:--}          |
    108    ]])
    109 
    110    feed('<CR>')
    111    screen:expect([[
    112      hello hero  |
    113      he          |
    114      ^            |
    115      {1:~           }|*2
    116      {5:-- INSERT --}|
    117    ]])
    118  end)
    119 end)