Radish alpha
r
rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt
Git libraries for Radicle
Radicle
Git
radicle-git test test-helpers src roundtrip.rs
use std::{
    fmt::{Debug, Display},
    str::FromStr,
};

use pretty_assertions::assert_eq;

pub fn json<A>(a: A)
where
    for<'de> A: Debug + PartialEq + serde::Serialize + serde::Deserialize<'de>,
{
    assert_eq!(
        a,
        serde_json::from_str(&serde_json::to_string(&a).unwrap()).unwrap()
    )
}

pub fn json_value<A>(a: A)
where
    for<'de> A: Clone + Debug + PartialEq + serde::Serialize + serde::Deserialize<'de>,
{
    assert_eq!(
        a.clone(),
        serde_json::from_value(serde_json::to_value(a).unwrap()).unwrap()
    )
}

pub fn cbor<A>(a: A)
where
    for<'de> A: Debug + PartialEq + minicbor::Encode + minicbor::Decode<'de>,
{
    assert_eq!(a, minicbor::decode(&minicbor::to_vec(&a).unwrap()).unwrap())
}

pub fn str<A>(a: A)
where
    A: Debug + PartialEq + Display + FromStr,
    <A as FromStr>::Err: Debug,
{
    assert_eq!(a, a.to_string().parse().unwrap())
}