diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/http-body/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/http-body/tests')
-rw-r--r-- | third_party/rust/http-body/tests/is_end_stream.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/third_party/rust/http-body/tests/is_end_stream.rs b/third_party/rust/http-body/tests/is_end_stream.rs new file mode 100644 index 0000000000..beaeb0b1a0 --- /dev/null +++ b/third_party/rust/http-body/tests/is_end_stream.rs @@ -0,0 +1,79 @@ +use http::HeaderMap; +use http_body::{Body, SizeHint}; +use std::pin::Pin; +use std::task::{Context, Poll}; + +struct Mock { + size_hint: SizeHint, +} + +impl Body for Mock { + type Data = ::std::io::Cursor<Vec<u8>>; + type Error = (); + + fn poll_data( + self: Pin<&mut Self>, + _cx: &mut Context<'_>, + ) -> Poll<Option<Result<Self::Data, Self::Error>>> { + Poll::Ready(None) + } + + fn poll_trailers( + self: Pin<&mut Self>, + _cx: &mut Context<'_>, + ) -> Poll<Result<Option<HeaderMap>, Self::Error>> { + Poll::Ready(Ok(None)) + } + + fn size_hint(&self) -> SizeHint { + self.size_hint.clone() + } +} + +#[test] +fn is_end_stream_true() { + let combos = [ + (None, None, false), + (Some(123), None, false), + (Some(0), Some(123), false), + (Some(123), Some(123), false), + (Some(0), Some(0), false), + ]; + + for &(lower, upper, is_end_stream) in &combos { + let mut size_hint = SizeHint::new(); + assert_eq!(0, size_hint.lower()); + assert!(size_hint.upper().is_none()); + + if let Some(lower) = lower { + size_hint.set_lower(lower); + } + + if let Some(upper) = upper { + size_hint.set_upper(upper); + } + + let mut mock = Mock { size_hint }; + + assert_eq!( + is_end_stream, + Pin::new(&mut mock).is_end_stream(), + "size_hint = {:?}", + mock.size_hint.clone() + ); + } +} + +#[test] +fn is_end_stream_default_false() { + let mut mock = Mock { + size_hint: SizeHint::default(), + }; + + assert_eq!( + false, + Pin::new(&mut mock).is_end_stream(), + "size_hint = {:?}", + mock.size_hint.clone() + ); +} |