From dca054c680959e3456895f8cfd047662699d1a1a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 2 Apr 2024 09:40:19 +1100 Subject: [PATCH] test: Add unit tests for hex_u32 Test the current behaviour of `hex_u32` - verifies that we handle parsing strings with and without a prefix. --- units/src/parse.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/units/src/parse.rs b/units/src/parse.rs index 787bbdeb..83ea5980 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -182,3 +182,22 @@ macro_rules! impl_parse_str { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_u32_from_hex_prefixed() { + let want = 171; + let got = hex_u32("0xab").expect("failed to parse prefixed hex"); + assert_eq!(got, want); + } + + #[test] + fn parse_u32_from_hex_no_prefix() { + let want = 171; + let got = hex_u32("ab").expect("failed to parse non-prefixed hex"); + assert_eq!(got, want); + } +}