window_spec.lua 10 KB

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