Split out the messages into individual files,, and add negative tests, so we can aspire towards good coverage.

This commit is contained in:
2021-06-27 16:53:57 -07:00
parent 1bf6f62d4e
commit d1143a414c
13 changed files with 1087 additions and 607 deletions

33
src/messages/utils.rs Normal file
View File

@@ -0,0 +1,33 @@
#[cfg(test)]
use quickcheck::{Arbitrary, Gen};
#[cfg(test)]
pub fn arbitrary_socks_string(g: &mut Gen) -> String {
loop {
let mut potential = String::arbitrary(g);
potential.truncate(255);
let bytestring = potential.as_bytes();
if bytestring.len() > 0 && bytestring.len() < 256 {
return potential;
}
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! standard_roundtrip {
($name: ident, $t: ty) => {
#[cfg(test)]
quickcheck! {
fn $name(xs: $t) -> bool {
let mut buffer = vec![];
task::block_on(xs.write(&mut buffer)).unwrap();
let mut cursor = Cursor::new(buffer);
let ys = <$t>::read(Pin::new(&mut cursor));
xs == task::block_on(ys).unwrap()
}
}
};
}