summaryrefslogtreecommitdiffstats
path: root/library/portable-simd/crates/test_helpers/src/wasm.rs
blob: 3f11d67cbf390bea2a93daaacaada98761e0a858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Strategies for `u128` and `i128`, since proptest doesn't provide them for the wasm target.

macro_rules! impl_num {
    { $name:ident } => {
        pub(crate) mod $name {
            type InnerStrategy = crate::array::UniformArrayStrategy<proptest::num::u64::Any, [u64; 2]>;
            use proptest::strategy::{Strategy, ValueTree, NewTree};


            #[must_use = "strategies do nothing unless used"]
            #[derive(Clone, Copy, Debug)]
            pub struct Any {
                strategy: InnerStrategy,
            }

            pub struct BinarySearch {
                inner: <InnerStrategy as Strategy>::Tree,
            }

            impl ValueTree for BinarySearch {
                type Value = $name;

                fn current(&self) -> $name {
                    unsafe { core::mem::transmute(self.inner.current()) }
                }

                fn simplify(&mut self) -> bool {
                    self.inner.simplify()
                }

                fn complicate(&mut self) -> bool {
                    self.inner.complicate()
                }
            }

            impl Strategy for Any {
                type Tree = BinarySearch;
                type Value = $name;

                fn new_tree(&self, runner: &mut proptest::test_runner::TestRunner) -> NewTree<Self> {
                    Ok(BinarySearch { inner: self.strategy.new_tree(runner)? })
                }
            }

            pub const ANY: Any = Any { strategy: InnerStrategy::new(proptest::num::u64::ANY) };
        }
    }
}

impl_num! { u128 }
impl_num! { i128 }