Commit 7d993b95 authored by Robert Hensing's avatar Robert Hensing
Browse files

lib.attrsets.hasAttrByPath: Document law and laziness, and test it

parent 72bd4bbb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -697,6 +697,11 @@ runTests {
    expected = false;
  };

  testHasAttrByPathNonStrict = {
    expr = hasAttrByPath [] (throw "do not use");
    expected = true;
  };

  testLongestValidPathPrefix_empty_empty = {
    expr = attrsets.longestValidPathPrefix [ ] { };
    expected = [ ];