neovim

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

autocmd_oldtest_spec.lua (3505B)


      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 = n.clear
      6 local eq = t.eq
      7 local api = n.api
      8 local fn = n.fn
      9 local exec = n.exec
     10 local feed = n.feed
     11 
     12 describe('oldtests', function()
     13  before_each(clear)
     14 
     15  local exec_lines = function(str)
     16    return fn.split(fn.execute(str), '\n')
     17  end
     18 
     19  local add_an_autocmd = function()
     20    exec [[
     21      augroup vimBarTest
     22        au BufReadCmd * echo 'hello'
     23      augroup END
     24    ]]
     25 
     26    eq(3, #exec_lines('au vimBarTest'))
     27    eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' }))
     28  end
     29 
     30  it('should recognize a bar before the {event}', function()
     31    -- Good spacing
     32    add_an_autocmd()
     33    exec [[ augroup vimBarTest | au! | augroup END ]]
     34    eq(1, #exec_lines('au vimBarTest'))
     35    eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' }))
     36 
     37    -- Sad spacing
     38    add_an_autocmd()
     39    exec [[ augroup vimBarTest| au!| augroup END ]]
     40    eq(1, #exec_lines('au vimBarTest'))
     41 
     42    -- test that a bar is recognized after the {event}
     43    add_an_autocmd()
     44    exec [[ augroup vimBarTest| au!BufReadCmd| augroup END ]]
     45    eq(1, #exec_lines('au vimBarTest'))
     46 
     47    add_an_autocmd()
     48    exec [[ au! vimBarTest|echo 'hello' ]]
     49    eq(1, #exec_lines('au vimBarTest'))
     50  end)
     51 
     52  -- oldtest: Test_delete_ml_get_errors()
     53  it('no ml_get error with TextChanged autocommand and delete', function()
     54    local screen = Screen.new(75, 10)
     55    screen:add_extra_attr_ids {
     56      [100] = { background = Screen.colors.Cyan1 },
     57    }
     58    exec([[
     59      set noshowcmd noruler scrolloff=0
     60      source test/old/testdir/samples/matchparen.vim
     61      edit test/old/testdir/samples/box.txt
     62    ]])
     63    feed('249GV<C-End>d')
     64    screen:expect([[
     65              const auto themeEmoji = _forPeer->themeEmoji();                    |
     66              if (themeEmoji.isEmpty()) {                                        |
     67                      return nonCustom;                                          |
     68              }                                                                  |
     69              const auto &themes = _forPeer->owner().cloudThemes();              |
     70              const auto theme = themes.themeForEmoji(themeEmoji);               |
     71              if (!theme) {100:{}                                                      |
     72                      return nonCustom;                                          |
     73              {100:^}}                                                                  |
     74      353 fewer lines                                                            |
     75    ]])
     76    feed('<PageUp>')
     77    screen:expect([[
     78                                                                                 |
     79      auto BackgroundBox::Inner::resolveResetCustomPaper() const                 |
     80      -> std::optional<Data::WallPaper> {                                        |
     81              if (!_forPeer) {                                                   |
     82                      return {};                                                 |
     83              }                                                                  |
     84              const auto nonCustom = Window::Theme::Background()->paper();       |
     85              const auto themeEmoji = _forPeer->themeEmoji();                    |
     86              ^if (themeEmoji.isEmpty()) {                                        |
     87      353 fewer lines                                                            |
     88    ]])
     89  end)
     90 end)