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.
This commit is contained in:
Tobin C. Harding 2024-04-02 09:40:19 +11:00
parent 499f36f972
commit dca054c680
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 19 additions and 0 deletions

View File

@ -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);
}
}