stanza_id: Use the new get_attr! macro to get attributes.
This commit is contained in:
parent
185bd79c72
commit
8c53d6e415
1 changed files with 4 additions and 10 deletions
|
@ -35,15 +35,9 @@ impl<'a> TryFrom<&'a Element> for StanzaId {
|
||||||
for _ in elem.children() {
|
for _ in elem.children() {
|
||||||
return Err(Error::ParseError("Unknown child in stanza-id or origin-id element."));
|
return Err(Error::ParseError("Unknown child in stanza-id or origin-id element."));
|
||||||
}
|
}
|
||||||
let id = match elem.attr("id") {
|
let id = get_attr!(elem, "id", required);
|
||||||
Some(id) => id.to_owned(),
|
|
||||||
None => return Err(Error::ParseError("No 'id' attribute present in stanza-id or origin-id.")),
|
|
||||||
};
|
|
||||||
Ok(if is_stanza_id {
|
Ok(if is_stanza_id {
|
||||||
let by = match elem.attr("by") {
|
let by = get_attr!(elem, "by", required);
|
||||||
Some(by) => by.parse().unwrap(),
|
|
||||||
None => return Err(Error::ParseError("No 'by' attribute present in stanza-id.")),
|
|
||||||
};
|
|
||||||
StanzaId::StanzaId { id, by }
|
StanzaId::StanzaId { id, by }
|
||||||
} else {
|
} else {
|
||||||
StanzaId::OriginId { id }
|
StanzaId::OriginId { id }
|
||||||
|
@ -115,7 +109,7 @@ mod tests {
|
||||||
Error::ParseError(string) => string,
|
Error::ParseError(string) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "No 'id' attribute present in stanza-id or origin-id.");
|
assert_eq!(message, "Required attribute 'id' missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -126,7 +120,7 @@ mod tests {
|
||||||
Error::ParseError(string) => string,
|
Error::ParseError(string) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "No 'by' attribute present in stanza-id.");
|
assert_eq!(message, "Required attribute 'by' missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue