diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2023-12-11 13:25:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 13:25:45 +0100 |
commit | 6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8 (patch) | |
tree | a7758bc162ada271f9ae29f778eeee04473524de /lib/tests/misc.nix | |
parent | 287f9168f8443ebdd25ecc4c8f70ca9daef5554d (diff) | |
parent | 7d993b9521aa8a229648a1c33e730df8b630670f (diff) | |
download | nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar.gz nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar.bz2 nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar.lz nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar.xz nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.tar.zst nixlib-6c8fb49bfcc73cecdbd36856bec9e4deb6a150b8.zip |
Merge pull request #273004 from hercules-ci/attrset-path-longest-prefix
lib.attrsets.longestValidPathPrefix: init
Diffstat (limited to 'lib/tests/misc.nix')
-rw-r--r-- | lib/tests/misc.nix | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 608af656d02c..2884e880e13a 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -697,6 +697,51 @@ runTests { expected = false; }; + testHasAttrByPathNonStrict = { + expr = hasAttrByPath [] (throw "do not use"); + expected = true; + }; + + testLongestValidPathPrefix_empty_empty = { + expr = attrsets.longestValidPathPrefix [ ] { }; + expected = [ ]; + }; + + testLongestValidPathPrefix_empty_nonStrict = { + expr = attrsets.longestValidPathPrefix [ ] (throw "do not use"); + expected = [ ]; + }; + + testLongestValidPathPrefix_zero = { + expr = attrsets.longestValidPathPrefix [ "a" (throw "do not use") ] { d = null; }; + expected = [ ]; + }; + + testLongestValidPathPrefix_zero_b = { + expr = attrsets.longestValidPathPrefix [ "z" "z" ] "remarkably harmonious"; + expected = [ ]; + }; + + testLongestValidPathPrefix_one = { + expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a = null; }; + expected = [ "a" ]; + }; + + testLongestValidPathPrefix_two = { + expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b = null; }; + expected = [ "a" "b" ]; + }; + + testLongestValidPathPrefix_three = { + expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b.c = null; }; + expected = [ "a" "b" "c" ]; + }; + + testLongestValidPathPrefix_three_extra = { + expr = attrsets.longestValidPathPrefix [ "a" "b" "c" ] { a.b.c.d = throw "nope"; }; + expected = [ "a" "b" "c" ]; + }; + testFindFirstIndexExample1 = { expr = lists.findFirstIndex (x: x > 3) (abort "index found, so a default must not be evaluated") [ 1 6 4 ]; expected = 1; |