diff --git a/src/roster.rs b/src/roster.rs index f38817d0..db939ad8 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -65,7 +65,7 @@ impl Into for Item { .attr("jid", String::from(self.jid)) .attr("name", self.name) .attr("subscription", self.subscription) - .append(self.groups) + .append(self.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::>()) .build() } } @@ -172,6 +172,29 @@ mod tests { assert_eq!(roster.items[0].groups, vec!(String::from("Friends"))); } + #[test] + fn test_multiple_groups() { + let elem: Element = r#" + + + A + B + + +"#.parse().unwrap(); + let elem1 = elem.clone(); + let roster = Roster::try_from(elem).unwrap(); + assert!(roster.ver.is_none()); + assert_eq!(roster.items.len(), 1); + assert_eq!(roster.items[0].jid, Jid::from_str("test@example.org").unwrap()); + assert_eq!(roster.items[0].name, None); + assert_eq!(roster.items[0].groups.len(), 2); + assert_eq!(roster.items[0].groups[0], String::from("A")); + assert_eq!(roster.items[0].groups[1], String::from("B")); + let elem2 = roster.into(); + assert_eq!(elem1, elem2); + } + #[test] fn test_set() { let elem: Element = "".parse().unwrap(); @@ -186,7 +209,6 @@ mod tests { Servants - "#.parse().unwrap(); let roster = Roster::try_from(elem).unwrap(); assert!(roster.ver.is_none());