Fix read_sizeline returning wrong error

Also added more tests
next
Sayan Nandan 3 years ago
parent daaf6968ba
commit 6d29e519c9

@ -97,11 +97,14 @@ impl<'a> Parser<'a> {
// Now read the remaining line // Now read the remaining line
let (started_at, stopped_at) = self.read_line(); let (started_at, stopped_at) = self.read_line();
return Self::parse_into_usize(&self.buffer[started_at..stopped_at]); return Self::parse_into_usize(&self.buffer[started_at..stopped_at]);
} } else {
}
// A sizeline should begin with a opt_char; this one doesn't so it's a bad packet; ugh // A sizeline should begin with a opt_char; this one doesn't so it's a bad packet; ugh
Err(ParseError::UnexpectedByte) Err(ParseError::UnexpectedByte)
} }
} else {
Err(ParseError::NotEnough)
}
}
fn incr_cursor(&mut self) { fn incr_cursor(&mut self) {
self.cursor += 1; self.cursor += 1;
} }
@ -390,4 +393,18 @@ fn test_query_fail_not_enough() {
.unwrap_err(), .unwrap_err(),
ParseError::NotEnough ParseError::NotEnough
); );
let metaframe = "\r2\n*1\n".as_bytes();
// we just got the metaframe, but there are more bytes, so this is incomplete!
assert_eq!(
Parser::new(&metaframe).parse().unwrap_err(),
ParseError::NotEnough
);
let metaframe_and_dataframe_layout = "\r2\n*1\n#2\n&2\n".as_bytes();
// we got the number of queries and the size of the data group, but no data; this is incomplete
assert_eq!(
Parser::new(&metaframe_and_dataframe_layout)
.parse()
.unwrap_err(),
ParseError::NotEnough
);
} }

Loading…
Cancel
Save