1#![warn(rust_2018_idioms)]
2
3use std::task::Poll;
4use tokio_test::{
5 assert_pending, assert_ready, assert_ready_eq, assert_ready_err, assert_ready_ok,
6};
7
8fn ready() -> Poll<()> {
9 Poll::Ready(())
10}
11
12fn ready_ok() -> Poll<Result<(), ()>> {
13 Poll::Ready(Ok(()))
14}
15
16fn ready_err() -> Poll<Result<(), ()>> {
17 Poll::Ready(Err(()))
18}
19
20fn pending() -> Poll<()> {
21 Poll::Pending
22}
23
24#[derive(Debug)]
25enum Test {
26 Data,
27}
28
29#[test]
30fn assert_ready() {
31 let poll = ready();
32 assert_ready!(poll);
33 assert_ready!(poll, "some message");
34 assert_ready!(poll, "{:?}", ());
35 assert_ready!(poll, "{:?}", Test::Data);
36}
37
38#[test]
39#[should_panic]
40fn assert_ready_on_pending() {
41 let poll = pending();
42 assert_ready!(poll);
43}
44
45#[test]
46fn assert_pending() {
47 let poll = pending();
48 assert_pending!(poll);
49 assert_pending!(poll, "some message");
50 assert_pending!(poll, "{:?}", ());
51 assert_pending!(poll, "{:?}", Test::Data);
52}
53
54#[test]
55#[should_panic]
56fn assert_pending_on_ready() {
57 let poll = ready();
58 assert_pending!(poll);
59}
60
61#[test]
62fn assert_ready_ok() {
63 let poll = ready_ok();
64 assert_ready_ok!(poll);
65 assert_ready_ok!(poll, "some message");
66 assert_ready_ok!(poll, "{:?}", ());
67 assert_ready_ok!(poll, "{:?}", Test::Data);
68}
69
70#[test]
71#[should_panic]
72fn assert_ok_on_err() {
73 let poll = ready_err();
74 assert_ready_ok!(poll);
75}
76
77#[test]
78fn assert_ready_err() {
79 let poll = ready_err();
80 assert_ready_err!(poll);
81 assert_ready_err!(poll, "some message");
82 assert_ready_err!(poll, "{:?}", ());
83 assert_ready_err!(poll, "{:?}", Test::Data);
84}
85
86#[test]
87#[should_panic]
88fn assert_err_on_ok() {
89 let poll = ready_ok();
90 assert_ready_err!(poll);
91}
92
93#[test]
94fn assert_ready_eq() {
95 let poll = ready();
96 assert_ready_eq!(poll, ());
97 assert_ready_eq!(poll, (), "some message");
98 assert_ready_eq!(poll, (), "{:?}", ());
99 assert_ready_eq!(poll, (), "{:?}", Test::Data);
100}
101
102#[test]
103#[should_panic]
104fn assert_eq_on_not_eq() {
105 let poll = ready_err();
106 assert_ready_eq!(poll, Ok(()));
107}
108