@@ -8,20 +8,27 @@ local function inspect(obj)
8
8
return vim .inspect (obj ):gsub (" %s+" , " " )
9
9
end
10
10
11
- --- @param plugins LazyPlugin[] | LazyPlugin
11
+ --- @param plugin LazyPlugin
12
+ local function resolve (plugin )
13
+ local meta = getmetatable (plugin )
14
+ local ret = meta and type (meta .__index ) == " table" and resolve (meta .__index ) or {}
15
+ for k , v in pairs (plugin ) do
16
+ ret [k ] = v
17
+ end
18
+ return ret
19
+ end
20
+
21
+ --- @param plugins LazyPlugin[]
12
22
local function clean (plugins )
13
- local p = plugins
14
- plugins = type (plugins ) == " table" and plugins or { plugins }
15
- for _ , plugin in pairs (plugins ) do
16
- plugin ._ .fid = nil
17
- plugin ._ .fpid = nil
18
- plugin ._ .fdeps = nil
23
+ return vim .tbl_map (function (plugin )
24
+ plugin = resolve (plugin )
25
+ plugin [1 ] = nil
19
26
plugin ._ .frags = nil
20
27
if plugin ._ .dep == false then
21
28
plugin ._ .dep = nil
22
29
end
23
- end
24
- return p
30
+ return plugin
31
+ end , plugins )
25
32
end
26
33
27
34
describe (" plugin spec url/name" , function ()
@@ -168,22 +175,19 @@ describe("plugin spec opt", function()
168
175
end
169
176
assert .same ({
170
177
bar = {
171
- " foo/bar" ,
172
178
_ = {},
173
179
dependencies = { " dep1" , " dep2" },
174
180
name = " bar" ,
175
181
url = " https://github.com/foo/bar.git" ,
176
182
},
177
183
dep1 = {
178
- " foo/dep1" ,
179
184
_ = {
180
185
dep = true ,
181
186
},
182
187
name = " dep1" ,
183
188
url = " https://github.com/foo/dep1.git" ,
184
189
},
185
190
dep2 = {
186
- " foo/dep2" ,
187
191
_ = {
188
192
dep = true ,
189
193
},
@@ -198,13 +202,13 @@ describe("plugin spec opt", function()
198
202
before_each (function ()
199
203
Handler .init ()
200
204
end )
201
- it ( " handles dep names " , function ()
202
- Config . options . defaults . lazy = false
203
- local tests = {
204
- { { " foo/bar" , dependencies = { { " dep1" }, " foo/dep2" } }, " foo/dep1 " },
205
- { " foo/dep1 " , { " foo/bar " , dependencies = { { " dep1 " }, " foo/dep2 " } } },
206
- }
207
- for _ , test in ipairs ( tests ) do
205
+ Config . options . defaults . lazy = false
206
+ local tests = {
207
+ { { " foo/bar " , dependencies = { { " dep1 " }, " foo/dep2 " } }, " foo/dep1 " },
208
+ { " foo/dep1 " , { " foo/bar" , dependencies = { { " dep1" }, " foo/dep2" } } },
209
+ }
210
+ for _ , test in ipairs ( tests ) do
211
+ it ( " handles dep names " .. inspect ( test ), function ()
208
212
local spec = Plugin .Spec .new (vim .deepcopy (test ))
209
213
assert (# spec .notifs == 0 )
210
214
Config .plugins = spec .plugins
@@ -213,31 +217,74 @@ describe("plugin spec opt", function()
213
217
for _ , plugin in pairs (spec .plugins ) do
214
218
plugin .dir = nil
215
219
end
216
- assert .same (clean ( spec . plugins ), {
220
+ assert .same ({
217
221
bar = {
218
- " foo/bar" ,
219
222
_ = {},
220
223
dependencies = { " dep1" , " dep2" },
221
224
name = " bar" ,
222
225
url = " https://github.com/foo/bar.git" ,
223
226
},
224
227
dep1 = {
225
- " foo/dep1" ,
226
228
_ = {},
227
229
name = " dep1" ,
228
230
url = " https://github.com/foo/dep1.git" ,
229
231
},
230
232
dep2 = {
231
- " foo/dep2" ,
232
233
_ = {
233
234
dep = true ,
234
235
},
235
236
name = " dep2" ,
236
237
url = " https://github.com/foo/dep2.git" ,
237
238
},
238
- })
239
- end
240
- end )
239
+ }, clean (spec .plugins ))
240
+ end )
241
+ end
242
+
243
+ Config .options .defaults .lazy = false
244
+ local tests = {
245
+ {
246
+ { " foo/baz" , name = " bar" },
247
+ { " foo/fee" , dependencies = { " foo/baz" } },
248
+ },
249
+ {
250
+ { " foo/fee" , dependencies = { " foo/baz" } },
251
+ { " foo/baz" , name = " bar" },
252
+ },
253
+ -- {
254
+ -- { "foo/baz", name = "bar" },
255
+ -- { "foo/fee", dependencies = { "baz" } },
256
+ -- },
257
+ {
258
+ { " foo/baz" , name = " bar" },
259
+ { " foo/fee" , dependencies = { " bar" } },
260
+ },
261
+ }
262
+ for _ , test in ipairs (tests ) do
263
+ it (" handles dep names " .. inspect (test ), function ()
264
+ local spec = Plugin .Spec .new (vim .deepcopy (test ))
265
+ assert (# spec .notifs == 0 )
266
+ Config .plugins = spec .plugins
267
+ Plugin .update_state ()
268
+ spec = Plugin .Spec .new (test )
269
+ spec .meta :rebuild ()
270
+ for _ , plugin in pairs (spec .plugins ) do
271
+ plugin .dir = nil
272
+ end
273
+ assert .same ({
274
+ bar = {
275
+ _ = {},
276
+ name = " bar" ,
277
+ url = " https://github.com/foo/baz.git" ,
278
+ },
279
+ fee = {
280
+ _ = {},
281
+ name = " fee" ,
282
+ url = " https://github.com/foo/fee.git" ,
283
+ dependencies = { " bar" },
284
+ },
285
+ }, clean (spec .plugins ))
286
+ end )
287
+ end
241
288
242
289
it (" handles opt from dep" , function ()
243
290
Config .options .defaults .lazy = false
0 commit comments