diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs index 16a3b9cb98f0705493c9d5012a44c83bb6098738..97bf713c6d3f94581ee2f08a044f2865c2c94cc1 100644 --- a/parsers/src/disco.rs +++ b/parsers/src/disco.rs @@ -46,25 +46,28 @@ impl Feature { } } -generate_element!( - /// Structure representing an `` element. - Identity, "identity", DISCO_INFO, - attributes: [ - /// Category of this identity. - // TODO: use an enum here. - category: RequiredNonEmpty = "category", - - /// Type of this identity. - // TODO: use an enum here. - type_: RequiredNonEmpty = "type", - - /// Lang of the name of this identity. - lang: Option = "xml:lang", - - /// Name of this identity. - name: Option = "name", - ] -); +/// Structure representing an `` element. +#[derive(FromXml, AsXml, Debug, Clone, PartialEq, Eq, Hash)] +#[xml(namespace = ns::DISCO_INFO, name = "identity")] +pub struct Identity { + /// Category of this identity. + // TODO: use an enum here. + #[xml(attribute)] + pub category: String, + + /// Type of this identity. + // TODO: use an enum here. + #[xml(attribute = "type")] + pub type_: String, + + /// Lang of the name of this identity. + #[xml(attribute(default, name = "xml:lang"))] + pub lang: Option, + + /// Name of this identity. + #[xml(attribute(default))] + pub name: Option, +} impl Identity { /// Create a new ``. @@ -342,10 +345,13 @@ mod tests { FromElementError::Invalid(Error::Other(string)) => string, _ => panic!(), }; - assert_eq!(message, "Required attribute 'category' missing."); + assert_eq!( + message, + "Required attribute field 'category' on Identity element missing." + ); let elem: Element = - "" + "" .parse() .unwrap(); let error = DiscoInfoResult::try_from(elem).unwrap_err(); @@ -353,7 +359,10 @@ mod tests { FromElementError::Invalid(Error::Other(string)) => string, _ => panic!(), }; - assert_eq!(message, "Required attribute 'category' must not be empty."); + assert_eq!( + message, + "Required attribute field 'category' on Identity element missing." + ); let elem: Element = "".parse().unwrap(); let error = DiscoInfoResult::try_from(elem).unwrap_err(); @@ -361,15 +370,10 @@ mod tests { FromElementError::Invalid(Error::Other(string)) => string, _ => panic!(), }; - assert_eq!(message, "Required attribute 'type' missing."); - - let elem: Element = "".parse().unwrap(); - let error = DiscoInfoResult::try_from(elem).unwrap_err(); - let message = match error { - FromElementError::Invalid(Error::Other(string)) => string, - _ => panic!(), - }; - assert_eq!(message, "Required attribute 'type' must not be empty."); + assert_eq!( + message, + "Required attribute field 'type_' on Identity element missing." + ); } #[test]