Skip to content

Commit

Permalink
Don't consume list separator prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
evestera authored and Geal committed May 10, 2016
1 parent 5f9c928 commit d42cf5c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1887,11 +1887,10 @@ macro_rules! separated_list(
if i2.len() == input.len() {
break;
}
input = i2;

// get the element next
if let $crate::IResult::Done(i3,o3) = $submac!(input, $($args2)*) {
if i3.len() == input.len() {
if let $crate::IResult::Done(i3,o3) = $submac!(i2, $($args2)*) {
if i3.len() == i2.len() {
break;
}
res.push(o3);
Expand Down Expand Up @@ -1945,10 +1944,9 @@ macro_rules! separated_nonempty_list(
if i2.len() == input.len() {
break;
}
input = i2;

if let $crate::IResult::Done(i3,o3) = $submac!(input, $($args2)*) {
if i3.len() == input.len() {
if let $crate::IResult::Done(i3,o3) = $submac!(i2, $($args2)*) {
if i3.len() == i2.len() {
break;
}
res.push(o3);
Expand Down Expand Up @@ -2299,7 +2297,7 @@ macro_rules! count_fixed (
if cnt == $count {
ret = $crate::IResult::Done(input, res); break;
}

match $submac!(input, $($args)*) {
$crate::IResult::Done(i,o) => {
res[cnt] = o;
Expand Down Expand Up @@ -3206,13 +3204,18 @@ mod tests {
let b = &b"abcd,abcdef"[..];
let c = &b"azerty"[..];
let d = &b",,abc"[..];
let e = &b"abcd,abcd,ef"[..];

let res1 = vec![&b"abcd"[..]];
assert_eq!(multi(a), Done(&b"ef"[..], res1));
let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
assert_eq!(multi(b), Done(&b"ef"[..], res2));
assert_eq!(multi(c), Done(&b"azerty"[..], Vec::new()));
assert_eq!(multi_empty(d), Error(Position(ErrorKind::SeparatedList, d)));
let res3 = vec![&b""[..], &b""[..], &b""[..]];
//assert_eq!(multi_empty(d), Done(&b"abc"[..], res3));
let res4 = vec![&b"abcd"[..], &b"abcd"[..]];
assert_eq!(multi(e), Done(&b",ef"[..], res4));
}

#[test]
Expand All @@ -3222,12 +3225,15 @@ mod tests {
let a = &b"abcdef"[..];
let b = &b"abcd,abcdef"[..];
let c = &b"azerty"[..];
let d = &b"abcd,abcd,ef"[..];

let res1 = vec![&b"abcd"[..]];
assert_eq!(multi(a), Done(&b"ef"[..], res1));
let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
assert_eq!(multi(b), Done(&b"ef"[..], res2));
assert_eq!(multi(c), Error(Position(ErrorKind::Tag,c)));
let res3 = vec![&b"abcd"[..], &b"abcd"[..]];
assert_eq!(multi(d), Done(&b",ef"[..], res3));
}

#[test]
Expand Down

0 comments on commit d42cf5c

Please sign in to comment.