@@ -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,22 +101,14 @@ describe("mini.files integration", function()
88
101
expect (files [1 ]).to_be (" /Users/test/project/src" )
89
102
end )
90
103
91
- it (" should get multiple files in visual mode" , function ()
92
- mock_vim .fn .mode = function ()
93
- return " V" -- Visual line mode
94
- end
95
-
96
- -- Mock mini.files module
104
+ it (" should handle mini.files buffer path format" , function ()
105
+ -- Mock mini.files module that returns buffer-style paths
97
106
local mock_mini_files = {
98
- get_fs_entry = function (buf_id , line )
99
- if line == 1 then
100
- return { path = " /Users/test/project/file1.lua" }
101
- elseif line == 2 then
102
- return { path = " /Users/test/project/file2.lua" }
103
- elseif line == 3 then
104
- return { path = " /Users/test/project/src" }
107
+ get_fs_entry = function (buf_id )
108
+ if buf_id ~= 1 then
109
+ return nil
105
110
end
106
- return nil
111
+ return { path = " minifiles://42//Users/test/project/buffer_file.lua " }
107
112
end ,
108
113
}
109
114
package.loaded [" mini.files" ] = mock_mini_files
@@ -112,39 +117,37 @@ describe("mini.files integration", function()
112
117
113
118
expect (err ).to_be_nil ()
114
119
expect (files ).to_be_table ()
115
- expect (# files ).to_be (3 )
116
- expect (files [1 ]).to_be (" /Users/test/project/file1.lua" )
117
- expect (files [2 ]).to_be (" /Users/test/project/file2.lua" )
118
- expect (files [3 ]).to_be (" /Users/test/project/src" )
120
+ expect (# files ).to_be (1 )
121
+ expect (files [1 ]).to_be (" /Users/test/project/buffer_file.lua" )
119
122
end )
120
123
121
- it (" should filter out invalid files in visual mode" , function ()
122
- mock_vim .fn .mode = function ()
123
- return " V" -- Visual line mode
124
- end
125
-
126
- -- Mock mini.files module
127
- local mock_mini_files = {
128
- get_fs_entry = function (buf_id , line )
129
- if line == 1 then
130
- return { path = " /Users/test/project/valid.lua" }
131
- elseif line == 2 then
132
- return { path = " /Users/test/project/invalid.xyz" } -- Won't pass filereadable/isdirectory
133
- elseif line == 3 then
134
- return { path = " /Users/test/project/src" }
135
- end
136
- return nil
137
- end ,
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" },
138
131
}
139
- package.loaded [" mini.files" ] = mock_mini_files
140
-
141
- local files , err = integrations ._get_mini_files_selection ()
142
132
143
- expect (err ).to_be_nil ()
144
- expect (files ).to_be_table ()
145
- expect (# files ).to_be (2 ) -- Only valid.lua and src
146
- expect (files [1 ]).to_be (" /Users/test/project/valid.lua" )
147
- expect (files [2 ]).to_be (" /Users/test/project/src" )
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
148
151
end )
149
152
150
153
it (" should handle empty entry under cursor" , function ()
@@ -228,26 +231,6 @@ describe("mini.files integration", function()
228
231
expect (files ).to_be_table ()
229
232
expect (# files ).to_be (0 )
230
233
end )
231
-
232
- it (" should handle visual mode with no valid entries" , function ()
233
- mock_vim .fn .mode = function ()
234
- return " V" -- Visual line mode
235
- end
236
-
237
- -- Mock mini.files module
238
- local mock_mini_files = {
239
- get_fs_entry = function (buf_id , line )
240
- return nil -- No entries
241
- end ,
242
- }
243
- package.loaded [" mini.files" ] = mock_mini_files
244
-
245
- local files , err = integrations ._get_mini_files_selection ()
246
-
247
- expect (err ).to_be (" No file found under cursor" )
248
- expect (files ).to_be_table ()
249
- expect (# files ).to_be (0 )
250
- end )
251
234
end )
252
235
253
236
describe (" get_selected_files_from_tree" , function ()
@@ -279,4 +262,4 @@ describe("mini.files integration", function()
279
262
expect (files ).to_be_nil ()
280
263
end )
281
264
end )
282
- end )
265
+ end )
0 commit comments