From efb69345d8a36cd60635f3055712134fa4bcc249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 14 Jan 2023 12:26:41 +0100 Subject: [PATCH] Implement 'receives: nothing' as Action::ReceiveNone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/lib.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e6fe84..ab2a6a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,6 +101,7 @@ pub enum Action { Connect(ClientName), Send(ClientName, Element), Receive(ClientName, Element), + ReceiveNone(ClientName), Disconnect(ClientName), } @@ -262,12 +263,21 @@ fn parse_sep(s: Span) -> IResult { } fn parse_action(s: Span) -> IResult { - let (s, name) = - take_until_tags(vec!["disconnects", "connects", "sends:", "receives:"].into_iter())(s)?; + let (s, name) = take_until_tags( + vec![ + "disconnects", + "connects", + "receives: nothing", + "sends:", + "receives:", + ] + .into_iter(), + )(s)?; let (s, (tagname, _, _)) = tuple(( alt(( tag("connects"), tag("disconnects"), + tag("receives: nothing"), tag("sends:"), tag("receives:"), )), @@ -279,6 +289,7 @@ fn parse_action(s: Span) -> IResult { let (s, action) = match *tagname.fragment() { "connects" => (s, Action::Connect(name)), "disconnects" => (s, Action::Disconnect(name)), + "receives: nothing" => (s, Action::ReceiveNone(name)), tagname @ "sends:" | tagname @ "receives:" => parse_send_receive(tagname, name, s)?, _ => unreachable!(), }; @@ -564,6 +575,13 @@ mod tests { assert_eq!(parse_action(buf.into()).unwrap().1, receive); } + #[test] + fn test_action_receive_none() { + let buf = "rosa receives: nothing\n"; + let receive = Action::ReceiveNone(String::from("rosa")); + assert_eq!(parse_action(buf.into()).unwrap().1, receive); + } + #[test] fn test_parse_spec() { let buf = r#"# Test title