1 use http::HeaderMap;
2 use http_body::{Body, SizeHint};
3 use std::pin::Pin;
4 use std::task::{Context, Poll};
5
6 struct Mock {
7 size_hint: SizeHint,
8 }
9
10 impl Body for Mock {
11 type Data = ::std::io::Cursor<Vec<u8>>;
12 type Error = ();
13
poll_data( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Option<Result<Self::Data, Self::Error>>>14 fn poll_data(
15 self: Pin<&mut Self>,
16 _cx: &mut Context<'_>,
17 ) -> Poll<Option<Result<Self::Data, Self::Error>>> {
18 Poll::Ready(None)
19 }
20
poll_trailers( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<Option<HeaderMap>, Self::Error>>21 fn poll_trailers(
22 self: Pin<&mut Self>,
23 _cx: &mut Context<'_>,
24 ) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
25 Poll::Ready(Ok(None))
26 }
27
size_hint(&self) -> SizeHint28 fn size_hint(&self) -> SizeHint {
29 self.size_hint.clone()
30 }
31 }
32
33 #[test]
is_end_stream_true()34 fn is_end_stream_true() {
35 let combos = [
36 (None, None, false),
37 (Some(123), None, false),
38 (Some(0), Some(123), false),
39 (Some(123), Some(123), false),
40 (Some(0), Some(0), false),
41 ];
42
43 for &(lower, upper, is_end_stream) in &combos {
44 let mut size_hint = SizeHint::new();
45 assert_eq!(0, size_hint.lower());
46 assert!(size_hint.upper().is_none());
47
48 if let Some(lower) = lower {
49 size_hint.set_lower(lower);
50 }
51
52 if let Some(upper) = upper {
53 size_hint.set_upper(upper);
54 }
55
56 let mut mock = Mock { size_hint };
57
58 assert_eq!(
59 is_end_stream,
60 Pin::new(&mut mock).is_end_stream(),
61 "size_hint = {:?}",
62 mock.size_hint.clone()
63 );
64 }
65 }
66
67 #[test]
is_end_stream_default_false()68 fn is_end_stream_default_false() {
69 let mut mock = Mock {
70 size_hint: SizeHint::default(),
71 };
72
73 assert_eq!(
74 false,
75 Pin::new(&mut mock).is_end_stream(),
76 "size_hint = {:?}",
77 mock.size_hint.clone()
78 );
79 }
80