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:
52
tests/h2-support/src/raw.rs
Normal file
52
tests/h2-support/src/raw.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user