From 60cec38c964d890e92516f65ffa310887415ad08 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 22 Aug 2021 23:06:09 +0100 Subject: [PATCH] fix tests Signed-off-by: Ian Jackson --- src/slip.rs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/slip.rs b/src/slip.rs index cd1e9a0..00c1560 100644 --- a/src/slip.rs +++ b/src/slip.rs @@ -24,7 +24,7 @@ impl SlipMime for Slip2Mime { const CONV_TO: Option = Some(true); } impl SlipMime for Mime2Slip { const CONV_TO: Option = Some(false); } impl SlipMime for SlipNoConv { const CONV_TO: Option = None; } -#[derive(Debug,Error)] +#[derive(Debug,Error,Eq,PartialEq)] pub enum SlipFramesError where E: std::error::Error + 'static { #[error("only bad IP datagrams")] ErrorOnlyBad, #[error("{0}")] Other(#[from] E), @@ -206,45 +206,55 @@ async fn mime_slip_to_mime() { async fn chk(m: M, i: &[u8], exp_p: &[&[u8]], - exp_e: &[PacketError]) + exp_e: &[PacketError], + exp_r: Result<(),SlipFramesError>) { dbg!(M::CONV_TO, DumpHex(i)); let mut got_e = vec![]; let mut got_p = vec![]; - processn(m, MTU, i, - |_|Ok(()), - |(p,())| { got_p.push(p); async { Ok(()) } }, - |e| Ok::<_,SlipFramesError>(got_e.push(e))) - .await.unwrap(); + let got_r = processn( + m, MTU, i, + |_|Ok(()), + |(p,())| { got_p.push(p); async { Ok(()) } }, + |e| Ok::<_,SlipFramesError>(got_e.push(e)) + ).await; assert_eq!( got_p.iter().map(|b| DumpHex(b)).collect_vec(), exp_p.iter().map(|b| DumpHex(b)).collect_vec() ); assert_eq!( got_e, exp_e ); + assert_eq!( got_r, + exp_r ); } + use SlipFramesError::ErrorOnlyBad; chk(Slip2Mime, &[ SLIP_END, SLIP_ESC, SLIP_ESC_END, b'-', b'X' ], &[ &[ b'-', SLIP_ESC_END, SLIP_ESC, b'X' ] ], - &[ PE::Empty ]).await; + &[ ], + Ok(())).await; chk(Slip2Mime, &[ SLIP_END, SLIP_ESC, b'y' ], &[], - &[ PE::Empty, PE::SLIP ]).await; + &[ PE::SLIP ], + Err(ErrorOnlyBad)).await; chk(Slip2Mime, &[ SLIP_END, b'-', b'y' ], &[ &[ SLIP_ESC, b'y' ] ], - &[ PE::Empty ]).await; + &[ ], + Ok(())).await; chk(Slip2Mime, &[b'x'; 20], &[ ], - &[ PE::MTU { len: 20, mtu: MTU } ]).await; + &[ PE::MTU { len: 20, mtu: MTU } ], + Err(ErrorOnlyBad)).await; chk(SlipNoConv, &[ SLIP_END, SLIP_ESC, SLIP_ESC_END, b'-', b'X' ], &[ &[ SLIP_ESC, SLIP_ESC_END, b'-', b'X' ] ], - &[ PE::Empty, ]).await; + &[ ], + Ok(())).await; } -- 2.30.2