From 94380fdbd5a0a78c4b1abb8f43f18ebaf09c8b10 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 21 Apr 2017 03:21:06 +0100 Subject: [PATCH] ibb: Add some more tests. --- src/ibb.rs | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/ibb.rs b/src/ibb.rs index f77541c8..89aad820 100644 --- a/src/ibb.rs +++ b/src/ibb.rs @@ -7,7 +7,7 @@ use error::Error; use ns; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum Stanza { Iq, Message, @@ -35,9 +35,19 @@ impl FromStr for Stanza { #[derive(Debug, Clone)] pub enum IBB { - Open { block_size: u16, sid: String, stanza: Stanza }, - Data { seq: u16, sid: String, data: Vec }, - Close { sid: String }, + Open { + block_size: u16, + sid: String, + stanza: Stanza, + }, + Data { + seq: u16, + sid: String, + data: Vec, + }, + Close { + sid: String, + }, } fn optional_attr(root: &Element, attr: &str) -> Option { @@ -98,13 +108,35 @@ mod tests { #[test] fn test_simple() { let elem: Element = "".parse().unwrap(); - ibb::parse_ibb(&elem).unwrap(); + let open = ibb::parse_ibb(&elem).unwrap(); + match open { + ibb::IBB::Open { block_size, sid, stanza } => { + assert_eq!(block_size, 3); + assert_eq!(sid, "coucou"); + assert_eq!(stanza, ibb::Stanza::Iq); + }, + _ => panic!(), + } let elem: Element = "AAAA".parse().unwrap(); - ibb::parse_ibb(&elem).unwrap(); + let data = ibb::parse_ibb(&elem).unwrap(); + match data { + ibb::IBB::Data { seq, sid, data } => { + assert_eq!(seq, 0); + assert_eq!(sid, "coucou"); + assert_eq!(data, vec!(0, 0, 0)); + }, + _ => panic!(), + } let elem: Element = "".parse().unwrap(); - ibb::parse_ibb(&elem).unwrap(); + let close = ibb::parse_ibb(&elem).unwrap(); + match close { + ibb::IBB::Close { sid } => { + assert_eq!(sid, "coucou"); + }, + _ => panic!(), + } } #[test]