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 <sternenseemann@systemli.org> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									b9e3db35b2
								
							
						
					
					
						commit
						5ab86ab8dc
					
				
					 2 changed files with 14 additions and 0 deletions
				
			
		| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					[ 1 2 ]
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue