robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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