Skip to content

Commit 678de0e

Browse files
test(path): add coverage for path.abspath (#511)
1 parent 6d82fc2 commit 678de0e

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

tests/test-path.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,32 @@ do -- path.splitpath & path.splitext
6666
end
6767

6868

69-
-- TODO: path.abspath
69+
do -- path.abspath
70+
local cp = path.currentdir()
71+
72+
-- Relative paths should become absolute and point to the same location
73+
local rel = path.abspath("docs")
74+
asserteq(path.isabs(rel), true)
75+
asserteq(slash(rel):sub(-#"/docs"), "/docs")
76+
77+
-- Absolute paths should remain unchanged or normalized
78+
local abs = path.abspath(cp)
79+
asserteq(slash(abs), slash(cp))
80+
81+
-- "." should resolve to the current directory
82+
local dot = path.abspath(".")
83+
asserteq(slash(dot), slash(cp))
84+
85+
-- ".." should resolve to an absolute parent path
86+
local parent = path.abspath("..")
87+
asserteq(path.isabs(parent), true)
88+
89+
-- Explicit pwd parameter should be honored
90+
local with_pwd = path.abspath("test.txt", cp)
91+
asserteq(path.isabs(with_pwd), true)
92+
asserteq(slash(with_pwd), slash(path.join(cp, "test.txt")))
93+
end
94+
7095

7196
-- TODO: path.dirname
7297

0 commit comments

Comments
 (0)