robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
5.8 KiB160 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local api = n.api
8local eq = t.eq
9local poke_eventloop = n.poke_eventloop
10local assert_alive = n.assert_alive
11
12local CSI = '\027['
13
14describe(':terminal synchronized output (mode 2026)', function()
15  local screen, chan, buf
16
17  before_each(function()
18    clear()
19    screen = Screen.new(50, 7)
20    buf = api.nvim_create_buf(true, true)
21    chan = api.nvim_open_term(buf, {})
22    api.nvim_win_set_buf(0, buf)
23  end)
24
25  it('renders content sent inside a synchronized update', function()
26    api.nvim_chan_send(chan, CSI .. '?2026h')
27    api.nvim_chan_send(chan, 'synced line 1\r\n')
28    api.nvim_chan_send(chan, 'synced line 2\r\n')
29    api.nvim_chan_send(chan, CSI .. '?2026l')
30    screen:expect([[
31      ^synced line 1                                     |
32      synced line 2                                     |
33                                                        |*4
34                                                        |
35    ]])
36  end)
37
38  it('renders all lines from a synchronized update', function()
39    api.nvim_chan_send(chan, CSI .. '?2026h')
40    for i = 1, 5 do
41      api.nvim_chan_send(chan, 'line ' .. i .. '\r\n')
42    end
43    api.nvim_chan_send(chan, CSI .. '?2026l')
44    screen:expect([[
45      ^line 1                                            |
46      line 2                                            |
47      line 3                                            |
48      line 4                                            |
49      line 5                                            |
50                                                        |
51                                                        |
52    ]])
53    -- Buffer lines should also match.
54    local lines = api.nvim_buf_get_lines(buf, 0, -1, true)
55    eq('line 1', lines[1])
56    eq('line 2', lines[2])
57    eq('line 5', lines[5])
58  end)
59
60  it('handles multiple synchronized update cycles', function()
61    -- First cycle.
62    api.nvim_chan_send(chan, CSI .. '?2026h')
63    api.nvim_chan_send(chan, 'cycle 1\r\n')
64    api.nvim_chan_send(chan, CSI .. '?2026l')
65    screen:expect([[
66      ^cycle 1                                           |
67                                                        |*5
68                                                        |
69    ]])
70
71    -- Second cycle.
72    api.nvim_chan_send(chan, CSI .. '?2026h')
73    api.nvim_chan_send(chan, 'cycle 2\r\n')
74    api.nvim_chan_send(chan, CSI .. '?2026l')
75    screen:expect([[
76      ^cycle 1                                           |
77      cycle 2                                           |
78                                                        |*4
79                                                        |
80    ]])
81  end)
82
83  it('works with content before and after sync', function()
84    -- Unsynchronized content.
85    api.nvim_chan_send(chan, 'before\r\n')
86    poke_eventloop()
87    screen:expect([[
88      ^before                                            |
89                                                        |*5
90                                                        |
91    ]])
92
93    -- Synchronized content.
94    api.nvim_chan_send(chan, CSI .. '?2026h')
95    api.nvim_chan_send(chan, 'during\r\n')
96    api.nvim_chan_send(chan, CSI .. '?2026l')
97    screen:expect([[
98      ^before                                            |
99      during                                            |
100                                                        |*4
101                                                        |
102    ]])
103
104    -- More unsynchronized content.
105    api.nvim_chan_send(chan, 'after\r\n')
106    screen:expect([[
107      ^before                                            |
108      during                                            |
109      after                                             |
110                                                        |*3
111                                                        |
112    ]])
113  end)
114
115  it('does not crash when mode 2026 is set and queried', function()
116    api.nvim_chan_send(chan, CSI .. '?2026h')
117    assert_alive()
118    api.nvim_chan_send(chan, CSI .. '?2026l')
119    assert_alive()
120  end)
121
122  it('defers screen update during sync mode', function()
123    -- Establish a known screen state first.
124    api.nvim_chan_send(chan, 'visible\r\n')
125    screen:expect([[
126      ^visible                                           |
127                                                        |*5
128                                                        |
129    ]])
130    -- Begin sync and send more content — screen should not change.
131    api.nvim_chan_send(chan, CSI .. '?2026h')
132    api.nvim_chan_send(chan, 'deferred\r\n')
133    screen:expect_unchanged()
134    -- End sync — now the deferred content should appear.
135    api.nvim_chan_send(chan, CSI .. '?2026l')
136    screen:expect([[
137      ^visible                                           |
138      deferred                                          |
139                                                        |*4
140                                                        |
141    ]])
142  end)
143
144  it('handles rapid sync on/off toggling', function()
145    for i = 1, 5 do
146      api.nvim_chan_send(chan, CSI .. '?2026h')
147      api.nvim_chan_send(chan, 'rapid ' .. i .. '\r\n')
148      api.nvim_chan_send(chan, CSI .. '?2026l')
149    end
150    screen:expect([[
151      ^rapid 1                                           |
152      rapid 2                                           |
153      rapid 3                                           |
154      rapid 4                                           |
155      rapid 5                                           |
156                                                        |
157                                                        |
158    ]])
159  end)
160end)