xmpp-parsers: Convert disco#info identity to xso
This commit is contained in:
parent
2690e62060
commit
6b167ed677
1 changed files with 35 additions and 31 deletions
|
|
@ -46,25 +46,28 @@ impl Feature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_element!(
|
/// Structure representing an `<identity xmlns='http://jabber.org/protocol/disco#info'/>` element.
|
||||||
/// Structure representing an `<identity xmlns='http://jabber.org/protocol/disco#info'/>` element.
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
Identity, "identity", DISCO_INFO,
|
#[xml(namespace = ns::DISCO_INFO, name = "identity")]
|
||||||
attributes: [
|
pub struct Identity {
|
||||||
/// Category of this identity.
|
/// Category of this identity.
|
||||||
// TODO: use an enum here.
|
// TODO: use an enum here.
|
||||||
category: RequiredNonEmpty<String> = "category",
|
#[xml(attribute)]
|
||||||
|
pub category: String,
|
||||||
|
|
||||||
/// Type of this identity.
|
/// Type of this identity.
|
||||||
// TODO: use an enum here.
|
// TODO: use an enum here.
|
||||||
type_: RequiredNonEmpty<String> = "type",
|
#[xml(attribute = "type")]
|
||||||
|
pub type_: String,
|
||||||
|
|
||||||
/// Lang of the name of this identity.
|
/// Lang of the name of this identity.
|
||||||
lang: Option<String> = "xml:lang",
|
#[xml(attribute(default, name = "xml:lang"))]
|
||||||
|
pub lang: Option<String>,
|
||||||
|
|
||||||
/// Name of this identity.
|
/// Name of this identity.
|
||||||
name: Option<String> = "name",
|
#[xml(attribute(default))]
|
||||||
]
|
pub name: Option<String>,
|
||||||
);
|
}
|
||||||
|
|
||||||
impl Identity {
|
impl Identity {
|
||||||
/// Create a new `<identity/>`.
|
/// Create a new `<identity/>`.
|
||||||
|
|
@ -342,10 +345,13 @@ mod tests {
|
||||||
FromElementError::Invalid(Error::Other(string)) => string,
|
FromElementError::Invalid(Error::Other(string)) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "Required attribute 'category' missing.");
|
assert_eq!(
|
||||||
|
message,
|
||||||
|
"Required attribute field 'category' on Identity element missing."
|
||||||
|
);
|
||||||
|
|
||||||
let elem: Element =
|
let elem: Element =
|
||||||
"<query xmlns='http://jabber.org/protocol/disco#info'><identity category=''/></query>"
|
"<query xmlns='http://jabber.org/protocol/disco#info'><identity type='coucou'/></query>"
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let error = DiscoInfoResult::try_from(elem).unwrap_err();
|
let error = DiscoInfoResult::try_from(elem).unwrap_err();
|
||||||
|
|
@ -353,7 +359,10 @@ mod tests {
|
||||||
FromElementError::Invalid(Error::Other(string)) => string,
|
FromElementError::Invalid(Error::Other(string)) => string,
|
||||||
_ => panic!(),
|
_ => 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 = "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='coucou'/></query>".parse().unwrap();
|
let elem: Element = "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='coucou'/></query>".parse().unwrap();
|
||||||
let error = DiscoInfoResult::try_from(elem).unwrap_err();
|
let error = DiscoInfoResult::try_from(elem).unwrap_err();
|
||||||
|
|
@ -361,15 +370,10 @@ mod tests {
|
||||||
FromElementError::Invalid(Error::Other(string)) => string,
|
FromElementError::Invalid(Error::Other(string)) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "Required attribute 'type' missing.");
|
assert_eq!(
|
||||||
|
message,
|
||||||
let elem: Element = "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='coucou' type=''/></query>".parse().unwrap();
|
"Required attribute field 'type_' on Identity element missing."
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue