about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-09-17T19·08-0400
committerclbot <clbot@tvl.fyi>2022-09-17T19·51+0000
commit51f1924f196761f041970b32456af49fc5d7b1ee (patch)
tree501714fc09e6bc98057d4aac8b6c878aade59ba3
parente6fe7b1687cfb59518393a9d615ada04bee51a5e (diff)
test(tvix/eval): Test StringRepr::Smol as well r/4893
The From<String> impl for NixString only generates StringRepr::Heap
strings, but we want to make sure we're testing StringRepr::Smol too

Change-Id: I6d04b9cf12ef8462fe2788e0c6414b165f40311d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6629
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/value/string.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs
index 9ac8869935f2..20564653433d 100644
--- a/tvix/eval/src/value/string.rs
+++ b/tvix/eval/src/value/string.rs
@@ -62,6 +62,7 @@ impl Hash for NixString {
 mod arbitrary {
     use super::*;
     use proptest::prelude::{any_with, Arbitrary};
+    use proptest::prop_oneof;
     use proptest::strategy::{BoxedStrategy, Strategy};
 
     impl Arbitrary for NixString {
@@ -70,7 +71,13 @@ mod arbitrary {
         type Strategy = BoxedStrategy<Self>;
 
         fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
-            any_with::<String>(args).prop_map(Self::from).boxed()
+            prop_oneof![
+                // Either generate `StringRepr::Heap`...
+                any_with::<String>(args).prop_map(Self::from),
+                // ...or generate `StringRepr::Smol` (which `impl From<&str> for NixString` returns)
+                any_with::<String>(args).prop_map(|s| Self::from(s.as_str())),
+            ]
+            .boxed()
         }
     }
 }