From d47e855e656330ce0f47840fd8b0a0692afd3a7a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 22 Mar 2024 08:22:51 +0100 Subject: [PATCH] Add test for roundtripping u32 write/parse Signed-off-by: Matthias Beyer --- mqtt-format/src/v5/integers.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mqtt-format/src/v5/integers.rs b/mqtt-format/src/v5/integers.rs index e6702c9c..f37ec4cc 100644 --- a/mqtt-format/src/v5/integers.rs +++ b/mqtt-format/src/v5/integers.rs @@ -210,6 +210,19 @@ mod tests { assert_eq!(writer.buffer, &[0x00, 0x00, 0x00, 0x01]); } + #[tokio::test] + async fn test_write_u32() { + // step by some prime number + for i in (0..268_435_455).step_by(271) { + let mut writer = TestWriter { buffer: Vec::new() }; + + writer.write_u32(i).await.unwrap(); + + let out = parse_variable_u32(&mut Bytes::new(&writer.buffer)).unwrap(); + assert_eq!(out, i); + } + } + #[tokio::test] async fn test_write_variable_u32() { // step by some prime number