summary refs log tree commit diff
path: root/lib/path/tests
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-07-19 16:20:40 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-07-26 23:20:12 +0200
commitb42e178ed4ba33925a474644f5bc54723b2ff15f (patch)
treeecb36719cc09dde24eb08f6f42209f85767eaffe /lib/path/tests
parent814f067760d029f532f990974a6df240d4320105 (diff)
lib.path.splitRoot: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Diffstat (limited to 'lib/path/tests')
-rw-r--r--lib/path/tests/unit.nix19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix
index 3e4b216f099ff..8bfb6f201219f 100644
--- a/lib/path/tests/unit.nix
+++ b/lib/path/tests/unit.nix
@@ -3,7 +3,7 @@
 { libpath }:
 let
   lib = import libpath;
-  inherit (lib.path) hasPrefix removePrefix append subpath;
+  inherit (lib.path) hasPrefix removePrefix append splitRoot subpath;
 
   cases = lib.runTests {
     # Test examples from the lib.path.append documentation
@@ -74,6 +74,23 @@ let
       expected = "./foo";
     };
 
+    testSplitRootExample1 = {
+      expr = splitRoot /foo/bar;
+      expected = { root = /.; subpath = "./foo/bar"; };
+    };
+    testSplitRootExample2 = {
+      expr = splitRoot /.;
+      expected = { root = /.; subpath = "./."; };
+    };
+    testSplitRootExample3 = {
+      expr = splitRoot /foo/../bar;
+      expected = { root = /.; subpath = "./bar"; };
+    };
+    testSplitRootExample4 = {
+      expr = (builtins.tryEval (splitRoot "/foo/bar")).success;
+      expected = false;
+    };
+
     # Test examples from the lib.path.subpath.isValid documentation
     testSubpathIsValidExample1 = {
       expr = subpath.isValid null;