diff --git a/bin_macro/src/stream.rs b/bin_macro/src/stream.rs index 1b059e2..dc4c84a 100644 --- a/bin_macro/src/stream.rs +++ b/bin_macro/src/stream.rs @@ -133,7 +133,7 @@ pub fn impl_named_fields(fields: Fields) -> (Vec, Vec) pub fn impl_streamable_lazy(name: &Ident, ty: &Type) -> (TokenStream, TokenStream) { ( quote! { writer.write(&self.#name.parse()?[..])?; }, - quote!(#name: #ty::compose(&source, position)?), + quote!(#name: <#ty>::compose(&source, position)?), ) } diff --git a/tests/enum.rs b/tests/enums.rs similarity index 100% rename from tests/enum.rs rename to tests/enums.rs diff --git a/tests/format.rs b/tests/format.rs new file mode 100644 index 0000000..a1a3e8d --- /dev/null +++ b/tests/format.rs @@ -0,0 +1,22 @@ +use binary_utils::*; + +pub const EXPECTED_DEBUG: &[u8] = &[ + // packet id + 95, // u128 as LE + 117, 215, 192, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +]; + +#[derive(BinaryStream)] +pub struct TestPacket { + pub id: u8, + pub width: LE, +} + +#[test] +fn test_varint() { + let test = TestPacket { + id: 95, + width: LE::(4206942069), + }; + assert_eq!(&test.parse().unwrap()[..], EXPECTED_DEBUG); +} diff --git a/tests/macro_tests.rs b/tests/macro_tests.rs index f7987df..40514b9 100644 --- a/tests/macro_tests.rs +++ b/tests/macro_tests.rs @@ -34,7 +34,7 @@ fn read_string() { #[derive(BinaryStream)] pub struct HelloWorld { - data: LE::, + data: LE, } #[test] diff --git a/tests/tests.rs b/tests/tests.rs index 6c383c1..d9bbc66 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,4 +1,5 @@ -// make a test +mod enums; +mod format; mod le_test; mod lstring; mod macro_tests; diff --git a/tests/vec.rs b/tests/vec.rs index 015f67e..20e6ba3 100644 --- a/tests/vec.rs +++ b/tests/vec.rs @@ -18,13 +18,13 @@ fn test_le_vec() { assert_eq!(str_bytes.fparse(), le_bytes_netrex); - let mut test: Vec> = Vec::new(); + let mut test: Vec> = Vec::new(); test.push(str_bytes.clone()); // Vectors store length {stream, stream } // where "stream" in this case is [length, string bytes] let vector = test.fparse(); println!("{:?}", vector); - let restored = Vec::>::fcompose(&vector[..], &mut 0); + let restored = Vec::>::fcompose(&vector[..], &mut 0); assert_eq!(restored[0].clone().inner(), str_bytes.inner()) }