#![allow(clippy::unused_unit)] use diff::Diff; use quickcheck::quickcheck; use quickcheck_derive::Arbitrary; use std::collections::{BTreeMap, HashMap}; use std::sync::Arc; #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct Unit; #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct Basic { pub items: HashMap>, pub items_b: BTreeMap>, pub tuple: (u32, u16), pub arc: Arc, pub unit: Unit, } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub enum Enum { VarUnit, VarNamed { a: u32, b: u32 }, VarUnnamed(u32, Basic), } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct NamedGenerics { pub a: A, pub b: B, } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct UnnamedGenerics(A, B); #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub enum EnumGenerics where A: PartialEq, B: PartialEq, { Named { a: A, b: B }, Unnamed(A, B), } pub trait Bound1 {} pub trait Bound2 {} impl Bound1 for u32 {} impl Bound2 for u32 {} #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct NamedGenericsBoundsInternal { pub a: A, pub b: B, } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct NamedGenericsBoundsExternal where A: Bound1 + Bound2, { pub a: A, pub b: B, } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct NamedGenericsBoundsMixed where A: Bound2, { pub a: A, pub b: B, } #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct UnnamedGenericsBoundsInternal(A, B); #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct UnnamedGenericsBoundsExternal(A, B) where A: Bound1 + Bound2; #[derive(Clone, Arbitrary, Diff, Eq, PartialEq, Debug)] pub struct UnnamedGenericsBoundsMixed(A, B) where A: Bound2; fn tester(mut a: T, b: T) -> bool where T: Diff + Eq, { let diff = a.diff(&b); a.apply(&diff); a == b } #[test] fn test_basic() { quickcheck(tester as fn(Basic, Basic) -> bool); } #[test] fn test_named_generics() { quickcheck(tester as fn(NamedGenerics, NamedGenerics) -> bool); } #[test] fn test_unnamed_generics() { quickcheck(tester as fn(UnnamedGenerics, UnnamedGenerics) -> bool); } #[test] fn test_enum_generics() { quickcheck(tester as fn(EnumGenerics, EnumGenerics) -> bool); } #[test] fn test_enum() { quickcheck(tester as fn(Enum, Enum) -> bool); } #[test] fn test_named_generics_bounds_internal() { quickcheck( tester as fn( NamedGenericsBoundsInternal, NamedGenericsBoundsInternal, ) -> bool, ); } #[test] fn test_named_generics_bounds_external() { quickcheck( tester as fn( NamedGenericsBoundsExternal, NamedGenericsBoundsExternal, ) -> bool, ); } #[test] fn test_named_generics_bounds_mixed() { quickcheck( tester as fn(NamedGenericsBoundsMixed, NamedGenericsBoundsMixed) -> bool, ); } #[test] fn test_unnamed_generics_bounds_internal() { quickcheck( tester as fn( UnnamedGenericsBoundsInternal, UnnamedGenericsBoundsInternal, ) -> bool, ); } #[test] fn test_unnamed_generics_bounds_external() { quickcheck( tester as fn( UnnamedGenericsBoundsExternal, UnnamedGenericsBoundsExternal, ) -> bool, ); } #[test] fn test_unnamed_generics_bounds_mixed() { quickcheck( tester as fn( UnnamedGenericsBoundsMixed, UnnamedGenericsBoundsMixed, ) -> bool, ); }