From f8b380672043e9b870c4303ce47205a1435de8ee Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 17 Sep 2022 14:14:33 -0400 Subject: test(tvix/eval): impl Arbitrary for Value Impl Arbitrary for Value (and NixAttrs and NixList) in the same way we did for NixString. Value currently only generates non-"internal" values (no thunks, AttrNotFound, etc.) and can't generate functions (builtins or closures), because those'd require full generation of tvix bytecode, which is a bit more work than I'd like to do now - there's a `todo!` left in the code for a place where we could allow opting-in to internal values and functions later. Change-Id: I07a59e2b1d89cfaa912d4ecebd642caf4ddb040a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6627 Autosubmit: grfn Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/value/list.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tvix/eval/src/value/list.rs') diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs index c00ddd4191ea..19415c0d557f 100644 --- a/tvix/eval/src/value/list.rs +++ b/tvix/eval/src/value/list.rs @@ -20,6 +20,25 @@ impl Display for NixList { } } +#[cfg(feature = "arbitrary")] +mod arbitrary { + use proptest::{ + prelude::{any_with, Arbitrary}, + strategy::{BoxedStrategy, Strategy}, + }; + + use super::*; + + impl Arbitrary for NixList { + type Parameters = as Arbitrary>::Parameters; + type Strategy = BoxedStrategy; + + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + any_with::>(args).prop_map(Self).boxed() + } + } +} + impl NixList { pub fn concat(&self, other: &Self) -> Self { let mut lhs = self.clone(); -- cgit 1.4.1