diff options
author | Vincent Ambo <mail@tazj.in> | 2022-12-02T08·32+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-12-02T14·39+0000 |
commit | 5ab86ab8dcb59b5f63daa5ec869c8c6cbf97a458 (patch) | |
tree | b6f61f14c3aa2d241f342fa4daba82db94ebaf5d /tvix/eval/src/tests | |
parent | b9e3db35b2f7520a150208ebe7b6a439cc10aa9a (diff) |
test(tvix/eval): add a test for repeated keys in listToAttrs r/5373
This came up in the Nix Language channel today and I thought it warranted a test case. We did actually implement this correctly. Change-Id: I4b37c92d06eb6e3a7f59ea3d10af38f2b0a93d53 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7493 Reviewed-by: sterni <sternenseemann@systemli.org> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/tests')
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp | 1 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp new file mode 100644 index 000000000000..b4a1e66d6b8a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp @@ -0,0 +1 @@ +[ 1 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix new file mode 100644 index 000000000000..2f719dcef5be --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix @@ -0,0 +1,13 @@ +# Ensure that builtins.listToAttrs returns the first instance of a key. + +let + inherit (builtins) foldl' listToAttrs; + + input = [ { name = "result"; value = 1; } { name = "result"; value = 2; } ]; + + # foldl-based version of listToAttrs with the _opposite_ behaviour. + listToAttrs' = list: foldl' ( acc: elem: acc // { ${elem.name} = elem.value; }) {} list; +in [ + (listToAttrs input).result + (listToAttrs' input).result +] |