neovim

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

mode_spec.lua (7686B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 local Screen = require('test.functional.ui.screen')
      4 
      5 local clear, feed, insert = n.clear, n.feed, n.insert
      6 local command = n.command
      7 local retry = t.retry
      8 
      9 describe('ui mode_change event', function()
     10  local screen
     11 
     12  before_each(function()
     13    clear()
     14    screen = Screen.new(25, 4, { rgb = true })
     15  end)
     16 
     17  it('works in normal mode', function()
     18    screen:expect {
     19      grid = [[
     20      ^                         |
     21      {1:~                        }|*2
     22                               |
     23    ]],
     24      mode = 'normal',
     25    }
     26 
     27    feed('d')
     28    screen:expect {
     29      grid = [[
     30      ^                         |
     31      {1:~                        }|*2
     32                               |
     33    ]],
     34      mode = 'operator',
     35    }
     36 
     37    feed('<esc>')
     38    screen:expect {
     39      grid = [[
     40      ^                         |
     41      {1:~                        }|*2
     42                               |
     43    ]],
     44      mode = 'normal',
     45    }
     46 
     47    n.feed(':append<cr>')
     48    screen:expect({ mode = 'cmdline_normal' })
     49    n.feed('<esc>')
     50    screen:expect({ mode = 'normal' })
     51  end)
     52 
     53  -- oldtest: Test_mouse_shape_after_failed_change()
     54  it('is restored to Normal mode after failed "c"', function()
     55    screen:try_resize(50, 4)
     56    command('set nomodifiable')
     57 
     58    feed('c')
     59    screen:expect {
     60      grid = [[
     61      ^                                                  |
     62      {1:~                                                 }|*2
     63                                                        |
     64    ]],
     65      mode = 'operator',
     66    }
     67 
     68    feed('c')
     69    screen:expect {
     70      grid = [[
     71      ^                                                  |
     72      {1:~                                                 }|*2
     73      {9:E21: Cannot make changes, 'modifiable' is off}     |
     74    ]],
     75      mode = 'normal',
     76    }
     77  end)
     78 
     79  -- oldtest: Test_mouse_shape_after_cancelling_gr()
     80  it('is restored to Normal mode after cancelling "gr"', function()
     81    feed('gr')
     82    screen:expect {
     83      grid = [[
     84      ^                         |
     85      {1:~                        }|*2
     86                               |
     87    ]],
     88      mode = 'replace',
     89    }
     90 
     91    feed('<Esc>')
     92    screen:expect {
     93      grid = [[
     94      ^                         |
     95      {1:~                        }|*2
     96                               |
     97    ]],
     98      mode = 'normal',
     99    }
    100  end)
    101 
    102  -- oldtest: Test_mouse_shape_indent_norm_with_gq()
    103  it('is restored to Normal mode after "gq" indents using :normal #12309', function()
    104    screen:try_resize(60, 6)
    105    n.exec([[
    106      func Indent()
    107        exe "normal! \<Ignore>"
    108        return 0
    109      endfunc
    110 
    111      setlocal indentexpr=Indent()
    112      call setline(1, [repeat('a', 80), repeat('b', 80)])
    113    ]])
    114 
    115    feed('ggVG')
    116    screen:expect {
    117      grid = [[
    118      {17:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
    119      {17:aaaaaaaaaaaaaaaaaaaa}                                        |
    120      ^b{17:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}|
    121      {17:bbbbbbbbbbbbbbbbbbbb}                                        |
    122      {1:~                                                           }|
    123      {5:-- VISUAL LINE --}                                           |
    124    ]],
    125      mode = 'visual',
    126    }
    127 
    128    feed('gq')
    129    screen:expect {
    130      grid = [[
    131      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
    132      aaaaaaaaaaaaaaaaaaaa                                        |
    133      ^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
    134      bbbbbbbbbbbbbbbbbbbb                                        |
    135      {1:~                                                           }|
    136                                                                  |
    137    ]],
    138      mode = 'normal',
    139    }
    140  end)
    141 
    142  it('works in insert mode', function()
    143    feed('i')
    144    screen:expect {
    145      grid = [[
    146      ^                         |
    147      {1:~                        }|*2
    148      {5:-- INSERT --}             |
    149    ]],
    150      mode = 'insert',
    151    }
    152 
    153    feed('word<esc>')
    154    screen:expect {
    155      grid = [[
    156      wor^d                     |
    157      {1:~                        }|*2
    158                               |
    159    ]],
    160      mode = 'normal',
    161    }
    162 
    163    local matchtime = 0
    164    command('set showmatch')
    165    retry(nil, nil, function()
    166      matchtime = matchtime + 1
    167      local screen_timeout = 1000 * matchtime -- fail faster for retry.
    168 
    169      command('set matchtime=' .. matchtime) -- tenths of seconds
    170      feed('a(stuff')
    171      screen:expect {
    172        grid = [[
    173        word(stuff^               |
    174        {1:~                        }|*2
    175        {5:-- INSERT --}             |
    176      ]],
    177        mode = 'insert',
    178        timeout = screen_timeout,
    179      }
    180 
    181      feed(')')
    182      screen:expect {
    183        grid = [[
    184        word^(stuff)              |
    185        {1:~                        }|*2
    186        {5:-- INSERT --}             |
    187      ]],
    188        mode = 'showmatch',
    189        timeout = screen_timeout,
    190      }
    191 
    192      screen:expect {
    193        grid = [[
    194        word(stuff)^              |
    195        {1:~                        }|*2
    196        {5:-- INSERT --}             |
    197      ]],
    198        mode = 'insert',
    199        timeout = screen_timeout,
    200      }
    201    end)
    202  end)
    203 
    204  it('works in replace mode', function()
    205    feed('R')
    206    screen:expect {
    207      grid = [[
    208      ^                         |
    209      {1:~                        }|*2
    210      {5:-- REPLACE --}            |
    211    ]],
    212      mode = 'replace',
    213    }
    214 
    215    feed('word<esc>')
    216    screen:expect {
    217      grid = [[
    218      wor^d                     |
    219      {1:~                        }|*2
    220                               |
    221    ]],
    222      mode = 'normal',
    223    }
    224  end)
    225 
    226  it('works in cmdline mode', function()
    227    feed(':')
    228    screen:expect {
    229      grid = [[
    230                               |
    231      {1:~                        }|*2
    232      :^                        |
    233    ]],
    234      mode = 'cmdline_normal',
    235    }
    236 
    237    feed('x<left>')
    238    screen:expect {
    239      grid = [[
    240                               |
    241      {1:~                        }|*2
    242      :^x                       |
    243    ]],
    244      mode = 'cmdline_insert',
    245    }
    246 
    247    feed('<insert>')
    248    screen:expect {
    249      grid = [[
    250                               |
    251      {1:~                        }|*2
    252      :^x                       |
    253    ]],
    254      mode = 'cmdline_replace',
    255    }
    256 
    257    feed('<right>')
    258    screen:expect {
    259      grid = [[
    260                               |
    261      {1:~                        }|*2
    262      :x^                       |
    263    ]],
    264      mode = 'cmdline_normal',
    265    }
    266 
    267    feed('<esc>')
    268    screen:expect {
    269      grid = [[
    270      ^                         |
    271      {1:~                        }|*2
    272                               |
    273    ]],
    274      mode = 'normal',
    275    }
    276  end)
    277 
    278  it('works in visual mode', function()
    279    insert('text')
    280    feed('v')
    281    screen:expect {
    282      grid = [[
    283      tex^t                     |
    284      {1:~                        }|*2
    285      {5:-- VISUAL --}             |
    286    ]],
    287      mode = 'visual',
    288    }
    289 
    290    feed('<esc>')
    291    screen:expect {
    292      grid = [[
    293      tex^t                     |
    294      {1:~                        }|*2
    295                               |
    296    ]],
    297      mode = 'normal',
    298    }
    299 
    300    command('set selection=exclusive')
    301    feed('v')
    302    screen:expect {
    303      grid = [[
    304      tex^t                     |
    305      {1:~                        }|*2
    306      {5:-- VISUAL --}             |
    307    ]],
    308      mode = 'visual_select',
    309    }
    310 
    311    feed('<esc>')
    312    screen:expect {
    313      grid = [[
    314      tex^t                     |
    315      {1:~                        }|*2
    316                               |
    317    ]],
    318      mode = 'normal',
    319    }
    320  end)
    321 end)