use std::fmt::Debug; use serde::Deserialize; use clauser::de::from_str; use clauser::error::{Error, ErrorType}; #[derive(Deserialize, Debug, PartialEq)] pub struct SingleContainer { pub val: T, } impl<'a, T: Debug + PartialEq> SingleContainer where T: Deserialize<'a>, { pub fn new(val: T) -> SingleContainer { SingleContainer { val } } pub fn expect(text: &'a str, expected: T) -> Result<(), Error> { assert_eq!(from_str::>(text)?.val, expected); Ok(()) } } pub fn expect_str<'a, T: Debug + PartialEq>(text: &'a str, expected: T) -> Result<(), Error> where T: Deserialize<'a>, { assert_eq!(from_str::(text)?, expected); Ok(()) } pub fn expect_error Deserialize<'a> + std::fmt::Debug>( source: &str, expected_error: ErrorType, ) -> Result<(), Error> { let result = from_str::(source); assert!( result.is_err(), "expected error {:?} but got result {:?}", expected_error, result.unwrap() ); match result { Ok(_) => Ok(()), Err(e) => match e.error_type == expected_error { true => Ok(()), false => Err(e), }, } }