@@ -55,6 +55,7 @@ describe("Path2", function()
5555 { { " lua/../README.md" }, " lua/../README.md" },
5656 { { " ./lua/../README.md" }, " lua/../README.md" },
5757 { " ./lua//..//README.md" , " lua/../README.md" },
58+ { { " foo" , " bar" , " baz" }, " foo/bar/baz" },
5859 { " foo/bar/" , " foo/bar" },
5960 { { readme_path }, readme_path },
6061 { { readme_path , license_path }, license_path }, -- takes only the last abs path
@@ -269,7 +270,16 @@ describe("Path2", function()
269270 end )
270271
271272 describe (" :make_relative" , function ()
272- local root = iswin and " c:\\ " or " /"
273+ local root = function ()
274+ if not iswin then
275+ return " /"
276+ end
277+ if hasshellslash and vim .o .shellslash then
278+ return " C:/"
279+ end
280+ return " C:\\ "
281+ end
282+
273283 it_cross_plat (" can take absolute paths and make them relative to the cwd" , function ()
274284 local p = Path :new { " lua" , " plenary" , " path.lua" }
275285 local absolute = vim .fn .getcwd () .. path .sep .. p .filename
@@ -278,7 +288,7 @@ describe("Path2", function()
278288 end )
279289
280290 it_cross_plat (" can take absolute paths and make them relative to a given path" , function ()
281- local r = Path :new { root , " home" , " prime" }
291+ local r = Path :new { root () , " home" , " prime" }
282292 local p = Path :new { " aoeu" , " agen.lua" }
283293 local absolute = r .filename .. path .sep .. p .filename
284294 local relative = Path :new (absolute ):make_relative (r .filename )
@@ -293,30 +303,29 @@ describe("Path2", function()
293303 end )
294304
295305 it_cross_plat (" can take double separator absolute paths and make them relative to a given path" , function ()
296- local r = Path :new { root , " home" , " prime" }
306+ local r = Path :new { root () , " home" , " prime" }
297307 local p = Path :new { " aoeu" , " agen.lua" }
298308 local absolute = r .filename .. path .sep .. path .sep .. p .filename
299309 local relative = Path :new (absolute ):make_relative (r .filename )
300310 assert .are .same (p .filename , relative )
301311 end )
302312
303313 it_cross_plat (" can take absolute paths and make them relative to a given path with trailing separator" , function ()
304- local r = Path :new { root , " home" , " prime" }
314+ local r = Path :new { root () , " home" , " prime" }
305315 local p = Path :new { " aoeu" , " agen.lua" }
306316 local absolute = r .filename .. path .sep .. p .filename
307317 local relative = Path :new (absolute ):make_relative (r .filename .. path .sep )
308318 assert .are .same (p .filename , relative )
309319 end )
310320
311321 it_cross_plat (" can take absolute paths and make them relative to the root directory" , function ()
312- local p = Path :new { root , " prime" , " aoeu" , " agen.lua" }
313- local absolute = root .. p .filename
314- local relative = Path :new (absolute ):make_relative (root )
315- assert .are .same (p .filename , relative )
322+ local p = Path :new { root (), " prime" , " aoeu" , " agen.lua" }
323+ local relative = Path :new (p :absolute ()):make_relative (root ())
324+ assert .are .same ((p .filename :gsub (root (), " " )), relative )
316325 end )
317326
318327 it_cross_plat (" can take absolute paths and make them relative to themselves" , function ()
319- local p = Path :new { root , " home" , " prime" , " aoeu" , " agen.lua" }
328+ local p = Path :new { root () , " home" , " prime" , " aoeu" , " agen.lua" }
320329 local relative = Path :new (p .filename ):make_relative (p .filename )
321330 assert .are .same (" ." , relative )
322331 end )
@@ -445,17 +454,16 @@ describe("Path2", function()
445454 assert .is_false (Path :new (" impossible" ):exists ())
446455 end )
447456
448- -- it_cross_plat("can set different modes", function()
449- -- local p = Path:new "_dir_not_exist"
450- -- assert.has_no_error(function()
451- -- p:mkdir { mode = 0755 }
452- -- end)
453- -- print(vim.uv.fs_stat(p:absolute()).mode)
454- -- assert_permission(0755, p:permission())
457+ it_cross_plat (" can set different modes" , function ()
458+ local p = Path :new " _dir_not_exist"
459+ assert .has_no_error (function ()
460+ p :mkdir { mode = 0755 }
461+ end )
462+ assert_permission (0755 , p :permission ())
455463
456- -- p:rmdir()
457- -- assert.is_false(p:exists())
458- -- end)
464+ p :rmdir ()
465+ assert .is_false (p :exists ())
466+ end )
459467 end )
460468
461469 describe (" parents" , function ()
0 commit comments