robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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