Parse Action::Connect
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-01-08 20:05:41 +01:00
parent 4a1dc94a41
commit 71da176728
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -92,15 +92,30 @@ fn parse_accounts(i: &str) -> IResult<&str, HashMap<AccountName, Account>> {
Ok((i, map))
}
fn parse_actions(i: &str) -> IResult<&str, Vec<Action>> {
Ok((i, Vec::new()))
}
fn parse_sep(i: &str) -> IResult<&str, &str> {
let (i, _) = delimited(allspaces, many1(tag("-")), allspaces)(i)?;
Ok((i, ""))
}
fn parse_connect(i: &str) -> IResult<&str, Action> {
let (i, (name, _, _)) = tuple((take_while1(is_not_space), space1, tag("connects\n")))(i)?;
Ok((i, Action::Connect(String::from(name))))
}
fn parse_action(i: &str) -> IResult<&str, Action> {
delimited(
allspaces,
parse_connect,
allspaces,
)(i)
}
fn parse_actions(i: &str) -> IResult<&str, Vec<Action>> {
let (i, actions) = many1(parse_action)(i)?;
Ok((i, actions))
}
pub fn parse_spec(i: &str) -> Result<Spec, nom::Err<nom::error::Error<&str>>> {
let (i, accounts) = parse_accounts(i)?;
let (i, _) = parse_sep(i)?;
@ -214,4 +229,33 @@ mod tests {
);
assert_eq!(parse_accounts(buf1), Ok(("", accounts)));
}
#[test]
fn test_action_connect() {
let buf1 = r#"
[Client] louise
jid: louise@localhost
password: password
[Client] rosa
jid: rosa@localhost
password: password
------
louise connects
rosa connects
"#;
let mut accounts: HashMap<AccountName, Account> = HashMap::new();
accounts.insert(String::from("louise"), get_account("louise"));
accounts.insert(String::from("rosa"), get_account("rosa"));
let actions = vec![
Action::Connect(String::from("louise")),
Action::Connect(String::from("rosa")),
];
let spec = Spec { accounts, actions };
assert_eq!(parse_spec(buf1), Ok(spec));
}
}