1 //! Arbitrarily choose a spec test from the list of known spec tests.
2 
3 use arbitrary::{Arbitrary, Unstructured};
4 
5 // See `build.rs` for how the `FILES` array is generated.
6 include!(concat!(env!("OUT_DIR"), "/wasttests.rs"));
7 
8 /// A wast test from this repository.
9 #[derive(Debug)]
10 pub struct WastTest {
11     /// The filename of the spec test
12     pub file: &'static str,
13     /// The `*.wast` contents of the spec test
14     pub contents: &'static str,
15 }
16 
17 impl<'a> Arbitrary<'a> for WastTest {
18     fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
19         // NB: this does get a uniform value in the provided range.
20         let i = u.int_in_range(0..=FILES.len() - 1)?;
21         let (file, contents) = FILES[i];
22         Ok(WastTest { file, contents })
23     }
24 
25     fn size_hint(_depth: usize) -> (usize, Option<usize>) {
26         (1, Some(std::mem::size_of::<usize>()))
27     }
28 }
29