From 67e72b009e0e5b12c74c308e89bb415826e4f30d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 29 Jul 2017 04:39:50 +0100 Subject: [PATCH] disco: Fix serialisation of extensions, and add a test. --- src/disco.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/disco.rs b/src/disco.rs index f3fad62e..88e105ce 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -191,14 +191,12 @@ impl TryFrom for DiscoInfoResult { impl From for Element { fn from(disco: DiscoInfoResult) -> Element { - for _ in disco.extensions { - panic!("Not yet implemented!"); - } Element::builder("query") .ns(ns::DISCO_INFO) .attr("node", disco.node) .append(disco.identities) .append(disco.features) + .append(disco.extensions) .build() } } @@ -339,6 +337,21 @@ mod tests { assert!(query.extensions.is_empty()); } + #[test] + fn test_extension() { + let elem: Element = "example".parse().unwrap(); + let elem1 = elem.clone(); + let query = DiscoInfoResult::try_from(elem).unwrap(); + assert!(query.node.is_none()); + assert_eq!(query.identities.len(), 1); + assert_eq!(query.features.len(), 1); + assert_eq!(query.extensions.len(), 1); + assert_eq!(query.extensions[0].form_type, Some(String::from("example"))); + + let elem2 = query.into(); + assert_eq!(elem1, elem2); + } + #[test] fn test_invalid() { let elem: Element = "".parse().unwrap();