diff options
author | Gabriel Volpe <volpegabriel@gmail.com> | 2024-04-15 19:16:15 +0200 |
---|---|---|
committer | Gabriel Volpe <volpegabriel@gmail.com> | 2024-04-15 19:16:15 +0200 |
commit | fe2bead78b1034052eca1d695118997f31826924 (patch) | |
tree | f217b407bcca7e0e4610ded01c9c44ebaaf0b76b /lib/tests | |
parent | 10517cf9abe8d54c66b1dd5fb18fc4b03750037f (diff) |
lib/attrsets: introduce mapCartesianProduct
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/misc.nix | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index b66f335c74f54..e15e110682fb8 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -71,6 +71,7 @@ let makeIncludePath makeOverridable mapAttrs + mapCartesianProduct matchAttrs mergeAttrs meta @@ -1753,6 +1754,30 @@ runTests { ]; }; + testMapCartesianProductOfOneSet = { + expr = mapCartesianProduct ({a}: a * 2) { a = [ 1 2 3 ]; }; + expected = [ 2 4 6 ]; + }; + + testMapCartesianProductOfTwoSets = { + expr = mapCartesianProduct ({a,b}: a + b) { a = [ 1 ]; b = [ 10 20 ]; }; + expected = [ 11 21 ]; + }; + + testMapCartesianProcutOfTwoSetsWithOneEmpty = { + expr = mapCartesianProduct (x: x.a + x.b) { a = [ ]; b = [ 10 20 ]; }; + expected = [ ]; + }; + + testMapCartesianProductOfThreeSets = { + expr = mapCartesianProduct ({a,b,c}: a + b + c) { + a = [ 1 2 3 ]; + b = [ 10 20 30 ]; + c = [ 100 200 300 ]; + }; + expected = [ 111 211 311 121 221 321 131 231 331 112 212 312 122 222 322 132 232 332 113 213 313 123 223 323 133 233 333 ]; + }; + # The example from the showAttrPath documentation testShowAttrPathExample = { expr = showAttrPath [ "foo" "10" "bar" ]; |