Implement 'receives: nothing' as Action::ReceiveNone
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-01-14 12:26:41 +01:00
parent 66a611fa6e
commit efb69345d8
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -101,6 +101,7 @@ pub enum Action {
Connect(ClientName), Connect(ClientName),
Send(ClientName, Element), Send(ClientName, Element),
Receive(ClientName, Element), Receive(ClientName, Element),
ReceiveNone(ClientName),
Disconnect(ClientName), Disconnect(ClientName),
} }
@ -262,12 +263,21 @@ fn parse_sep(s: Span) -> IResult<Span, Token> {
} }
fn parse_action(s: Span) -> IResult<Span, Action> { fn parse_action(s: Span) -> IResult<Span, Action> {
let (s, name) = let (s, name) = take_until_tags(
take_until_tags(vec!["disconnects", "connects", "sends:", "receives:"].into_iter())(s)?; vec![
"disconnects",
"connects",
"receives: nothing",
"sends:",
"receives:",
]
.into_iter(),
)(s)?;
let (s, (tagname, _, _)) = tuple(( let (s, (tagname, _, _)) = tuple((
alt(( alt((
tag("connects"), tag("connects"),
tag("disconnects"), tag("disconnects"),
tag("receives: nothing"),
tag("sends:"), tag("sends:"),
tag("receives:"), tag("receives:"),
)), )),
@ -279,6 +289,7 @@ fn parse_action(s: Span) -> IResult<Span, Action> {
let (s, action) = match *tagname.fragment() { let (s, action) = match *tagname.fragment() {
"connects" => (s, Action::Connect(name)), "connects" => (s, Action::Connect(name)),
"disconnects" => (s, Action::Disconnect(name)), "disconnects" => (s, Action::Disconnect(name)),
"receives: nothing" => (s, Action::ReceiveNone(name)),
tagname @ "sends:" | tagname @ "receives:" => parse_send_receive(tagname, name, s)?, tagname @ "sends:" | tagname @ "receives:" => parse_send_receive(tagname, name, s)?,
_ => unreachable!(), _ => unreachable!(),
}; };
@ -564,6 +575,13 @@ mod tests {
assert_eq!(parse_action(buf.into()).unwrap().1, receive); 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] #[test]
fn test_parse_spec() { fn test_parse_spec() {
let buf = r#"# Test title let buf = r#"# Test title