parse_receive now correctly returns Action::Receive

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-01-09 18:13:10 +01:00
parent 413e1b4560
commit 22f12b2b10
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -116,7 +116,7 @@ fn parse_action_line(i: &str) -> IResult<&str, &str> {
Ok((i, line))
}
fn parse_send_receive(tagname: &str) -> impl Fn(&str) -> IResult<&str, Action> + '_ {
fn parse_send_receive(tagname: &str) -> impl Fn(&str) -> IResult<&str, (String, Element)> + '_ {
move |i: &str| {
let (i , (name, _, _, _, lines)) = tuple((
take_while1(is_not_space),
@ -132,18 +132,18 @@ fn parse_send_receive(tagname: &str) -> impl Fn(&str) -> IResult<&str, Action> +
&lines.as_bytes()[..],
String::from(DEFAULT_NS),
).unwrap();
Ok((i, Action::Send(String::from(name), elem)))
Ok((i, (String::from(name), elem)))
}
}
fn parse_send(i: &str) -> IResult<&str, Action> {
let (i, action) = parse_send_receive("sends:")(i)?;
Ok((i, action))
let (i, (name, elem)) = parse_send_receive("sends:")(i)?;
Ok((i, Action::Send(name, elem)))
}
fn parse_receive(i: &str) -> IResult<&str, Action> {
let (i, action) = parse_send_receive("receives::")(i)?;
Ok((i, action))
let (i, (name, elem)) = parse_send_receive("receives:")(i)?;
Ok((i, Action::Receive(name, elem)))
}
fn parse_action(i: &str) -> IResult<&str, Action> {
@ -290,17 +290,16 @@ mod tests {
/>
"#;
let xml = b"<presence\n\t\ttype=\"unavailable\"\t\n/>";
let action = Action::Send(
let send = Action::Send(
String::from("rosa"),
Element::from_reader_with_prefixes(
&xml[..],
String::from(DEFAULT_NS),
).unwrap(),
);
assert_eq!(parse_send_receive("sends:")(buf).unwrap().1, action);
assert_eq!(parse_send(buf).unwrap().1, send);
let buf2 = r#"rosa receives:
@ -309,6 +308,13 @@ mod tests {
/>
"#;
assert_eq!(parse_send_receive("receives:")(buf2).unwrap().1, action);
let receive = Action::Receive(
String::from("rosa"),
Element::from_reader_with_prefixes(
&xml[..],
String::from(DEFAULT_NS),
).unwrap(),
);
assert_eq!(parse_receive(buf2).unwrap().1, receive);
}
}