Move tests and support utilities to sub crates. (#268)

These crates will not be published to crates.io, but moving them allows
`tower-h2` to also depend on the test utilities.
This commit is contained in:
Carl Lerche
2018-05-03 13:08:39 -07:00
committed by GitHub
parent 51f6a12454
commit 8a9dfd14dc
29 changed files with 135 additions and 33 deletions

View File

@@ -0,0 +1,52 @@
// ===== Build a codec from raw bytes =====
#[macro_export]
macro_rules! raw_codec {
(
$(
$fn:ident => [$($chunk:expr,)+];
)*
) => {{
let mut b = $crate::mock_io::Builder::new();
$({
let mut chunk = vec![];
$(
$crate::raw::Chunk::push(&$chunk, &mut chunk);
)+
b.$fn(&chunk[..]);
})*
$crate::Codec::new(b.build())
}}
}
pub trait Chunk {
fn push(&self, dst: &mut Vec<u8>);
}
impl Chunk for u8 {
fn push(&self, dst: &mut Vec<u8>) {
dst.push(*self);
}
}
impl<'a> Chunk for &'a [u8] {
fn push(&self, dst: &mut Vec<u8>) {
dst.extend(*self)
}
}
impl<'a> Chunk for &'a str {
fn push(&self, dst: &mut Vec<u8>) {
dst.extend(self.as_bytes())
}
}
impl Chunk for Vec<u8> {
fn push(&self, dst: &mut Vec<u8>) {
dst.extend(self.iter())
}
}