neovim

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

search_stat_spec.lua (6701B)


      1 local n = require('test.functional.testnvim')()
      2 local Screen = require('test.functional.ui.screen')
      3 
      4 local clear, feed, exec, command = n.clear, n.feed, n.exec, n.command
      5 
      6 describe('search stat', function()
      7  local screen
      8  before_each(function()
      9    clear()
     10    screen = Screen.new(30, 10)
     11  end)
     12 
     13  -- oldtest: Test_search_stat_screendump()
     14  it('right spacing with silent mapping vim-patch:8.1.1970', function()
     15    exec([[
     16      set shortmess-=S
     17      " Append 50 lines with text to search for, "foobar" appears 20 times
     18      call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 20))
     19      call setline(2, 'find this')
     20      call setline(70, 'find this')
     21      nnoremap n n
     22      let @/ = 'find this'
     23      call cursor(1,1)
     24      norm n
     25    ]])
     26    screen:expect([[
     27      foobar                        |
     28      {10:^find this}                     |
     29      fooooobar                     |
     30      foba                          |
     31      foobar                        |*2
     32      foo                           |
     33      fooooobar                     |
     34      foba                          |
     35      /find this             [1/2]  |
     36    ]])
     37    command('nnoremap <silent> n n')
     38    feed('gg0n')
     39    screen:expect([[
     40      foobar                        |
     41      {10:^find this}                     |
     42      fooooobar                     |
     43      foba                          |
     44      foobar                        |*2
     45      foo                           |
     46      fooooobar                     |
     47      foba                          |
     48                             [1/2]  |
     49    ]])
     50  end)
     51 
     52  -- oldtest: Test_search_stat_foldopen()
     53  it('when only match is in fold vim-patch:8.2.0840', function()
     54    exec([[
     55      set shortmess-=S
     56      setl foldenable foldmethod=indent foldopen-=search
     57      call append(0, ['if', "\tfoo", "\tfoo", 'endif'])
     58      let @/ = 'foo'
     59      call cursor(1,1)
     60      norm n
     61    ]])
     62    screen:expect([[
     63      if                            |
     64      {13:^+--  2 lines: foo·············}|
     65      endif                         |
     66                                    |
     67      {1:~                             }|*5
     68      /foo                   [1/2]  |
     69    ]])
     70    feed('n')
     71    screen:expect([[
     72      if                            |
     73      {13:^+--  2 lines: foo·············}|
     74      endif                         |
     75                                    |
     76      {1:~                             }|*5
     77      /foo                 W [1/2]  |
     78    ]])
     79    feed('n')
     80    -- Note: there is an intermediate state where the search stat disappears.
     81    screen:expect_unchanged(true)
     82  end)
     83 
     84  -- oldtest: Test_search_stat_then_gd()
     85  it('is cleared by gd and gD vim-patch:8.2.3583', function()
     86    exec([[
     87      call setline(1, ['int cat;', 'int dog;', 'cat = dog;'])
     88      set shortmess-=S
     89      set hlsearch
     90    ]])
     91    feed('/dog<CR>')
     92    screen:expect([[
     93      int cat;                      |
     94      int {10:^dog};                      |
     95      cat = {10:dog};                    |
     96      {1:~                             }|*6
     97      /dog                   [1/2]  |
     98    ]])
     99    feed('G0gD')
    100    screen:expect([[
    101      int {10:^cat};                      |
    102      int dog;                      |
    103      {10:cat} = dog;                    |
    104      {1:~                             }|*6
    105                                    |
    106    ]])
    107  end)
    108 
    109  -- oldtest: Test_search_stat_and_incsearch()
    110  it('is not broken by calling searchcount() in tabline vim-patch:8.2.4378', function()
    111    exec([[
    112      call setline(1, ['abc--c', '--------abc', '--abc'])
    113      set hlsearch
    114      set incsearch
    115      set showtabline=2
    116 
    117      function MyTabLine()
    118      try
    119        let a=searchcount(#{recompute: 1, maxcount: -1})
    120        return a.current .. '/' .. a.total
    121      catch
    122        return ''
    123      endtry
    124      endfunction
    125 
    126      set tabline=%!MyTabLine()
    127    ]])
    128 
    129    feed('/abc')
    130    screen:expect([[
    131      {2:                              }|
    132      {10:abc}--c                        |
    133      --------{2:abc}                   |
    134      --{10:abc}                         |
    135      {1:~                             }|*5
    136      /abc^                          |
    137    ]])
    138 
    139    feed('<C-G>')
    140    screen:expect([[
    141      {2:3/3                           }|
    142      {10:abc}--c                        |
    143      --------{10:abc}                   |
    144      --{2:abc}                         |
    145      {1:~                             }|*5
    146      /abc^                          |
    147    ]])
    148 
    149    feed('<C-G>')
    150    screen:expect([[
    151      {2:1/3                           }|
    152      {2:abc}--c                        |
    153      --------{10:abc}                   |
    154      --{10:abc}                         |
    155      {1:~                             }|*5
    156      /abc^                          |
    157    ]])
    158  end)
    159 
    160  -- oldtest: Test_search_stat_backwards()
    161  it('when searching backwards', function()
    162    screen:try_resize(60, 10)
    163    exec([[
    164      set shm-=S
    165      call setline(1, ['test', ''])
    166    ]])
    167 
    168    feed('*')
    169    screen:expect([[
    170      {10:^test}                                                        |
    171                                                                  |
    172      {1:~                                                           }|*7
    173      /\<test\>                                          W [1/1]  |
    174    ]])
    175 
    176    feed('N')
    177    screen:expect([[
    178      {10:^test}                                                        |
    179                                                                  |
    180      {1:~                                                           }|*7
    181      ?\<test\>                                          W [1/1]  |
    182    ]])
    183 
    184    command('set shm+=S')
    185    feed('N')
    186    -- shows "Search Hit Bottom.."
    187    screen:expect([[
    188      {10:^test}                                                        |
    189                                                                  |
    190      {1:~                                                           }|*7
    191      {19:search hit TOP, continuing at BOTTOM}                        |
    192    ]])
    193  end)
    194 
    195  -- oldtest: Test_search_stat_smartcase_ignorecase()
    196  it('when changing case of pattern', function()
    197    exec([[
    198      set shm-=S ignorecase smartcase
    199      call setline(1, [' MainmainmainmmmainmAin', ''])
    200    ]])
    201 
    202    feed('/main<cr>nnnn')
    203    screen:expect([[
    204       {10:Mainmainmain}mm{10:main^mAin}       |
    205                                    |
    206      {1:~                             }|*7
    207      /main                  [5/5]  |
    208    ]])
    209 
    210    feed('/mAin<cr>')
    211    screen:expect([[
    212       Mainmainmainmmmain{10:^mAin}       |
    213                                    |
    214      {1:~                             }|*7
    215      /mAin                W [1/1]  |
    216    ]])
    217  end)
    218 end)