Actions are parsed until the end of the line only
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
12299c5898
commit
7314127763
1 changed files with 31 additions and 2 deletions
33
src/lib.rs
33
src/lib.rs
|
@ -138,7 +138,10 @@ fn comment(s: Span) -> IResult<Span, Token> {
|
|||
Ok((s, Token { position: pos }))
|
||||
}
|
||||
|
||||
fn take_until_tags<T, I, E: ParseError<I>, List>(list: List) -> impl Fn(I) -> IResult<I, I, E>
|
||||
fn take_until_tags<T, I, E: ParseError<I>, List>(
|
||||
list: List,
|
||||
endmark: T,
|
||||
) -> impl Fn(I) -> IResult<I, I, E>
|
||||
where
|
||||
I: InputTake + FindSubstring<T>,
|
||||
T: InputLength + Clone,
|
||||
|
@ -146,11 +149,19 @@ where
|
|||
{
|
||||
move |i: I| {
|
||||
let mut l = list.clone();
|
||||
let endmark = endmark.clone();
|
||||
let endindex = match i.find_substring(endmark) {
|
||||
None | Some(0) => {
|
||||
return Err(nom::Err::Error(E::from_error_kind(i, ErrorKind::TakeUntil)))
|
||||
}
|
||||
Some(index) => index,
|
||||
};
|
||||
let res: Option<usize> = loop {
|
||||
if let Some(item) = l.next() {
|
||||
match i.find_substring(item) {
|
||||
None | Some(0) => continue,
|
||||
valid @ Some(_) => break valid,
|
||||
Some(index) if index >= endindex => continue,
|
||||
valid => break valid,
|
||||
}
|
||||
} else {
|
||||
break None;
|
||||
|
@ -273,6 +284,7 @@ fn parse_action(s: Span) -> IResult<Span, Action> {
|
|||
"receives:",
|
||||
]
|
||||
.into_iter(),
|
||||
"\n",
|
||||
)(s)?;
|
||||
let (s, (tagname, _, _)) = tuple((
|
||||
alt((
|
||||
|
@ -575,6 +587,23 @@ mod tests {
|
|||
assert_eq!(parse_action(buf.into()).unwrap().1, receive);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_actions_take_until() {
|
||||
let buf = "Rosa receives:\n\t<presence/>\n\n\n# Comment\n\nPeter sends:\n\t<presence/>\n";
|
||||
let xml = b"<presence/>";
|
||||
let actions = vec![
|
||||
Action::Receive(
|
||||
String::from("Rosa"),
|
||||
Element::from_reader_with_prefixes(&xml[..], String::from(DEFAULT_NS)).unwrap(),
|
||||
),
|
||||
Action::Send(
|
||||
String::from("Peter"),
|
||||
Element::from_reader_with_prefixes(&xml[..], String::from(DEFAULT_NS)).unwrap(),
|
||||
),
|
||||
];
|
||||
assert_eq!(parse_actions(buf.into()).unwrap().1, actions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_action_receive_none() {
|
||||
let buf = "rosa receives: nothing\n";
|
||||
|
|
Loading…
Reference in a new issue