improve test

new-idea
Avril 4 years ago
parent 055039d2e0
commit 8a1ccd55d9
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,8 +1,8 @@
/// Default anonymous name /// Default anonymous name
pub const ANON_NAME: &'static str = "名無し"; pub const ANON_NAME: &'static str = "名無し";
/// Max length of `name` and `email` feilds in posts. /// Max length of `name` and `email` feilds in posts.
pub const POST_ID_MAX_LEN: usize = 32; pub const POST_ID_MAX_LEN: usize = 32;
/// The salt to use for tripcode hashes /// The salt to use for tripcode hashes
pub const TRIPCODE_SALT: khash::salt::Salt = khash::salt::Salt::internal(); pub const TRIPCODE_SALT: khash::salt::Salt = khash::salt::Salt::internal();
/// The tripcode algorithm to use /// The tripcode algorithm to use

@ -75,9 +75,10 @@ mod tests
#[test] #[test]
fn post_serialise() fn post_serialise()
{ {
use std::convert::TryInto;
let post = super::Post { let post = super::Post {
id: super::PostID::id_new(), id: super::PostID::id_new(),
name: None, name: Some("Some name".to_owned().try_into().unwrap()),
email: None, email: None,
tripcode: Some(super::Tripcode::generate("uhh hello").unwrap()), tripcode: Some(super::Tripcode::generate("uhh hello").unwrap()),
body: unsafe { super::PEMFormattedStr::new_unchecked("test").to_owned() }, //temporary body: unsafe { super::PEMFormattedStr::new_unchecked("test").to_owned() }, //temporary
@ -85,7 +86,7 @@ mod tests
hash: Default::default(), hash: Default::default(),
}; };
let post_json = serde_json::to_vec(&post).expect("Serialise"); let post_json = serde_json::to_vec(&post).expect("Serialise");
println!("Post json: {:?}", post_json); println!("Post json: {}", std::str::from_utf8(&post_json[..]).unwrap());
let post2: super::Post = serde_json::from_slice(&post_json[..]).expect("Deserialise"); let post2: super::Post = serde_json::from_slice(&post_json[..]).expect("Deserialise");
assert_eq!(post, post2); assert_eq!(post, post2);
println!("Post was: {:?}", post); println!("Post was: {:?}", post);

@ -20,7 +20,7 @@ impl Tripcode
khash::generate(&CONTEXT, from).map(Self) khash::generate(&CONTEXT, from).map(Self)
} }
/// Create a tripcode that *is* this string /// Create a tripcode that *is* this string
#[inline] pub fn from_string(string: String) -> Self #[inline] pub fn special(string: String) -> Self
{ {
Self(string) Self(string)
} }
@ -29,6 +29,11 @@ impl Tripcode
{ {
&self.0 &self.0
} }
/// Consume into regular string
#[inline] pub fn into_inner(self) -> String
{
self.0
}
} }
impl From<Tripcode> for String impl From<Tripcode> for String

Loading…
Cancel
Save