altscreen_spec.lua 5.9 KB

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