@@ -10,31 +10,68 @@ describe("util", function()
10
10
it (" lsmod lists all mods in dir" , function ()
11
11
local tests = {
12
12
{
13
+ root = " lua/foo" ,
14
+ mod = " foo" ,
13
15
files = { " lua/foo/one.lua" , " lua/foo/two.lua" , " lua/foo/init.lua" },
14
- mods = { " foo" , " foo.one " , " foo.two " },
16
+ mods = { " foo.one " , " foo.two " , " foo" },
15
17
},
16
18
{
19
+ root = " lua/foo" ,
20
+ mod = " foo" ,
17
21
files = { " lua/foo/one.lua" , " lua/foo/two.lua" , " lua/foo.lua" },
18
- mods = { " foo" , " foo.one " , " foo.two " },
22
+ mods = { " foo.one " , " foo.two " , " foo" },
19
23
},
20
24
{
25
+ root = " lua/foo" ,
26
+ mod = " foo" ,
21
27
files = { " lua/foo/one.lua" , " lua/foo/two.lua" },
22
28
mods = { " foo.one" , " foo.two" },
23
29
},
30
+ {
31
+ root = " lua/load-plugins" ,
32
+ mod = " load-plugins" ,
33
+ files = { " lua/load-plugins.lua" },
34
+ mods = { " load-plugins" },
35
+ },
24
36
}
25
37
26
38
vim .opt .rtp :append (Helpers .path (" " ))
27
- for _ , test in ipairs (tests ) do
28
- Cache . cache = {}
29
- table.sort (test . mods )
39
+ for t , test in ipairs (tests ) do
40
+ local expected = vim . deepcopy ( test . mods )
41
+ table.sort (expected )
30
42
Helpers .fs_rm (" " )
31
- Helpers .fs_create (test .files )
43
+ local files = Helpers .fs_create (test .files )
44
+
45
+ -- test with empty cache
46
+ Cache .cache = {}
47
+ Cache .indexed = {}
48
+ Cache .indexed_rtp = false
49
+ local root = Cache .find_root (test .mod )
50
+ assert (root , " no root found for " .. test .mod .. " (test " .. t .. " )" )
51
+ assert .same (Helpers .path (test .root ), root )
32
52
local mods = {}
33
- Util .lsmod (" foo" , function (modname , modpath )
53
+ Util .lsmod (test .mod , function (modname , modpath )
54
+ mods [# mods + 1 ] = modname
55
+ end )
56
+ table.sort (mods )
57
+ assert .same (expected , mods )
58
+
59
+ -- fill the cache
60
+ Cache .cache = {}
61
+ for i , file in ipairs (files ) do
62
+ Cache .cache [test .mods [i ]] = { modpath = file }
63
+ end
64
+ Cache .indexed = {}
65
+ Cache .indexed_rtp = false
66
+ root = Cache .find_root (test .mod )
67
+ assert (root , " no root found for " .. test .mod .. " (test " .. t .. " )" )
68
+ assert .same (Helpers .path (test .root ), root )
69
+ mods = {}
70
+ Util .lsmod (test .mod , function (modname , modpath )
34
71
mods [# mods + 1 ] = modname
35
72
end )
36
73
table.sort (mods )
37
- assert .same (test . mods , mods )
74
+ assert .same (expected , mods )
38
75
end
39
76
end )
40
77
end )
0 commit comments