Implement 'receives: nothing' as Action::ReceiveNone
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
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:
parent
66a611fa6e
commit
efb69345d8
1 changed files with 20 additions and 2 deletions
22
src/lib.rs
22
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<Span, Token> {
|
|||
}
|
||||
|
||||
fn parse_action(s: Span) -> IResult<Span, Action> {
|
||||
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<Span, Action> {
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue