@@ -86,3 +86,54 @@ describe('get_real_path', function()
86
86
assert .is .False (fs_utils .get_real_path (' .' ))
87
87
end )
88
88
end )
89
+
90
+ describe (' trim_common_root' , function ()
91
+ it (' trims the common root when all files share the same root with the shortest one' , function ()
92
+ local result = fs_utils .trim_common_root ({
93
+ ' foo/bar/baz.org' ,
94
+ ' foo/bar/baz/bar.org' ,
95
+ ' foo/bar/baz3.org' ,
96
+ })
97
+ assert .are .same ({
98
+ ' baz.org' ,
99
+ ' baz/bar.org' ,
100
+ ' baz3.org' ,
101
+ }, result )
102
+ end )
103
+
104
+ it (' trims the common root when there are multiple different roots' , function ()
105
+ local result = fs_utils .trim_common_root ({
106
+ ' foo/bar/tea/notes.org' ,
107
+ ' foo/bar/tea/todos.org' ,
108
+ ' foo/bar/baz/work.org' ,
109
+ ' foo/bar/baz/personal.org' ,
110
+ ' foo/bar/baz/project.org' ,
111
+ })
112
+
113
+ assert .are .same ({
114
+ ' tea/notes.org' ,
115
+ ' tea/todos.org' ,
116
+ ' baz/work.org' ,
117
+ ' baz/personal.org' ,
118
+ ' baz/project.org' ,
119
+ }, result )
120
+ end )
121
+
122
+ it (' returns paths as they are if they do not share the common root' , function ()
123
+ local result = fs_utils .trim_common_root ({
124
+ ' foo/bar/tea/notes.org' ,
125
+ ' foo/bar/tea/todos.org' ,
126
+ ' foo/bar/baz/work.org' ,
127
+ ' foo/bar/baz/personal.org' ,
128
+ ' other/bar/baz/project.org' ,
129
+ })
130
+
131
+ assert .are .same ({
132
+ ' foo/bar/tea/notes.org' ,
133
+ ' foo/bar/tea/todos.org' ,
134
+ ' foo/bar/baz/work.org' ,
135
+ ' foo/bar/baz/personal.org' ,
136
+ ' other/bar/baz/project.org' ,
137
+ }, result )
138
+ end )
139
+ end )
0 commit comments