@@ -42,6 +42,11 @@ describe("mini.files integration", function()
42
42
return 0
43
43
end ,
44
44
},
45
+ api = {
46
+ nvim_get_current_buf = function ()
47
+ return 1 -- Mock buffer ID
48
+ end
49
+ },
45
50
bo = { filetype = " minifiles" },
46
51
}
47
52
@@ -57,7 +62,11 @@ describe("mini.files integration", function()
57
62
it (" should get single file under cursor" , function ()
58
63
-- Mock mini.files module
59
64
local mock_mini_files = {
60
- get_fs_entry = function ()
65
+ get_fs_entry = function (buf_id )
66
+ -- Verify buffer ID is passed correctly
67
+ if buf_id ~= 1 then
68
+ return nil
69
+ end
61
70
return { path = " /Users/test/project/main.lua" }
62
71
end ,
63
72
}
@@ -74,7 +83,11 @@ describe("mini.files integration", function()
74
83
it (" should get directory under cursor" , function ()
75
84
-- Mock mini.files module
76
85
local mock_mini_files = {
77
- get_fs_entry = function ()
86
+ get_fs_entry = function (buf_id )
87
+ -- Verify buffer ID is passed correctly
88
+ if buf_id ~= 1 then
89
+ return nil
90
+ end
78
91
return { path = " /Users/test/project/src" }
79
92
end ,
80
93
}
@@ -88,6 +101,89 @@ describe("mini.files integration", function()
88
101
expect (files [1 ]).to_be (" /Users/test/project/src" )
89
102
end )
90
103
104
+ it (" should handle mini.files buffer path format" , function ()
105
+ -- Mock mini.files module that returns buffer-style paths
106
+ local mock_mini_files = {
107
+ get_fs_entry = function (buf_id )
108
+ if buf_id ~= 1 then
109
+ return nil
110
+ end
111
+ return { path = " minifiles://42//Users/test/project/buffer_file.lua" }
112
+ end ,
113
+ }
114
+ package.loaded [" mini.files" ] = mock_mini_files
115
+
116
+ local files , err = integrations ._get_mini_files_selection ()
117
+
118
+ expect (err ).to_be_nil ()
119
+ expect (files ).to_be_table ()
120
+ expect (# files ).to_be (1 )
121
+ expect (files [1 ]).to_be (" /Users/test/project/buffer_file.lua" )
122
+ end )
123
+
124
+ it (" should handle various mini.files buffer path formats" , function ()
125
+ -- Test different buffer path formats that could occur
126
+ local test_cases = {
127
+ { input = " minifiles://42/Users/test/file.lua" , expected = " Users/test/file.lua" },
128
+ { input = " minifiles://42//Users/test/file.lua" , expected = " /Users/test/file.lua" },
129
+ { input = " minifiles://123///Users/test/file.lua" , expected = " //Users/test/file.lua" },
130
+ { input = " /Users/test/normal_path.lua" , expected = " /Users/test/normal_path.lua" },
131
+ }
132
+
133
+ for i , test_case in ipairs (test_cases ) do
134
+ local mock_mini_files = {
135
+ get_fs_entry = function (buf_id )
136
+ if buf_id ~= 1 then
137
+ return nil
138
+ end
139
+ return { path = test_case .input }
140
+ end ,
141
+ }
142
+ package.loaded [" mini.files" ] = mock_mini_files
143
+
144
+ local files , err = integrations ._get_mini_files_selection ()
145
+
146
+ expect (err ).to_be_nil ()
147
+ expect (files ).to_be_table ()
148
+ expect (# files ).to_be (1 )
149
+ expect (files [1 ]).to_be (test_case .expected )
150
+ end
151
+ end )
152
+
153
+ it (" should handle mini.files buffer paths in visual mode" , function ()
154
+ mock_vim .fn .mode = function ()
155
+ return " V" -- Visual line mode
156
+ end
157
+
158
+ -- Mock mini.files module that returns buffer-style paths
159
+ local mock_mini_files = {
160
+ get_fs_entry = function (buf_id , line )
161
+ if buf_id ~= 1 then
162
+ return nil
163
+ end
164
+
165
+ if line == 1 then
166
+ return { path = " minifiles://42//Users/test/project/visual1.lua" }
167
+ elseif line == 2 then
168
+ return { path = " minifiles://42//Users/test/project/visual2.txt" }
169
+ elseif line == 3 then
170
+ return { path = " minifiles://42//Users/test/project/src" }
171
+ end
172
+ return nil
173
+ end ,
174
+ }
175
+ package.loaded [" mini.files" ] = mock_mini_files
176
+
177
+ local files , err = integrations ._get_mini_files_selection ()
178
+
179
+ expect (err ).to_be_nil ()
180
+ expect (files ).to_be_table ()
181
+ expect (# files ).to_be (3 )
182
+ expect (files [1 ]).to_be (" /Users/test/project/visual1.lua" )
183
+ expect (files [2 ]).to_be (" /Users/test/project/visual2.txt" )
184
+ expect (files [3 ]).to_be (" /Users/test/project/src" )
185
+ end )
186
+
91
187
it (" should get multiple files in visual mode" , function ()
92
188
mock_vim .fn .mode = function ()
93
189
return " V" -- Visual line mode
@@ -96,6 +192,11 @@ describe("mini.files integration", function()
96
192
-- Mock mini.files module
97
193
local mock_mini_files = {
98
194
get_fs_entry = function (buf_id , line )
195
+ -- Verify buffer ID is passed correctly
196
+ if buf_id ~= 1 then
197
+ return nil
198
+ end
199
+
99
200
if line == 1 then
100
201
return { path = " /Users/test/project/file1.lua" }
101
202
elseif line == 2 then
@@ -147,6 +248,51 @@ describe("mini.files integration", function()
147
248
expect (files [2 ]).to_be (" /Users/test/project/src" )
148
249
end )
149
250
251
+ it (" should handle visual mode with buffer ID correctly" , function ()
252
+ mock_vim .fn .mode = function ()
253
+ return " v" -- Visual character mode
254
+ end
255
+
256
+ -- Mock different buffer ID to test parameter passing
257
+ mock_vim .api .nvim_get_current_buf = function ()
258
+ return 42 -- Different buffer ID
259
+ end
260
+
261
+ -- Mock mini.files module that validates buffer ID
262
+ local mock_mini_files = {
263
+ get_fs_entry = function (buf_id , line )
264
+ -- Should receive buffer ID 42
265
+ if buf_id ~= 42 then
266
+ error (" Expected buffer ID 42, got " .. tostring (buf_id ))
267
+ end
268
+
269
+ if line == 1 then
270
+ return { path = " /Users/test/project/selected1.lua" }
271
+ elseif line == 2 then
272
+ return { path = " /Users/test/project/selected2.txt" }
273
+ elseif line == 3 then
274
+ return { path = " /Users/test/project/selected3.lua" }
275
+ end
276
+ return nil
277
+ end ,
278
+ }
279
+ package.loaded [" mini.files" ] = mock_mini_files
280
+
281
+ local files , err = integrations ._get_mini_files_selection ()
282
+
283
+ expect (err ).to_be_nil ()
284
+ expect (files ).to_be_table ()
285
+ expect (# files ).to_be (3 )
286
+ expect (files [1 ]).to_be (" /Users/test/project/selected1.lua" )
287
+ expect (files [2 ]).to_be (" /Users/test/project/selected2.txt" )
288
+ expect (files [3 ]).to_be (" /Users/test/project/selected3.lua" )
289
+
290
+ -- Reset buffer ID for other tests
291
+ mock_vim .api .nvim_get_current_buf = function ()
292
+ return 1
293
+ end
294
+ end )
295
+
150
296
it (" should handle empty entry under cursor" , function ()
151
297
-- Mock mini.files module
152
298
local mock_mini_files = {
@@ -279,4 +425,4 @@ describe("mini.files integration", function()
279
425
expect (files ).to_be_nil ()
280
426
end )
281
427
end )
282
- end )
428
+ end )
0 commit comments