diff options
Diffstat (limited to 'lib/path/tests/unit.nix')
-rw-r--r-- | lib/path/tests/unit.nix | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix index bad6560f13a9..9b0a0b2714aa 100644 --- a/lib/path/tests/unit.nix +++ b/lib/path/tests/unit.nix @@ -3,7 +3,10 @@ { libpath }: let lib = import libpath; - inherit (lib.path) hasPrefix removePrefix append splitRoot subpath; + inherit (lib.path) hasPrefix removePrefix append splitRoot hasStorePathPrefix subpath; + + # This is not allowed generally, but we're in the tests here, so we'll allow ourselves. + storeDirPath = /. + builtins.storeDir; cases = lib.runTests { # Test examples from the lib.path.append documentation @@ -91,6 +94,31 @@ let expected = false; }; + testHasStorePathPrefixExample1 = { + expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo/bar/baz"); + expected = true; + }; + testHasStorePathPrefixExample2 = { + expr = hasStorePathPrefix storeDirPath; + expected = false; + }; + testHasStorePathPrefixExample3 = { + expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo"); + expected = true; + }; + testHasStorePathPrefixExample4 = { + expr = hasStorePathPrefix /home/user; + expected = false; + }; + testHasStorePathPrefixExample5 = { + expr = hasStorePathPrefix (storeDirPath + "/.links/10gg8k3rmbw8p7gszarbk7qyd9jwxhcfq9i6s5i0qikx8alkk4hq"); + expected = false; + }; + testHasStorePathPrefixExample6 = { + expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo.drv"); + expected = true; + }; + # Test examples from the lib.path.subpath.isValid documentation testSubpathIsValidExample1 = { expr = subpath.isValid null; |