window_spec.lua 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local tt = require('test.functional.terminal.testutil')
  4. local feed_data = tt.feed_data
  5. local feed, clear = n.feed, n.clear
  6. local poke_eventloop = n.poke_eventloop
  7. local command = n.command
  8. local retry = t.retry
  9. local eq = t.eq
  10. local eval = n.eval
  11. local skip = t.skip
  12. local is_os = t.is_os
  13. describe(':terminal window', function()
  14. local screen
  15. before_each(function()
  16. clear()
  17. screen = tt.screen_setup()
  18. end)
  19. it('sets topline correctly #8556', function()
  20. skip(is_os('win'))
  21. -- Test has hardcoded assumptions of dimensions.
  22. eq(7, eval('&lines'))
  23. feed_data('\n\n\n') -- Add blank lines.
  24. -- Terminal/shell contents must exceed the height of this window.
  25. command('topleft 1split')
  26. eq('terminal', eval('&buftype'))
  27. feed([[i<cr>]])
  28. -- Check topline _while_ in terminal-mode.
  29. retry(nil, nil, function()
  30. eq(6, eval('winsaveview()["topline"]'))
  31. end)
  32. end)
  33. describe("with 'number'", function()
  34. it('wraps text', function()
  35. skip(is_os('win')) -- todo(clason): unskip when reenabling reflow
  36. feed([[<C-\><C-N>]])
  37. feed([[:set numberwidth=1 number<CR>i]])
  38. screen:expect([[
  39. {7:1 }tty ready |
  40. {7:2 }rows: 6, cols: 48 |
  41. {7:3 }{1: } |
  42. {7:4 } |
  43. {7:5 } |
  44. {7:6 } |
  45. {3:-- TERMINAL --} |
  46. ]])
  47. feed_data('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  48. screen:expect([[
  49. {7:1 }tty ready |
  50. {7:2 }rows: 6, cols: 48 |
  51. {7:3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV|
  52. {7:4 }WXYZ{1: } |
  53. {7:5 } |
  54. {7:6 } |
  55. {3:-- TERMINAL --} |
  56. ]])
  57. -- numberwidth=9
  58. feed([[<C-\><C-N>]])
  59. feed([[:set numberwidth=9 number<CR>i]])
  60. screen:expect([[
  61. {7: 1 }tty ready |
  62. {7: 2 }rows: 6, cols: 48 |
  63. {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
  64. {7: 4 }WXYZrows: 6, cols: 41 |
  65. {7: 5 }{1: } |
  66. {7: 6 } |
  67. {3:-- TERMINAL --} |
  68. ]])
  69. feed_data(' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  70. screen:expect([[
  71. {7: 1 }tty ready |
  72. {7: 2 }rows: 6, cols: 48 |
  73. {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO|
  74. {7: 4 }WXYZrows: 6, cols: 41 |
  75. {7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN|
  76. {7: 6 }OPQRSTUVWXYZ{1: } |
  77. {3:-- TERMINAL --} |
  78. ]])
  79. end)
  80. end)
  81. describe("with 'statuscolumn'", function()
  82. it('wraps text', function()
  83. skip(is_os('win')) -- todo(clason): unskip when reenabling reflow
  84. command([[set number statuscolumn=++%l\ \ ]])
  85. screen:expect([[
  86. {7:++1 }tty ready |
  87. {7:++2 }rows: 6, cols: 45 |
  88. {7:++3 }{1: } |
  89. {7:++4 } |
  90. {7:++5 } |
  91. {7:++6 } |
  92. {3:-- TERMINAL --} |
  93. ]])
  94. feed_data('\n\n\n\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  95. screen:expect([[
  96. {7:++4 } |
  97. {7:++5 } |
  98. {7:++6 } |
  99. {7:++7 } |
  100. {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS|
  101. {7:++9 }TUVWXYZ{1: } |
  102. {3:-- TERMINAL --} |
  103. ]])
  104. feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
  105. screen:expect([[
  106. {7:++7 } |
  107. {7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
  108. {7:++9 }TUVWXYZ |
  109. {7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
  110. {7:++11 }TUVWXYZrows: 6, cols: 44 |
  111. {7:++12 }{1: } |
  112. {3:-- TERMINAL --} |
  113. ]])
  114. end)
  115. end)
  116. describe("with 'colorcolumn'", function()
  117. before_each(function()
  118. feed([[<C-\><C-N>]])
  119. screen:expect([[
  120. tty ready |
  121. {2:^ } |
  122. |*5
  123. ]])
  124. feed(':set colorcolumn=20<CR>i')
  125. end)
  126. it('wont show the color column', function()
  127. screen:expect([[
  128. tty ready |
  129. {1: } |
  130. |*4
  131. {3:-- TERMINAL --} |
  132. ]])
  133. end)
  134. end)
  135. describe('with fold set', function()
  136. before_each(function()
  137. feed([[<C-\><C-N>:set foldenable foldmethod=manual<CR>i]])
  138. feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
  139. screen:expect([[
  140. tty ready |
  141. line1 |
  142. line2 |
  143. line3 |
  144. line4 |
  145. {1: } |
  146. {3:-- TERMINAL --} |
  147. ]])
  148. end)
  149. it('wont show any folds', function()
  150. feed([[<C-\><C-N>ggvGzf]])
  151. poke_eventloop()
  152. screen:expect([[
  153. ^tty ready |
  154. line1 |
  155. line2 |
  156. line3 |
  157. line4 |
  158. {2: } |
  159. |
  160. ]])
  161. end)
  162. end)
  163. end)
  164. describe(':terminal with multigrid', function()
  165. local screen
  166. before_each(function()
  167. clear()
  168. screen = tt.screen_setup(0, nil, 50, nil, { ext_multigrid = true })
  169. end)
  170. it('resizes to requested size', function()
  171. screen:expect([[
  172. ## grid 1
  173. [2:--------------------------------------------------]|*6
  174. [3:--------------------------------------------------]|
  175. ## grid 2
  176. tty ready |
  177. {1: } |
  178. |*4
  179. ## grid 3
  180. {3:-- TERMINAL --} |
  181. ]])
  182. screen:try_resize_grid(2, 20, 10)
  183. if is_os('win') then
  184. screen:expect { any = 'rows: 10, cols: 20' }
  185. else
  186. screen:expect([[
  187. ## grid 1
  188. [2:--------------------------------------------------]|*6
  189. [3:--------------------------------------------------]|
  190. ## grid 2
  191. tty ready |
  192. rows: 10, cols: 20 |
  193. {1: } |
  194. |*7
  195. ## grid 3
  196. {3:-- TERMINAL --} |
  197. ]])
  198. end
  199. screen:try_resize_grid(2, 70, 3)
  200. if is_os('win') then
  201. screen:expect { any = 'rows: 3, cols: 70' }
  202. else
  203. screen:expect([[
  204. ## grid 1
  205. [2:--------------------------------------------------]|*6
  206. [3:--------------------------------------------------]|
  207. ## grid 2
  208. rows: 10, cols: 20 |
  209. rows: 3, cols: 70 |
  210. {1: } |
  211. ## grid 3
  212. {3:-- TERMINAL --} |
  213. ]])
  214. end
  215. screen:try_resize_grid(2, 0, 0)
  216. if is_os('win') then
  217. screen:expect { any = 'rows: 6, cols: 50' }
  218. else
  219. screen:expect([[
  220. ## grid 1
  221. [2:--------------------------------------------------]|*6
  222. [3:--------------------------------------------------]|
  223. ## grid 2
  224. tty ready |
  225. rows: 10, cols: 20 |
  226. rows: 3, cols: 70 |
  227. rows: 6, cols: 50 |
  228. {1: } |
  229. |
  230. ## grid 3
  231. {3:-- TERMINAL --} |
  232. ]])
  233. end
  234. end)
  235. end)