macro_rules! shrink_a_map_field {
($obj:expr, $field:ident, $key_fn:expr) => { ... };
}
Expand description
Shrinks a mapping field whose key is determined by the value.
For a mapping field, sometimes the key is determined by the value.
To keep this constraint in shrinking, one can use shrink_a_map_field
.
For example,
use rs_quickcheck_util::shrink_a_map_field;
use std::collections::BTreeMap;
#[derive(Debug, Clone)]
struct T {
m: BTreeMap<String, usize>,
}
let t = T {
m: [
("1".to_string(), 1),
("2".to_string(), 2),
("3".to_string(), 3),
("4".to_string(), 4),
("5".to_string(), 5),
("6".to_string(), 6),
].into(),
};
for x in shrink_a_map_field!(t, m, |x: &usize| -> String {format!("{}", x)}) {
for (k, v) in x.m.iter() {
assert_eq!(k.to_string(), format!("{}", v));
}
}
Then, both size and values of t.m
will be shrinked, but the relation between
keys and values are kept.