From fbe4451688ac3026b1c74fc2029113a87a103bad Mon Sep 17 00:00:00 2001 From: Olybear9 Date: Thu, 25 Nov 2021 17:36:26 -0600 Subject: [PATCH 1/2] chore: Wow it was really this easy the entire time... --- bin_macro/src/stream.rs | 2 +- tests/{enum.rs => enums.rs} | 0 tests/format.rs | 23 +++++++++++++++++++++++ tests/tests.rs | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) rename tests/{enum.rs => enums.rs} (100%) create mode 100644 tests/format.rs 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..9f7a716 --- /dev/null +++ b/tests/format.rs @@ -0,0 +1,23 @@ +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/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; From 9066604793299c13a8d333c92489d8101f5ec2f9 Mon Sep 17 00:00:00 2001 From: Olybear9 Date: Thu, 25 Nov 2021 17:36:52 -0600 Subject: [PATCH 2/2] format: Run cargo-fmt [skip ci] --- tests/format.rs | 9 ++++----- tests/macro_tests.rs | 2 +- tests/vec.rs | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/format.rs b/tests/format.rs index 9f7a716..a1a3e8d 100644 --- a/tests/format.rs +++ b/tests/format.rs @@ -2,22 +2,21 @@ 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 + 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 + pub width: LE, } #[test] fn test_varint() { let test = TestPacket { id: 95, - width: LE::(4206942069) + 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/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()) }