-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-cases.lua
More file actions
249 lines (190 loc) · 6.94 KB
/
test-cases.lua
File metadata and controls
249 lines (190 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
local M = {}
local helpers = require("tests.test-helpers")
M.two_tabs_with_two_buffers_for_each_tab = function()
require("tabscope").setup()
-- Creates first tab with two buffers
helpers.create_buffers({ "first", "second" })
helpers.assert_listed_buffers({ "first", "second" })
-- Creates second tab with two buffers
helpers.new_tab_with_buffer("third")
helpers.create_buffers({ "fourth" })
helpers.assert_listed_buffers({ "third", "fourth" })
-- Checks first tab
vim.cmd("tabprevious")
helpers.assert_listed_buffers({ "first", "second" })
-- Checks second tab
vim.cmd("tabnext")
helpers.assert_listed_buffers({ "third", "fourth" })
end
M.not_a_mutual_buffer_deleted = function()
require("tabscope").setup()
-- Creates first tab with two buffers
helpers.create_buffers({ "first", "second" })
-- Creates second tab with two not mutual buffers.
helpers.new_tab_with_buffer("third")
helpers.open_buffer("fourth")
-- Deletes third buffer
vim.cmd("bdelete third")
vim.wait(10)
-- Checks first tab
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
-- Checks second tab
helpers.tabnext()
helpers.assert_listed_buffers({ "fourth" })
end
M.tab_close = function()
require("tabscope").setup()
-- Creates first tab with two buffers
helpers.create_buffers({ "first", "second" })
-- Creates second tab with two buffers.
helpers.new_tab_with_buffer("third")
helpers.open_buffer("fourth")
-- Closes current tab
vim.cmd("tabclose")
-- Checks first tab
helpers.assert_listed_buffers({ "first", "second" })
end
M.tab_sbuffer = function()
require("tabscope").setup()
-- Creates first tab with two buffers
helpers.create_buffers({ "first", "second" })
helpers.open_buffer("second")
-- Creates second tab with second buffer
vim.cmd("tab sb")
vim.wait(10)
helpers.assert_listed_buffers({ "second" })
-- Checks first tab
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
-- Checks second tab
helpers.tabnext()
helpers.assert_listed_buffers({ "second" })
end
M.use_only_visible_buffers_on_load = function()
-- Creates three buffers
helpers.create_buffers({ "first", "second", "third" })
helpers.open_buffer("second")
-- Creates second tab and open new buffer
helpers.new_tab_with_buffer("fourth")
-- Loads plugin and checks that only visible buffers will be used.
require("tabscope").setup()
vim.wait(10)
-- Asserts that only visible buffers listed.
helpers.assert_listed_buffers({ "fourth" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "second" })
end
M.use_only_visible_buffers_on_SessionLoadPost = function()
require("tabscope").setup()
-- Emulate session loading
-- Creates first tab
helpers.create_buffers({ "first", "second", "third" })
helpers.open_buffer("first")
helpers.split("second")
-- Creates second tab
helpers.new_tab_with_buffer("fourth")
helpers.create_buffers({ "fifth" })
helpers.open_buffer("fourth")
-- Triggers SessionLoadPost
vim.cmd("doautoall SessionLoadPost")
vim.wait(10)
-- Asserts that only visible buffers listed.
helpers.assert_listed_buffers({ "fourth" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
end
M.use_only_visible_buffers_on_SessionLoadPost_even_if_some_buffers_are_mutual = function(
)
require("tabscope").setup()
-- Emulate session loading
-- Creates first tab
helpers.create_buffers({ "first", "second", "third" })
helpers.open_buffer("first")
-- Creates second tab
helpers.new_tab_with_buffer("fourth")
helpers.open_buffer("second")
helpers.split("third")
-- Triggers SessionLoadPost
vim.cmd("doautoall SessionLoadPost")
vim.wait(10)
-- Asserts that only visible buffers listed.
helpers.assert_listed_buffers({ "second", "third" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "first" })
end
M.remove_local_tab_buffer_with_mutual_appearance = function()
local tabscope = require("tabscope")
tabscope.setup()
-- Creates first tab
helpers.create_buffers({ "first", "second" })
helpers.open_buffer("first")
-- Creates second tab
helpers.new_tab_with_buffer("third")
helpers.split("second")
-- Removes local second buffer
local second_buffer = helpers.get_buffer_by_name("second")
tabscope.remove_tab_buffer(second_buffer)
-- Asserts that second buffer was deleted only for local tab
helpers.assert_listed_buffers({ "third" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
end
M.remove_local_tab_buffer_with_last_appearance = function()
local tabscope = require("tabscope")
tabscope.setup()
-- Creates first tab
helpers.create_buffers({ "first", "second" })
-- Creates second tab
helpers.new_tab_with_buffer("third")
helpers.split("fourth")
-- Removes local fourth buffer
local fourth_buffer = helpers.get_buffer_by_name("fourth")
tabscope.remove_tab_buffer(fourth_buffer)
-- Asserts that fourth buffer was deleted only for local tab
helpers.assert_listed_buffers({ "third" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
end
M.remove_local_tab_buffer_that_was_last_for_tab = function()
local tabscope = require("tabscope")
tabscope.setup()
-- Creates first tab
helpers.create_buffers({ "first", "second" })
-- Creates second tab
helpers.new_tab_with_buffer("third")
-- Removes local third buffer
local third_buffer = helpers.get_buffer_by_name("third")
tabscope.remove_tab_buffer(third_buffer)
-- Asserts that third buffer was replaced by noname buffer
helpers.assert_listed_buffers({ "" })
helpers.tabprevious()
helpers.assert_listed_buffers({ "first", "second" })
end
M.remove_tab_buffer_when_tracked_buffer_was_deleted_externally = function()
local tabscope = require("tabscope")
tabscope.setup()
-- Create buffers and visit them
local buf1 = vim.api.nvim_create_buf(true, false)
local buf2 = vim.api.nvim_create_buf(true, false)
vim.api.nvim_buf_set_name(buf1, "first")
vim.api.nvim_buf_set_name(buf2, "second")
vim.api.nvim_set_current_buf(buf1)
vim.api.nvim_set_current_buf(buf2)
-- Wipe buf1
vim.cmd("bwipeout! " .. buf1)
assert(not vim.api.nvim_buf_is_valid(buf1), "buf1 should be invalid after wipeout")
-- Simulate race condition: tracking contains ONLY buf2 and the invalid buf1
-- Use table replacement to ensure exact state, with invalid buffer ID first
local current_tab = vim.api.nvim_get_current_tabpage()
tabscope.tab_buffers._buffers_by_tab[current_tab] = {}
tabscope.tab_buffers._buffers_by_tab[current_tab][buf1] = true -- invalid, added first
tabscope.tab_buffers._buffers_by_tab[current_tab][buf2] = true -- valid, current
-- Close buf2 - tabscope must try to show buf1 (the only other tracked buffer)
-- Without the fix: "Invalid buffer id: X"
tabscope.remove_tab_buffer()
-- Should succeed without error
local listed = helpers.get_listed_buffers()
assert(#listed >= 1, "should have at least one buffer")
end
return M