mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 19:55:41 +03:00
Merge pull request #254452 from flyingcircusio/lib-attrsToList
lib.attrsets.attrsToList: add function
This commit is contained in:
commit
5323fbf703
3 changed files with 56 additions and 2 deletions
|
@ -20,6 +20,10 @@ let
|
|||
expr = (builtins.tryEval (builtins.seq expr "didn't throw"));
|
||||
expected = { success = false; value = false; };
|
||||
};
|
||||
testingEval = expr: {
|
||||
expr = (builtins.tryEval expr).success;
|
||||
expected = true;
|
||||
};
|
||||
testingDeepThrow = expr: testingThrow (builtins.deepSeq expr expr);
|
||||
|
||||
testSanitizeDerivationName = { name, expected }:
|
||||
|
@ -816,6 +820,26 @@ runTests {
|
|||
expected = { a = 1; b = 2; };
|
||||
};
|
||||
|
||||
testListAttrsReverse = let
|
||||
exampleAttrs = {foo=1; bar="asdf"; baz = [1 3 3 7]; fnord=null;};
|
||||
exampleSingletonList = [{name="foo"; value=1;}];
|
||||
in {
|
||||
expr = {
|
||||
isReverseToListToAttrs = builtins.listToAttrs (attrsToList exampleAttrs) == exampleAttrs;
|
||||
isReverseToAttrsToList = attrsToList (builtins.listToAttrs exampleSingletonList) == exampleSingletonList;
|
||||
testDuplicatePruningBehaviour = attrsToList (builtins.listToAttrs [{name="a"; value=2;} {name="a"; value=1;}]);
|
||||
};
|
||||
expected = {
|
||||
isReverseToAttrsToList = true;
|
||||
isReverseToListToAttrs = true;
|
||||
testDuplicatePruningBehaviour = [{name="a"; value=2;}];
|
||||
};
|
||||
};
|
||||
|
||||
testAttrsToListsCanDealWithFunctions = testingEval (
|
||||
attrsToList { someFunc= a: a + 1;}
|
||||
);
|
||||
|
||||
# GENERATORS
|
||||
# these tests assume attributes are converted to lists
|
||||
# in alphabetical order
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue