@@ -55,6 +55,7 @@ describe("Path2", function()
55
55
{ { " lua/../README.md" }, " lua/../README.md" },
56
56
{ { " ./lua/../README.md" }, " lua/../README.md" },
57
57
{ " ./lua//..//README.md" , " lua/../README.md" },
58
+ { { " foo" , " bar" , " baz" }, " foo/bar/baz" },
58
59
{ " foo/bar/" , " foo/bar" },
59
60
{ { readme_path }, readme_path },
60
61
{ { readme_path , license_path }, license_path }, -- takes only the last abs path
@@ -269,7 +270,16 @@ describe("Path2", function()
269
270
end )
270
271
271
272
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
+
273
283
it_cross_plat (" can take absolute paths and make them relative to the cwd" , function ()
274
284
local p = Path :new { " lua" , " plenary" , " path.lua" }
275
285
local absolute = vim .fn .getcwd () .. path .sep .. p .filename
@@ -278,7 +288,7 @@ describe("Path2", function()
278
288
end )
279
289
280
290
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" }
282
292
local p = Path :new { " aoeu" , " agen.lua" }
283
293
local absolute = r .filename .. path .sep .. p .filename
284
294
local relative = Path :new (absolute ):make_relative (r .filename )
@@ -293,30 +303,29 @@ describe("Path2", function()
293
303
end )
294
304
295
305
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" }
297
307
local p = Path :new { " aoeu" , " agen.lua" }
298
308
local absolute = r .filename .. path .sep .. path .sep .. p .filename
299
309
local relative = Path :new (absolute ):make_relative (r .filename )
300
310
assert .are .same (p .filename , relative )
301
311
end )
302
312
303
313
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" }
305
315
local p = Path :new { " aoeu" , " agen.lua" }
306
316
local absolute = r .filename .. path .sep .. p .filename
307
317
local relative = Path :new (absolute ):make_relative (r .filename .. path .sep )
308
318
assert .are .same (p .filename , relative )
309
319
end )
310
320
311
321
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 )
316
325
end )
317
326
318
327
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" }
320
329
local relative = Path :new (p .filename ):make_relative (p .filename )
321
330
assert .are .same (" ." , relative )
322
331
end )
@@ -445,17 +454,16 @@ describe("Path2", function()
445
454
assert .is_false (Path :new (" impossible" ):exists ())
446
455
end )
447
456
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 ())
455
463
456
- -- p:rmdir()
457
- -- assert.is_false(p:exists())
458
- -- end)
464
+ p :rmdir ()
465
+ assert .is_false (p :exists ())
466
+ end )
459
467
end )
460
468
461
469
describe (" parents" , function ()
0 commit comments