diff options
| author | 2025-11-18 13:34:41 -0600 | |
|---|---|---|
| committer | 2025-11-22 08:52:40 -0600 | |
| commit | 9567921f95c7ac810f533db9d4b62c6a1c2c7cbc (patch) | |
| tree | 546c33c99f12e2862b5743e1fe8eb9682b83dbc3 | |
| parent | add win32 basename implementation to handle possible drive/UNC prefix and add... (diff) | |
add more to Win32 path prefix PEG to handle DOS device paths
| -rw-r--r-- | spork/path.janet | 4 | ||||
| -rw-r--r-- | test/suite-path.janet | 78 |
2 files changed, 81 insertions, 1 deletions
diff --git a/spork/path.janet b/spork/path.janet index 0ab0c46..08f038f 100644 --- a/spork/path.janet +++ b/spork/path.janet @@ -178,8 +178,10 @@ (def- win-prefix-peg (peg/compile ~{:drive (* (range "AZ" "az") `:` (any (choice `\` `/`)) ($)) + :dos-unc (* `\\` (choice "." "?") `\UNC\` (some (if-not `\` 1)) `\` (some (if-not `\` 1)) (any `\`) ($)) + :dos (* `\\` (choice "." "?") `\` (some (if-not `\` 1)) (any `\`) ($)) :unc (* `\\` (some (if-not `\` 1)) `\` (some (if-not `\` 1)) (any `\`) ($)) - :main (+ :drive :unc)})) + :main (+ :drive :dos-unc :dos :unc)})) (defn win32/abspath? "Check if a path is absolute." diff --git a/test/suite-path.janet b/test/suite-path.janet index 801f0bf..da209b8 100644 --- a/test/suite-path.janet +++ b/test/suite-path.janet @@ -81,10 +81,40 @@ (aeq (path/win32/basename `D:\foo.txt`) "foo.txt") (aeq (path/win32/basename `c:\`) "") (aeq (path/win32/basename `D:`) "") + (aeq (path/win32/basename `\\wsl$\Debian\home\abc`) `abc`) (aeq (path/win32/basename `\\wsl$\Debian\home abc`) `home abc`) (aeq (path/win32/basename `\\wsl$\Debian\`) "") (aeq (path/win32/basename `\\wsl$\Debian`) "") +(aeq (path/win32/basename `\\.\home\xyz`) `xyz`) +(aeq (path/win32/basename `\\.\homeabc`) "") +(aeq (path/win32/basename `\\.\`) "") +(aeq (path/win32/basename `\\?\`) "") +(aeq (path/win32/basename `\\.\c:\temp\test-file.txt`) "test-file.txt") +(aeq (path/win32/basename `\\?\c:\temp\test-file.txt`) "test-file.txt") +(aeq (path/win32/basename `\\.\c:\temp`) "temp") +(aeq (path/win32/basename `\\?\c:\temp`) "temp") +(aeq (path/win32/basename `\\.\c:\`) "") +(aeq (path/win32/basename `\\?\D:\`) "") +(aeq (path/win32/basename `\\.\c:`) "") +(aeq (path/win32/basename `\\?\D:`) "") + +(aeq (path/win32/basename `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) "Foo.txt") +(aeq (path/win32/basename `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) "") +(aeq (path/win32/basename `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) "") +(aeq (path/win32/basename `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}`) "") + +(aeq (path/win32/basename `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) "Foo.txt") +(aeq (path/win32/basename `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) "") +(aeq (path/win32/basename `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) "") +(aeq (path/win32/basename `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}`) "") + +(aeq (path/win32/basename `\\.\UNC\Localhost\c$\foo.txt`) `foo.txt`) +(aeq (path/win32/basename `\\.\UNC\Localhost\c$\`) "") +(aeq (path/win32/basename `\\.\UNC\Localhost\c$`) "") +(aeq (path/win32/basename `\\?\UNC\Localhost\c$\foo.txt`) `foo.txt`) +(aeq (path/win32/basename `\\?\UNC\Localhost\c$\`) "") +(aeq (path/win32/basename `\\?\UNC\Localhost\c$`) "") # dirname @@ -111,6 +141,34 @@ (aeq (path/win32/dirname `\\.\abc\def`) `\\.\abc\`) (aeq (path/win32/dirname `\\.\abc`) `\\.\abc`) +(aeq (path/win32/dirname `\\.\c:\temp\test-file.txt`) `\\.\c:\temp\`) +(aeq (path/win32/dirname `\\?\c:\temp\test-file.txt`) `\\?\c:\temp\`) +(aeq (path/win32/dirname `\\.\c:\temp\`) `\\.\c:\temp\`) +(aeq (path/win32/dirname `\\?\c:\temp\`) `\\?\c:\temp\`) +(aeq (path/win32/dirname `\\.\c:\temp`) `\\.\c:\`) +(aeq (path/win32/dirname `\\?\c:\temp`) `\\?\c:\`) +(aeq (path/win32/dirname `\\.\X:\`) `\\.\X:\`) +(aeq (path/win32/dirname `\\?\Y:\`) `\\?\Y:\`) +(aeq (path/win32/dirname `\\.\x:`) `\\.\x:`) +(aeq (path/win32/dirname `\\?\y:`) `\\?\y:`) + +(aeq (path/win32/dirname `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) +(aeq (path/win32/dirname `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) +(aeq (path/win32/dirname `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) +(aeq (path/win32/dirname `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}`) + +(aeq (path/win32/dirname `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) +(aeq (path/win32/dirname `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) +(aeq (path/win32/dirname `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) +(aeq (path/win32/dirname `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}`) + +(aeq (path/win32/dirname `\\.\UNC\Localhost\c$\foo.txt`) `\\.\UNC\Localhost\c$\`) +(aeq (path/win32/dirname `\\.\UNC\Localhost\c$\`) `\\.\UNC\Localhost\c$\`) +(aeq (path/win32/dirname `\\.\UNC\Localhost\c$`) `\\.\UNC\Localhost\c$`) +(aeq (path/win32/dirname `\\?\UNC\Localhost\c$\foo.txt`) `\\?\UNC\Localhost\c$\`) +(aeq (path/win32/dirname `\\?\UNC\Localhost\c$\`) `\\?\UNC\Localhost\c$\`) +(aeq (path/win32/dirname `\\?\UNC\Localhost\c$`) `\\?\UNC\Localhost\c$`) + # parent (aeq (path/posix/parent "/abc/def") "/abc") @@ -143,6 +201,26 @@ (aeq (path/win32/parent `\\.\xyz\def`) `\\.\xyz\`) (aeq (path/win32/parent `\\.\abc`) `\\.\abc`) +(aeq (path/win32/parent `\\.\X:\`) `\\.\X:\`) +(aeq (path/win32/parent `\\?\Y:\`) `\\?\Y:\`) +(aeq (path/win32/parent `\\.\x:`) `\\.\x:`) +(aeq (path/win32/parent `\\?\y:`) `\\?\y:`) + +(aeq (path/win32/parent `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test`) +(aeq (path/win32/parent `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test`) +(aeq (path/win32/parent `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) +(aeq (path/win32/parent `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}`) `\\.\Volume{b75e2c83-0000-0000-0000-602f00000000}`) + +(aeq (path/win32/parent `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\Foo.txt`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test`) +(aeq (path/win32/parent `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test\`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\Test`) +(aeq (path/win32/parent `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}\`) +(aeq (path/win32/parent `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}`) `\\?\Volume{b75e2c83-0000-0000-0000-602f00000000}`) + +(aeq (path/win32/parent `\\.\UNC\Localhost\c$\foo.txt`) `\\.\UNC\Localhost\c$\`) +(aeq (path/win32/parent `\\.\UNC\Localhost\c$\`) `\\.\UNC\Localhost\c$\`) +(aeq (path/win32/parent `\\.\UNC\Localhost\c$`) `\\.\UNC\Localhost\c$`) +(aeq (path/win32/parent `\\?\UNC\Localhost\c$\foo.txt`) `\\?\UNC\Localhost\c$\`) +(aeq (path/win32/parent `\\?\UNC\Localhost\c$`) `\\?\UNC\Localhost\c$`) # ext |
