From 1a2c2846b0933b596c51e964acb8a45ab9a13691 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 18 Jan 2023 18:15:55 +0100 Subject: lib.path.subpath.join: init This function can be used to safely join subpaths together --- lib/path/tests/unit.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/path/tests') diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix index a1a45173a9098..61c4ab4d6f2ee 100644 --- a/lib/path/tests/unit.nix +++ b/lib/path/tests/unit.nix @@ -107,6 +107,36 @@ let expected = true; }; + # Test examples from the lib.path.subpath.join documentation + testSubpathJoinExample1 = { + expr = subpath.join [ "foo" "bar/baz" ]; + expected = "./foo/bar/baz"; + }; + testSubpathJoinExample2 = { + expr = subpath.join [ "./foo" "." "bar//./baz/" ]; + expected = "./foo/bar/baz"; + }; + testSubpathJoinExample3 = { + expr = subpath.join [ ]; + expected = "./."; + }; + testSubpathJoinExample4 = { + expr = (builtins.tryEval (subpath.join [ /foo ])).success; + expected = false; + }; + testSubpathJoinExample5 = { + expr = (builtins.tryEval (subpath.join [ "" ])).success; + expected = false; + }; + testSubpathJoinExample6 = { + expr = (builtins.tryEval (subpath.join [ "/foo" ])).success; + expected = false; + }; + testSubpathJoinExample7 = { + expr = (builtins.tryEval (subpath.join [ "../foo" ])).success; + expected = false; + }; + # Test examples from the lib.path.subpath.normalise documentation testSubpathNormaliseExample1 = { expr = subpath.normalise "foo//bar"; -- cgit 1.4.1