Debian Codegraph @

tests/maybe_bin.rs

raw symbols SCIP
1 use clap_num::maybe_bin;
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_bin($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_bin($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_bin, "0b0", 0u16);
31 pos!(one_dec, "1", 1u64);
32 pos!(one_bin, "0b1", 1u64);
33 pos!(aa, "0b10101010", 0xaau64);
34 pos!(leading_zero, "001", 1u64);
35
36 neg!(
37 missing_suffix,
38 "0b",
39 "cannot parse integer from empty string"
40 );
41 neg!(non_bin_digit, "0b12G", "invalid digit found in string");
42 }