File: is_end_stream.rs

package info (click to toggle)
rust-http-body 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 4
file content (70 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use http_body::{Body, Frame, 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_frame(
        self: Pin<&mut Self>,
        _cx: &mut Context<'_>,
    ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
        Poll::Ready(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!(
        !Pin::new(&mut mock).is_end_stream(),
        "size_hint = {:?}",
        mock.size_hint.clone()
    );
}