altscreen_spec.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local tt = require('test.functional.testterm')
  4. local clear, eq, api = n.clear, t.eq, n.api
  5. local feed = n.feed
  6. local feed_data = tt.feed_data
  7. local enter_altscreen = tt.enter_altscreen
  8. local exit_altscreen = tt.exit_altscreen
  9. if t.skip(t.is_os('win')) then
  10. return
  11. end
  12. describe(':terminal altscreen', function()
  13. local screen
  14. before_each(function()
  15. clear()
  16. screen = tt.setup_screen()
  17. feed_data({
  18. 'line1',
  19. 'line2',
  20. 'line3',
  21. 'line4',
  22. 'line5',
  23. 'line6',
  24. 'line7',
  25. 'line8',
  26. '',
  27. })
  28. screen:expect([[
  29. line4 |
  30. line5 |
  31. line6 |
  32. line7 |
  33. line8 |
  34. ^ |
  35. {3:-- TERMINAL --} |
  36. ]])
  37. enter_altscreen()
  38. screen:expect([[
  39. |*5
  40. ^ |
  41. {3:-- TERMINAL --} |
  42. ]])
  43. eq(10, api.nvim_buf_line_count(0))
  44. end)
  45. it('wont clear lines already in the scrollback', function()
  46. feed('<c-\\><c-n>gg')
  47. screen:expect([[
  48. ^tty ready |
  49. line1 |
  50. line2 |
  51. line3 |
  52. |*3
  53. ]])
  54. end)
  55. describe('on exit', function()
  56. before_each(exit_altscreen)
  57. it('restores buffer state', function()
  58. screen:expect([[
  59. line4 |
  60. line5 |
  61. line6 |
  62. line7 |
  63. line8 |
  64. ^ |
  65. {3:-- TERMINAL --} |
  66. ]])
  67. feed('<c-\\><c-n>gg')
  68. screen:expect([[
  69. ^tty ready |
  70. line1 |
  71. line2 |
  72. line3 |
  73. line4 |
  74. line5 |
  75. |
  76. ]])
  77. end)
  78. end)
  79. describe('with lines printed after the screen height limit', function()
  80. before_each(function()
  81. feed_data({
  82. 'line9',
  83. 'line10',
  84. 'line11',
  85. 'line12',
  86. 'line13',
  87. 'line14',
  88. 'line15',
  89. 'line16',
  90. '',
  91. })
  92. screen:expect([[
  93. line12 |
  94. line13 |
  95. line14 |
  96. line15 |
  97. line16 |
  98. ^ |
  99. {3:-- TERMINAL --} |
  100. ]])
  101. end)
  102. it('wont modify line count', function()
  103. eq(10, api.nvim_buf_line_count(0))
  104. end)
  105. it('wont modify lines in the scrollback', function()
  106. feed('<c-\\><c-n>gg')
  107. screen:expect([[
  108. ^tty ready |
  109. line1 |
  110. line2 |
  111. line3 |
  112. line12 |
  113. line13 |
  114. |
  115. ]])
  116. end)
  117. end)
  118. describe('after height is decreased by 2', function()
  119. local function wait_removal()
  120. screen:try_resize(screen._width, screen._height - 2)
  121. screen:expect([[
  122. |*2
  123. rows: 4, cols: 50 |
  124. ^ |
  125. {3:-- TERMINAL --} |
  126. ]])
  127. end
  128. it('removes 2 lines from the bottom of the visible buffer', function()
  129. wait_removal()
  130. feed('<c-\\><c-n>4k')
  131. screen:expect([[
  132. ^ |
  133. |*2
  134. rows: 4, cols: 50 |
  135. |
  136. ]])
  137. eq(9, api.nvim_buf_line_count(0))
  138. end)
  139. describe('and after exit', function()
  140. before_each(function()
  141. wait_removal()
  142. exit_altscreen()
  143. end)
  144. it('restore buffer state', function()
  145. screen:expect([[
  146. line5 |
  147. line6 |
  148. line7 |
  149. ^line8 |
  150. {3:-- TERMINAL --} |
  151. ]])
  152. end)
  153. end)
  154. end)
  155. end)