Debian Codegraph @

tests/maybe_hex.rs

raw symbols SCIP
1 use clap_num::maybe_hex;
2
3 #[cfg(test)]
4 mod basic {
5 use super::*;
6
7 // positive path
8 macro_rules! pos {
9 ($NAME:ident, $VAL:expr, $RESULT:expr) => {
10 #[test]
11 fn $NAME() {
12 assert_eq!(maybe_hex($VAL), Ok($RESULT));
13 }
14 };
15 }
16
17 // negative path
18 macro_rules! neg {
19 ($NAME:ident, $VAL:expr, $RESULT:expr) => {
20 #[test]
21 fn $NAME() {
22 let val: Result<u64, String> = maybe_hex($VAL);
23 assert_eq!(val, Err(String::from($RESULT)));
24 }
25 };
26 }
27
28 pos!(simple, "123", 123u8);
29 pos!(zero_dec, "0", 0u16);
30 pos!(zero_hex, "0x0", 0u16);
31 pos!(one_dec, "1", 1u64);
32 pos!(one_hex, "0x1", 1u64);
33 pos!(leading_zero, "001", 1u64);
34 pos!(case, "0XABcDE", 703710u32);
35
36 neg!(
37 missing_suffix,
38 "0x",
39 "cannot parse integer from empty string"
40 );
41 neg!(dec_with_hex, "1A", "invalid digit found in string");
42 neg!(non_hex_digit, "0x12G", "invalid digit found in string");
43 }