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
|
#[macro_use]
extern crate quickcheck;
use rmpv::decode::read_value;
use rmpv::encode::write_value;
use rmpv::Value;
fn mirror_test<T: Clone>(xs: T) -> bool
where Value: From<T>
{
let mut buf = Vec::new();
write_value(&mut buf, &Value::from(xs.clone())).unwrap();
Value::from(xs) == read_value(&mut &buf[..]).unwrap()
}
quickcheck! {
fn mirror_uint(xs: u64) -> bool {
mirror_test(xs)
}
fn mirror_sint(xs: i64) -> bool {
mirror_test(xs)
}
fn mirror_f32_value(xs: f32) -> bool {
let mut buf = Vec::new();
write_value(&mut buf, &Value::from(xs)).unwrap();
let eq = Value::from(xs) == read_value(&mut &buf[..]).unwrap();
eq || (!eq && xs.is_nan())
}
fn mirror_f64_value(xs: f64) -> bool {
let mut buf = Vec::new();
write_value(&mut buf, &Value::from(xs)).unwrap();
let eq = Value::from(xs) == read_value(&mut &buf[..]).unwrap();
eq || (!eq && xs.is_nan())
}
fn mirror_str(xs: String) -> bool {
mirror_test(xs)
}
}
|