Skip to content

Commit c150316

Browse files
committed
more fixes
1 parent 34c4f55 commit c150316

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lua/plenary/path2.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ end
342342
---@field private _raw_parts string[]
343343
---@field drv string drive name, eg. 'C:' (only for Windows, empty string for Posix)
344344
---@field root string root path (excludes drive name for Windows)
345+
---@field anchor string drive + root (eg 'C:/' for Windows, just '/' otherwise)
345346
---@field relparts string[] path separator separated relative path parts
346347
---@field sep string path separator (respects 'shellslash' on Windows)
347348
---@field filename string
@@ -362,6 +363,11 @@ Path.__index = function(t, k)
362363
return rawget(t, k)
363364
end
364365

366+
if k == "anchor" then
367+
t.anchor = t.drv .. t.root
368+
return t.anchor
369+
end
370+
365371
if k == "filename" then
366372
t.filename = t:_filename()
367373
return t.filename

tests/plenary/path2_spec.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,39 +233,39 @@ describe("Path2", function()
233233

234234
describe(".exists()", function()
235235
it_cross_plat("finds files that exist", function()
236-
assert.are.same(true, Path:new("README.md"):exists())
236+
assert.is_true(Path:new("README.md"):exists())
237237
end)
238238

239239
it_cross_plat("returns false for files that do not exist", function()
240-
assert.are.same(false, Path:new("asdf.md"):exists())
240+
assert.is_false(Path:new("asdf.md"):exists())
241241
end)
242242
end)
243243

244244
describe(".is_dir()", function()
245245
it_cross_plat("should find directories that exist", function()
246-
assert.are.same(true, Path:new("lua"):is_dir())
246+
assert.is_true(Path:new("lua"):is_dir())
247247
end)
248248

249249
it_cross_plat("should return false when the directory does not exist", function()
250-
assert.are.same(false, Path:new("asdf"):is_dir())
250+
assert.is_false(Path:new("asdf"):is_dir())
251251
end)
252252

253253
it_cross_plat("should not show files as directories", function()
254-
assert.are.same(false, Path:new("README.md"):is_dir())
254+
assert.is_false(Path:new("README.md"):is_dir())
255255
end)
256256
end)
257257

258258
describe(".is_file()", function()
259259
it_cross_plat("should not allow directories", function()
260-
assert.are.same(true, not Path:new("lua"):is_file())
260+
assert.is_true(not Path:new("lua"):is_file())
261261
end)
262262

263263
it_cross_plat("should return false when the file does not exist", function()
264-
assert.are.same(true, not Path:new("asdf"):is_file())
264+
assert.is_true(not Path:new("asdf"):is_file())
265265
end)
266266

267267
it_cross_plat("should show files as file", function()
268-
assert.are.same(true, Path:new("README.md"):is_file())
268+
assert.is_true(Path:new("README.md"):is_file())
269269
end)
270270
end)
271271

@@ -321,7 +321,7 @@ describe("Path2", function()
321321
it_cross_plat("can take absolute paths and make them relative to the root directory", function()
322322
local p = Path:new { root(), "prime", "aoeu", "agen.lua" }
323323
local relative = Path:new(p:absolute()):make_relative(root())
324-
assert.are.same((p.filename:gsub(root(), "")), relative)
324+
assert.are.same((p.filename:gsub("^" .. root(), "")), relative)
325325
end)
326326

327327
it_cross_plat("can take absolute paths and make them relative to themselves", function()

0 commit comments

Comments
 (0)