mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-12 02:40:31 +08:00
lib.attrsets.hasAttrByPath: Document law and laziness, and test it
This commit is contained in:
@@ -51,12 +51,19 @@ rec {
|
||||
|
||||
/* Return if an attribute from nested attribute set exists.
|
||||
|
||||
**Laws**:
|
||||
1. ```nix
|
||||
hasAttrByPath [] x == true
|
||||
```
|
||||
|
||||
Example:
|
||||
x = { a = { b = 3; }; }
|
||||
hasAttrByPath ["a" "b"] x
|
||||
=> true
|
||||
hasAttrByPath ["z" "z"] x
|
||||
=> false
|
||||
hasAttrByPath [] (throw "no need")
|
||||
=> true
|
||||
|
||||
Type:
|
||||
hasAttrByPath :: [String] -> AttrSet -> Bool
|
||||
|
||||
@@ -697,6 +697,11 @@ runTests {
|
||||
expected = false;
|
||||
};
|
||||
|
||||
testHasAttrByPathNonStrict = {
|
||||
expr = hasAttrByPath [] (throw "do not use");
|
||||
expected = true;
|
||||
};
|
||||
|
||||
testLongestValidPathPrefix_empty_empty = {
|
||||
expr = attrsets.longestValidPathPrefix [ ] { };
|
||||
expected = [ ];
|
||||
|
||||
Reference in New Issue
Block a user