Fix DNF construction, add proptest

This commit is contained in:
Jonas Schievink 2021-08-30 22:26:35 +02:00
parent 20f3792d10
commit e6255356d2
5 changed files with 99 additions and 4 deletions

View file

@ -50,6 +50,7 @@ impl fmt::Display for CfgAtom {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum CfgExpr {
Invalid,
Atom(CfgAtom),
@ -128,3 +129,17 @@ fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> {
}
Some(ret)
}
#[cfg(test)]
impl arbitrary::Arbitrary<'_> for CfgAtom {
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
match u.int_in_range(0..=1)? {
0 => Ok(CfgAtom::Flag(String::arbitrary(u)?.into())),
1 => Ok(CfgAtom::KeyValue {
key: String::arbitrary(u)?.into(),
value: String::arbitrary(u)?.into(),
}),
_ => unreachable!(),
}
}
}