parent
c095ee2aa0
commit
dea9398e08
1 changed files with 12 additions and 5 deletions
17
src/parse.rs
17
src/parse.rs
|
|
@ -25,9 +25,13 @@ unsafe fn parse_many<T, F>(lines: Vec<u8>, mut map: F) -> ZeroCopyResult<Vec<T>>
|
||||||
where
|
where
|
||||||
F: FnMut(Response<'static>) -> MapOrNot<T>,
|
F: FnMut(Response<'static>) -> MapOrNot<T>,
|
||||||
{
|
{
|
||||||
let f = |mut lines| {
|
let f = |mut lines: &'static [u8]| {
|
||||||
let mut things = Vec::new();
|
let mut things = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
|
if lines.is_empty() {
|
||||||
|
break Ok(things);
|
||||||
|
}
|
||||||
|
|
||||||
match imap_proto::parse_response(lines) {
|
match imap_proto::parse_response(lines) {
|
||||||
IResult::Done(rest, resp) => {
|
IResult::Done(rest, resp) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
|
|
@ -36,10 +40,6 @@ where
|
||||||
MapOrNot::Map(t) => things.push(t),
|
MapOrNot::Map(t) => things.push(t),
|
||||||
MapOrNot::Not(resp) => break Err(resp.into()),
|
MapOrNot::Not(resp) => break Err(resp.into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if lines.is_empty() {
|
|
||||||
break Ok(things);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
|
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
|
||||||
|
|
@ -237,6 +237,13 @@ mod tests {
|
||||||
assert_eq!(names[0].name(), "INBOX");
|
assert_eq!(names[0].name(), "INBOX");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_fetches_empty() {
|
||||||
|
let lines = b"";
|
||||||
|
let fetches = parse_fetches(lines.to_vec()).unwrap();
|
||||||
|
assert!(fetches.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_fetches_test() {
|
fn parse_fetches_test() {
|
||||||
let lines = b"\
|
let lines = b"\
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue