summary refs log tree commit diff
path: root/lib/path/tests/unit.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2022-12-23 21:07:30 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-01-03 13:21:03 +0100
commit63dd6d20db8ac4b5576b48a58fe434319791a7d7 (patch)
treec71013a5372f5ba3fde90f45e3f1f7ee9356ea3e /lib/path/tests/unit.nix
parent98fbcf17888872f5ebdf9fb6247266929f4308db (diff)
downloadnixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar.gz
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar.bz2
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar.lz
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar.xz
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.tar.zst
nixpkgs-63dd6d20db8ac4b5576b48a58fe434319791a7d7.zip
lib.path.subpath.normalise: init
Diffstat (limited to 'lib/path/tests/unit.nix')
-rw-r--r--lib/path/tests/unit.nix49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix
index 15f5940a51e..eccf3b7b1c3 100644
--- a/lib/path/tests/unit.nix
+++ b/lib/path/tests/unit.nix
@@ -70,6 +70,55 @@ let
       expr = subpath.isValid "foo/..../bar";
       expected = true;
     };
+
+    testSubpathNormaliseExample1 = {
+      expr = subpath.normalise "foo//bar";
+      expected = "./foo/bar";
+    };
+    testSubpathNormaliseExample2 = {
+      expr = subpath.normalise "foo/./bar";
+      expected = "./foo/bar";
+    };
+    testSubpathNormaliseExample3 = {
+      expr = subpath.normalise "foo/bar";
+      expected = "./foo/bar";
+    };
+    testSubpathNormaliseExample4 = {
+      expr = subpath.normalise "foo/bar/";
+      expected = "./foo/bar";
+    };
+    testSubpathNormaliseExample5 = {
+      expr = subpath.normalise "foo/bar/.";
+      expected = "./foo/bar";
+    };
+    testSubpathNormaliseExample6 = {
+      expr = subpath.normalise ".";
+      expected = "./.";
+    };
+    testSubpathNormaliseExample7 = {
+      expr = (builtins.tryEval (subpath.normalise "foo/../bar")).success;
+      expected = false;
+    };
+    testSubpathNormaliseExample8 = {
+      expr = (builtins.tryEval (subpath.normalise "")).success;
+      expected = false;
+    };
+    testSubpathNormaliseExample9 = {
+      expr = (builtins.tryEval (subpath.normalise "/foo")).success;
+      expected = false;
+    };
+    testSubpathNormaliseIsValidDots = {
+      expr = subpath.normalise "./foo/.bar/.../baz...qux";
+      expected = "./foo/.bar/.../baz...qux";
+    };
+    testSubpathNormaliseWrongType = {
+      expr = (builtins.tryEval (subpath.normalise null)).success;
+      expected = false;
+    };
+    testSubpathNormaliseTwoDots = {
+      expr = (builtins.tryEval (subpath.normalise "..")).success;
+      expected = false;
+    };
   };
 in
   if cases == [] then "Unit tests successful"