@@ -229,6 +229,16 @@ describe("Path2", function()
229
229
assert .are .same (" lua" .. path .sep .. " plenary" , Path :new (" lua" , " plenary" ).filename )
230
230
end )
231
231
232
+ describe (" .exists()" , function ()
233
+ it_cross_plat (" finds files that exist" , function ()
234
+ assert .are .same (true , Path :new (" README.md" ):exists ())
235
+ end )
236
+
237
+ it_cross_plat (" returns false for files that do not exist" , function ()
238
+ assert .are .same (false , Path :new (" asdf.md" ):exists ())
239
+ end )
240
+ end )
241
+
232
242
describe (" .is_dir()" , function ()
233
243
it_cross_plat (" should find directories that exist" , function ()
234
244
assert .are .same (true , Path :new (" lua" ):is_dir ())
@@ -242,4 +252,86 @@ describe("Path2", function()
242
252
assert .are .same (false , Path :new (" README.md" ):is_dir ())
243
253
end )
244
254
end )
255
+
256
+ describe (" .is_file()" , function ()
257
+ it_cross_plat (" should not allow directories" , function ()
258
+ assert .are .same (true , not Path :new (" lua" ):is_file ())
259
+ end )
260
+
261
+ it_cross_plat (" should return false when the file does not exist" , function ()
262
+ assert .are .same (true , not Path :new (" asdf" ):is_file ())
263
+ end )
264
+
265
+ it_cross_plat (" should show files as file" , function ()
266
+ assert .are .same (true , Path :new (" README.md" ):is_file ())
267
+ end )
268
+ end )
269
+
270
+ -- describe(":make_relative", function()
271
+ -- local root = iswin and "c:\\" or "/"
272
+ -- it_cross_plat("can take absolute paths and make them relative to the cwd", function()
273
+ -- local p = Path:new { "lua", "plenary", "path.lua" }
274
+ -- local absolute = vim.loop.cwd() .. path.sep .. p.filename
275
+ -- local relative = Path:new(absolute):make_relative()
276
+ -- assert.are.same(p.filename, relative)
277
+ -- end)
278
+
279
+ -- it_cross_plat("can take absolute paths and make them relative to a given path", function()
280
+ -- local r = Path:new { root, "home", "prime" }
281
+ -- local p = Path:new { "aoeu", "agen.lua" }
282
+ -- local absolute = r.filename .. path.sep .. p.filename
283
+ -- local relative = Path:new(absolute):make_relative(r.filename)
284
+ -- assert.are.same(relative, p.filename)
285
+ -- end)
286
+
287
+ -- it_cross_plat("can take double separator absolute paths and make them relative to the cwd", function()
288
+ -- local p = Path:new { "lua", "plenary", "path.lua" }
289
+ -- local absolute = vim.loop.cwd() .. path.sep .. path.sep .. p.filename
290
+ -- local relative = Path:new(absolute):make_relative()
291
+ -- assert.are.same(relative, p.filename)
292
+ -- end)
293
+
294
+ -- it_cross_plat("can take double separator absolute paths and make them relative to a given path", function()
295
+ -- local r = Path:new { root, "home", "prime" }
296
+ -- local p = Path:new { "aoeu", "agen.lua" }
297
+ -- local absolute = r.filename .. path.sep .. path.sep .. p.filename
298
+ -- local relative = Path:new(absolute):make_relative(r.filename)
299
+ -- assert.are.same(relative, p.filename)
300
+ -- end)
301
+
302
+ -- it_cross_plat("can take absolute paths and make them relative to a given path with trailing separator", function()
303
+ -- local r = Path:new { root, "home", "prime" }
304
+ -- local p = Path:new { "aoeu", "agen.lua" }
305
+ -- local absolute = r.filename .. path.sep .. p.filename
306
+ -- local relative = Path:new(absolute):make_relative(r.filename .. path.sep)
307
+ -- assert.are.same(relative, p.filename)
308
+ -- end)
309
+
310
+ -- it_cross_plat("can take absolute paths and make them relative to the root directory", function()
311
+ -- local p = Path:new { "home", "prime", "aoeu", "agen.lua" }
312
+ -- local absolute = root .. p.filename
313
+ -- local relative = Path:new(absolute):make_relative(root)
314
+ -- assert.are.same(relative, p.filename)
315
+ -- end)
316
+
317
+ -- it_cross_plat("can take absolute paths and make them relative to themselves", function()
318
+ -- local p = Path:new { root, "home", "prime", "aoeu", "agen.lua" }
319
+ -- local relative = Path:new(p.filename):make_relative(p.filename)
320
+ -- assert.are.same(relative, ".")
321
+ -- end)
322
+
323
+ -- it_cross_plat("should not truncate if path separator is not present after cwd", function()
324
+ -- local cwd = "tmp" .. path.sep .. "foo"
325
+ -- local p = Path:new { "tmp", "foo_bar", "fileb.lua" }
326
+ -- local relative = Path:new(p.filename):make_relative(cwd)
327
+ -- assert.are.same(p.filename, relative)
328
+ -- end)
329
+
330
+ -- it_cross_plat("should not truncate if path separator is not present after cwd and cwd ends in path sep", function()
331
+ -- local cwd = "tmp" .. path.sep .. "foo" .. path.sep
332
+ -- local p = Path:new { "tmp", "foo_bar", "fileb.lua" }
333
+ -- local relative = Path:new(p.filename):make_relative(cwd)
334
+ -- assert.are.same(p.filename, relative)
335
+ -- end)
336
+ -- end)
245
337
end )
0 commit comments