@@ -213,10 +213,8 @@ describe("Path", function()
213213 local short_path = Path :new (long_path ):shorten ()
214214 assert .are .same (short_path , " /t/i/a/l/path" )
215215 end )
216- end )
217216
218- describe (" :shorten" , function ()
219- it (" can shorten a path components to a given length" , function ()
217+ it (" can shorten a path's components to a given length" , function ()
220218 local long_path = " /this/is/a/long/path"
221219 local short_path = Path :new (long_path ):shorten (2 )
222220 assert .are .same (short_path , " /th/is/a/lo/path" )
@@ -231,6 +229,41 @@ describe("Path", function()
231229 short_path = Path :new (long_path ):shorten (5 )
232230 assert .are .same (short_path , " this/is/an/extre/long/path" )
233231 end )
232+
233+ it (" can shorten a path's components when excluding parts" , function ()
234+ local long_path = " /this/is/a/long/path"
235+ local short_path = Path :new (long_path ):shorten (nil , { 1 , - 1 })
236+ assert .are .same (short_path , " /this/i/a/l/path" )
237+
238+ -- without the leading /
239+ long_path = " this/is/a/long/path"
240+ short_path = Path :new (long_path ):shorten (nil , { 1 , - 1 })
241+ assert .are .same (short_path , " this/i/a/l/path" )
242+
243+ -- where excluding positions greater than the number of parts
244+ long_path = " this/is/an/extremely/long/path"
245+ short_path = Path :new (long_path ):shorten (nil , { 2 , 4 , 6 , 8 })
246+ assert .are .same (short_path , " t/is/a/extremely/l/path" )
247+
248+ -- where excluding positions less than the negation of the number of parts
249+ long_path = " this/is/an/extremely/long/path"
250+ short_path = Path :new (long_path ):shorten (nil , { - 2 , - 4 , - 6 , - 8 })
251+ assert .are .same (short_path , " this/i/an/e/long/p" )
252+ end )
253+
254+ it (" can shorten a path's components to a given length and exclude positions" , function ()
255+ local long_path = " /this/is/a/long/path"
256+ local short_path = Path :new (long_path ):shorten (2 , { 1 , - 1 })
257+ assert .are .same (short_path , " /this/is/a/lo/path" )
258+
259+ long_path = " this/is/a/long/path"
260+ short_path = Path :new (long_path ):shorten (3 , { 2 , - 2 })
261+ assert .are .same (short_path , " thi/is/a/long/pat" )
262+
263+ long_path = " this/is/an/extremely/long/path"
264+ short_path = Path :new (long_path ):shorten (5 , { 3 , - 3 })
265+ assert .are .same (short_path , " this/is/an/extremely/long/path" )
266+ end )
234267 end )
235268
236269 describe (" mkdir / rmdir" , function ()
0 commit comments