search_stat_spec.lua 6.0 KB

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