Pin postproc_prefix's StreamReader and add unit test

This commit is contained in:
Joseph LaFreniere 2022-12-24 15:44:13 -06:00
parent 1b97abfbca
commit 15a85275ef
No known key found for this signature in database
GPG Key ID: EE236AA0141EFCA3

View File

@ -140,7 +140,7 @@ pub fn postproc_prefix(line_prefix: &str, inp: impl AsyncRead + Send) -> impl As
}
}
};
StreamReader::new(oup_stream)
Box::pin(StreamReader::new(oup_stream))
}
/// Adds the prefix "Page N:" to each line,
@ -196,6 +196,18 @@ mod tests {
);
}
#[tokio::test]
async fn test_postproc_prefix() {
let mut output: Vec<u8> = Vec::new();
let mock: Mock = Builder::new().read(b"Hello\nWorld").build();
let res = postproc_prefix("prefix: ", mock)
.read_to_end(&mut output)
.await;
println!("{}", String::from_utf8_lossy(&output));
assert!(matches!(res, Ok(_)));
assert_eq!(output, b"prefix: Hello\nprefix: World");
}
async fn test_from_strs(
pagebreaks: bool,
line_prefix: &str,