1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

fix payload readuntil

This commit is contained in:
Nikolay Kim 2017-10-22 20:07:18 -07:00
parent 32a9d9f683
commit d49e61591f

View File

@ -297,7 +297,7 @@ impl Inner {
if idx == line.len() { if idx == line.len() {
num = no; num = no;
offset = pos+1; offset = pos+1;
length += pos; length += pos+1;
found = true; found = true;
break; break;
} }
@ -410,6 +410,7 @@ mod test {
} }
assert!(payload.is_empty()); assert!(payload.is_empty());
assert!(payload.eof()); assert!(payload.eof());
assert_eq!(payload.len(), 0);
match payload.readany() { match payload.readany() {
Async::Ready(None) => (), Async::Ready(None) => (),
@ -478,16 +479,19 @@ mod test {
sender.feed_data(Bytes::from("line1")); sender.feed_data(Bytes::from("line1"));
sender.feed_data(Bytes::from("line2")); sender.feed_data(Bytes::from("line2"));
assert_eq!(payload.len(), 10);
match payload.readexactly(2) { match payload.readexactly(2) {
Ok(Async::Ready(data)) => assert_eq!(&data, "li"), Ok(Async::Ready(data)) => assert_eq!(&data, "li"),
_ => panic!("error"), _ => panic!("error"),
} }
assert_eq!(payload.len(), 8);
match payload.readexactly(4) { match payload.readexactly(4) {
Ok(Async::Ready(data)) => assert_eq!(&data, "ne1l"), Ok(Async::Ready(data)) => assert_eq!(&data, "ne1l"),
_ => panic!("error"), _ => panic!("error"),
} }
assert_eq!(payload.len(), 4);
sender.set_error(PayloadError::Incomplete); sender.set_error(PayloadError::Incomplete);
match payload.readexactly(10) { match payload.readexactly(10) {
@ -512,16 +516,19 @@ mod test {
sender.feed_data(Bytes::from("line1")); sender.feed_data(Bytes::from("line1"));
sender.feed_data(Bytes::from("line2")); sender.feed_data(Bytes::from("line2"));
assert_eq!(payload.len(), 10);
match payload.readuntil(b"ne") { match payload.readuntil(b"ne") {
Ok(Async::Ready(data)) => assert_eq!(&data, "line"), Ok(Async::Ready(data)) => assert_eq!(&data, "line"),
_ => panic!("error"), _ => panic!("error"),
} }
assert_eq!(payload.len(), 6);
match payload.readuntil(b"2") { match payload.readuntil(b"2") {
Ok(Async::Ready(data)) => assert_eq!(&data, "1line2"), Ok(Async::Ready(data)) => assert_eq!(&data, "1line2"),
_ => panic!("error"), _ => panic!("error"),
} }
assert_eq!(payload.len(), 0);
sender.set_error(PayloadError::Incomplete); sender.set_error(PayloadError::Incomplete);
match payload.readuntil(b"b") { match payload.readuntil(b"b") {