From e371c801fed71bb73bc7c027e3de5ad2a6116673 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 20 Apr 2026 19:30:28 +0200 Subject: add tests and fix path resolution bug --- src/lib/path.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib/path.lua') diff --git a/src/lib/path.lua b/src/lib/path.lua index a0be1e5..925f017 100644 --- a/src/lib/path.lua +++ b/src/lib/path.lua @@ -8,6 +8,7 @@ function Path:new(p) p = p:gsub("/$", "") p = p:gsub("^%./", "") p = p:gsub("/[^/]+/%.%.", "") + p = p:gsub("^[^/]+/%.%./", "") local path = { segments = p:split('/'), @@ -126,6 +127,18 @@ function Path:remove(opts) pipe:close() end +function Path:is_parent_of(child) + return tostring(child):starts_with(tostring(self)) +end + +function Path:relative_to_parent(path) + if not path:is_parent_of(self) then + return nil + end + + return Path:new(tostring(self):sub(#tostring(path) + 2)) +end + return { tests = { function() -- cgit v1.2.3-70-g09d2