@@ -26,6 +26,7 @@ describe("plugin spec url/name", function()
26
26
end
27
27
local spec = Plugin .Spec .new (test [1 ])
28
28
local plugins = vim .tbl_values (spec .plugins )
29
+ assert (# spec .errors == 0 )
29
30
assert .equal (1 , # plugins )
30
31
assert .same (test [2 ], plugins [1 ])
31
32
end )
@@ -41,7 +42,8 @@ describe("plugin spec opt", function()
41
42
{ { { " foo/bar" , dependencies = { { " foo/dep1" }, " foo/dep2" } } } },
42
43
}
43
44
for _ , test in ipairs (tests ) do
44
- local spec = Plugin .Spec .new (test )
45
+ local spec = Plugin .Spec .new (vim .deepcopy (test ))
46
+ assert (# spec .errors == 0 )
45
47
Config .plugins = spec .plugins
46
48
Plugin .update_state ()
47
49
assert (vim .tbl_count (spec .plugins ) == 3 )
@@ -52,12 +54,168 @@ describe("plugin spec opt", function()
52
54
assert (spec .plugins .dep1 .lazy == true )
53
55
assert (spec .plugins .dep2 ._ .dep == true )
54
56
assert (spec .plugins .dep2 .lazy == true )
57
+ spec = Plugin .Spec .new (test )
58
+ for _ , plugin in pairs (spec .plugins ) do
59
+ plugin .dir = nil
60
+ end
61
+ assert .same (spec .plugins , {
62
+ bar = {
63
+ " foo/bar" ,
64
+ _ = {},
65
+ dependencies = { " dep1" , " dep2" },
66
+ name = " bar" ,
67
+ url = " https://github.com/foo/bar.git" ,
68
+ },
69
+ dep1 = {
70
+ " foo/dep1" ,
71
+ _ = {
72
+ dep = true ,
73
+ },
74
+ name = " dep1" ,
75
+ url = " https://github.com/foo/dep1.git" ,
76
+ },
77
+ dep2 = {
78
+ " foo/dep2" ,
79
+ _ = {
80
+ dep = true ,
81
+ },
82
+ name = " dep2" ,
83
+ url = " https://github.com/foo/dep2.git" ,
84
+ },
85
+ })
55
86
end
56
87
end )
57
88
89
+ describe (" deps" , function ()
90
+ it (" handles dep names" , function ()
91
+ Config .options .defaults .lazy = false
92
+ local tests = {
93
+ { { " foo/bar" , dependencies = { { " dep1" }, " foo/dep2" } }, " foo/dep1" },
94
+ { " foo/dep1" , { " foo/bar" , dependencies = { { " dep1" }, " foo/dep2" } } },
95
+ }
96
+ for _ , test in ipairs (tests ) do
97
+ local spec = Plugin .Spec .new (vim .deepcopy (test ))
98
+ assert (# spec .errors == 0 )
99
+ Config .plugins = spec .plugins
100
+ Plugin .update_state ()
101
+ spec = Plugin .Spec .new (test )
102
+ for _ , plugin in pairs (spec .plugins ) do
103
+ plugin .dir = nil
104
+ end
105
+ assert .same (spec .plugins , {
106
+ bar = {
107
+ " foo/bar" ,
108
+ _ = {},
109
+ dependencies = { " dep1" , " dep2" },
110
+ name = " bar" ,
111
+ url = " https://github.com/foo/bar.git" ,
112
+ },
113
+ dep1 = {
114
+ " foo/dep1" ,
115
+ _ = {},
116
+ name = " dep1" ,
117
+ url = " https://github.com/foo/dep1.git" ,
118
+ },
119
+ dep2 = {
120
+ " foo/dep2" ,
121
+ _ = {
122
+ dep = true ,
123
+ },
124
+ name = " dep2" ,
125
+ url = " https://github.com/foo/dep2.git" ,
126
+ },
127
+ })
128
+ end
129
+ end )
130
+
131
+ it (" handles opt from dep" , function ()
132
+ Config .options .defaults .lazy = false
133
+ local spec = Plugin .Spec .new ({ " foo/dep1" , { " foo/bar" , dependencies = { " foo/dep1" , " foo/dep2" } } })
134
+ assert (# spec .errors == 0 )
135
+ Config .plugins = spec .plugins
136
+ Plugin .update_state ()
137
+ assert .same (3 , vim .tbl_count (spec .plugins ))
138
+ assert (spec .plugins .bar ._ .dep ~= true )
139
+ assert (spec .plugins .bar .lazy == false )
140
+ assert (spec .plugins .dep2 ._ .dep == true )
141
+ assert (spec .plugins .dep2 .lazy == true )
142
+ assert (spec .plugins .dep1 ._ .dep ~= true )
143
+ assert (spec .plugins .dep1 .lazy == false )
144
+ end )
145
+
146
+ it (" handles defaults opt" , function ()
147
+ do
148
+ Config .options .defaults .lazy = true
149
+ local spec = Plugin .Spec .new ({ " foo/bar" })
150
+ assert (# spec .errors == 0 )
151
+ Config .plugins = spec .plugins
152
+ Plugin .update_state ()
153
+ assert (spec .plugins .bar .lazy == true )
154
+ end
155
+ do
156
+ Config .options .defaults .lazy = false
157
+ local spec = Plugin .Spec .new ({ " foo/bar" })
158
+ Config .plugins = spec .plugins
159
+ Plugin .update_state ()
160
+ assert (spec .plugins .bar .lazy == false )
161
+ end
162
+ end )
163
+
164
+ it (" handles opt from dep" , function ()
165
+ Config .options .defaults .lazy = false
166
+ local spec = Plugin .Spec .new ({ " foo/bar" , event = " foo" })
167
+ assert (# spec .errors == 0 )
168
+ Config .plugins = spec .plugins
169
+ Plugin .update_state ()
170
+ assert .same (1 , vim .tbl_count (spec .plugins ))
171
+ assert (spec .plugins .bar ._ .dep ~= true )
172
+ assert (spec .plugins .bar .lazy == true )
173
+ end )
174
+
175
+ it (" merges lazy loaders" , function ()
176
+ local tests = {
177
+ { { " foo/bar" , event = " mod1" }, { " foo/bar" , event = " mod2" } },
178
+ { { " foo/bar" , event = { " mod1" } }, { " foo/bar" , event = { " mod2" } } },
179
+ { { " foo/bar" , event = " mod1" }, { " foo/bar" , event = { " mod2" } } },
180
+ }
181
+ for _ , test in ipairs (tests ) do
182
+ local spec = Plugin .Spec .new (test )
183
+ assert (# spec .errors == 0 )
184
+ assert (vim .tbl_count (spec .plugins ) == 1 )
185
+ assert (type (spec .plugins .bar .event ) == " table" )
186
+ assert (# spec .plugins .bar .event == 2 )
187
+ assert (vim .tbl_contains (spec .plugins .bar .event , " mod1" ))
188
+ assert (vim .tbl_contains (spec .plugins .bar .event , " mod2" ))
189
+ end
190
+ end )
191
+
192
+ it (" refuses to merge" , function ()
193
+ local spec = Plugin .Spec .new ({
194
+ { " foo/dep1" , config = 1 },
195
+ {
196
+ " foo/bar" ,
197
+ dependencies = { { " foo/dep1" , config = 2 }, " foo/dep2" },
198
+ },
199
+ })
200
+ assert (# spec .errors > 0 )
201
+ end )
202
+
203
+ -- it("recursive deps", function()
204
+ -- local spec = Plugin.Spec.new({
205
+ -- "nvim-telescope/telescope.nvim",
206
+ -- dependencies = {
207
+ -- "nvim-lua/plenary.nvim",
208
+ -- { "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
209
+ -- { "nvim-telescope/telescope-frecency.nvim", dependencies = "kkharji/sqlite.lua" },
210
+ -- },
211
+ -- })
212
+ -- end)
213
+ end )
214
+
58
215
it (" handles opt from dep" , function ()
59
216
Config .options .defaults .lazy = false
60
217
local spec = Plugin .Spec .new ({ " foo/dep1" , { " foo/bar" , dependencies = { " foo/dep1" , " foo/dep2" } } })
218
+ assert (# spec .errors == 0 )
61
219
Config .plugins = spec .plugins
62
220
Plugin .update_state ()
63
221
assert .same (3 , vim .tbl_count (spec .plugins ))
@@ -73,6 +231,7 @@ describe("plugin spec opt", function()
73
231
do
74
232
Config .options .defaults .lazy = true
75
233
local spec = Plugin .Spec .new ({ " foo/bar" })
234
+ assert (# spec .errors == 0 )
76
235
Config .plugins = spec .plugins
77
236
Plugin .update_state ()
78
237
assert (spec .plugins .bar .lazy == true )
@@ -89,6 +248,7 @@ describe("plugin spec opt", function()
89
248
it (" handles opt from dep" , function ()
90
249
Config .options .defaults .lazy = false
91
250
local spec = Plugin .Spec .new ({ " foo/bar" , event = " foo" })
251
+ assert (# spec .errors == 0 )
92
252
Config .plugins = spec .plugins
93
253
Plugin .update_state ()
94
254
assert .same (1 , vim .tbl_count (spec .plugins ))
@@ -104,6 +264,7 @@ describe("plugin spec opt", function()
104
264
}
105
265
for _ , test in ipairs (tests ) do
106
266
local spec = Plugin .Spec .new (test )
267
+ assert (# spec .errors == 0 )
107
268
assert (vim .tbl_count (spec .plugins ) == 1 )
108
269
assert (type (spec .plugins .bar .event ) == " table" )
109
270
assert (# spec .plugins .bar .event == 2 )
@@ -113,13 +274,14 @@ describe("plugin spec opt", function()
113
274
end )
114
275
115
276
it (" refuses to merge" , function ()
116
- Plugin .Spec .new ({
277
+ local spec = Plugin .Spec .new ({
117
278
{ " foo/dep1" , config = 1 },
118
279
{
119
280
" foo/bar" ,
120
281
dependencies = { { " foo/dep1" , config = 2 }, " foo/dep2" },
121
282
},
122
283
})
284
+ assert (# spec .errors > 0 )
123
285
end )
124
286
125
287
-- it("recursive deps", function()
0 commit comments