From 5ab86ab8dcb59b5f63daa5ec869c8c6cbf97a458 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 2 Dec 2022 09:32:13 +0100 Subject: test(tvix/eval): add a test for repeated keys in listToAttrs 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 Autosubmit: tazjin Tested-by: BuildkiteCI --- .../tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp | 1 + .../tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix 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 0000000000..b4a1e66d6b --- /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 0000000000..2f719dcef5 --- /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 +] -- cgit 1.4.1