Fix wasm tests

This commit is contained in:
Caleb Zulawski 2021-02-13 11:40:10 -05:00
parent 8d5702e437
commit 976fafcf4f
7 changed files with 100 additions and 19 deletions

View File

@ -143,7 +143,7 @@ macro_rules! impl_vector {
impl <const LANES: usize> From<$name<LANES>> for [$type; LANES] {
fn from(vector: $name<LANES>) -> Self {
vector.0
vector.to_array()
}
}

View File

@ -1,6 +1,3 @@
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
macro_rules! impl_op_test {
{ unary, $vector:ty, $scalar:ty, $trait:ident :: $fn:ident } => {
test_helpers::test_lanes! {

View File

@ -1,6 +1,3 @@
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
macro_rules! impl_unary_op_test {
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
test_helpers::test_lanes! {

View File

@ -5,5 +5,7 @@ authors = ["Caleb Zulawski <caleb.zulawski@gmail.com>"]
edition = "2018"
publish = false
[dependencies]
proptest = "0.10"
[dependencies.proptest]
version = "0.10"
default-features = false
features = ["alloc"]

View File

@ -18,7 +18,7 @@ pub struct UniformArrayStrategy<S, T> {
}
impl<S, T> UniformArrayStrategy<S, T> {
pub fn new(strategy: S) -> Self {
pub const fn new(strategy: S) -> Self {
Self {
strategy,
_marker: PhantomData,

View File

@ -1,5 +1,8 @@
pub mod array;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
#[macro_use]
pub mod biteq;
@ -23,17 +26,47 @@ impl_num! { i8 }
impl_num! { i16 }
impl_num! { i32 }
impl_num! { i64 }
impl_num! { i128 }
impl_num! { isize }
impl_num! { u8 }
impl_num! { u16 }
impl_num! { u32 }
impl_num! { u64 }
impl_num! { u128 }
impl_num! { usize }
impl_num! { f32 }
impl_num! { f64 }
#[cfg(not(target_arch = "wasm32"))]
impl DefaultStrategy for u128 {
type Strategy = proptest::num::u128::Any;
fn default_strategy() -> Self::Strategy {
proptest::num::u128::ANY
}
}
#[cfg(not(target_arch = "wasm32"))]
impl DefaultStrategy for i128 {
type Strategy = proptest::num::i128::Any;
fn default_strategy() -> Self::Strategy {
proptest::num::i128::ANY
}
}
#[cfg(target_arch = "wasm32")]
impl DefaultStrategy for u128 {
type Strategy = crate::wasm::u128::Any;
fn default_strategy() -> Self::Strategy {
crate::wasm::u128::ANY
}
}
#[cfg(target_arch = "wasm32")]
impl DefaultStrategy for i128 {
type Strategy = crate::wasm::i128::Any;
fn default_strategy() -> Self::Strategy {
crate::wasm::i128::ANY
}
}
impl<T: core::fmt::Debug + DefaultStrategy, const LANES: usize> DefaultStrategy for [T; LANES] {
type Strategy = crate::array::UniformArrayStrategy<T::Strategy, Self>;
fn default_strategy() -> Self::Strategy {
@ -200,44 +233,47 @@ macro_rules! test_lanes {
fn implementation<const $lanes: usize>() $body
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_1() {
implementation::<1>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_2() {
implementation::<2>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_4() {
implementation::<4>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_8() {
implementation::<8>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_16() {
implementation::<16>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_32() {
implementation::<32>();
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn lanes_64() {
implementation::<64>();
}

View File

@ -0,0 +1,49 @@
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 }