Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Mar 14, 2023
1 parent 6fa6578 commit 44032d8
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/path/tests/unit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{ libpath }:
let
lib = import libpath;
inherit (lib.path) append subpath;
inherit (lib.path) append difference subpath;

cases = lib.runTests {
# Test examples from the lib.path.append documentation
Expand Down Expand Up @@ -40,6 +40,38 @@ let
expected = false;
};

# Test examples from the documentation
testDifferenceExample1 = {
expr = difference { foo = ./foo; bar = ./bar; };
expected = { commonPrefix = ./.; suffix = { foo = "./foo"; bar = "./bar"; }; };
};
testDifferenceExample2 = {
expr = difference { foo = ./foo; bar = ./.; };
expected = { commonPrefix = ./.; suffix = { foo = "./foo"; bar = "./."; }; };
};
testDifferenceExample3 = {
expr = difference { foo = ./foo; bar = ./foo; };
expected = { commonPrefix = ./foo; suffix = { foo = "./."; bar = "./."; }; };
};
testDifferenceExample4 = {
expr = difference { foo = ./foo; bar = ./foo/bar; };
expected = { commonPrefix = ./foo; suffix = { foo = "./."; bar = "./bar"; }; };
};
# Test that the invalid cases cause throws
testDifferenceNonAttrset = {
expr = (builtins.tryEval (difference 10).commonPrefix).success;
expected = false;
};
testDifferenceEmpty = {
expr = (builtins.tryEval (difference { }).commonPrefix).success;
expected = false;
};
testDifferenceNonPath = {
expr = (builtins.tryEval (difference { a = 10; }).commonPrefix).success;
expected = false;
};
# We can't test for multiple roots with the current Nix version though

# Test examples from the lib.path.subpath.isValid documentation
testSubpathIsValidExample1 = {
expr = subpath.isValid null;
Expand Down

0 comments on commit 44032d8

Please sign in to comment.