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

@ -1,3 +1,4 @@
use arbitrary::{Arbitrary, Unstructured};
use expect_test::{expect, Expect};
use mbe::syntax_node_to_token_tree;
use syntax::{ast, AstNode};
@ -130,6 +131,18 @@ fn nested() {
check_dnf("#![cfg(not(all(all(a, b))))]", expect![[r#"#![cfg(any(not(a), not(b)))]"#]]);
}
#[test]
fn regression() {
check_dnf("#![cfg(all(not(not(any(any(any()))))))]", expect![[r##"#![cfg(any())]"##]]);
check_dnf("#![cfg(all(any(all(any()))))]", expect![[r##"#![cfg(any())]"##]]);
check_dnf("#![cfg(all(all(any())))]", expect![[r##"#![cfg(any())]"##]]);
check_dnf("#![cfg(all(all(any(), x)))]", expect![[r##"#![cfg(any())]"##]]);
check_dnf("#![cfg(all(all(any()), x))]", expect![[r##"#![cfg(any())]"##]]);
check_dnf("#![cfg(all(all(any(x))))]", expect![[r##"#![cfg(x)]"##]]);
check_dnf("#![cfg(all(all(any(x), x)))]", expect![[r##"#![cfg(all(x, x))]"##]]);
}
#[test]
fn hints() {
let mut opts = CfgOptions::default();
@ -191,3 +204,21 @@ fn why_inactive() {
expect![["test and test2 are enabled and a is disabled"]],
);
}
#[test]
fn proptest() {
const REPEATS: usize = 512;
let mut rng = oorandom::Rand32::new(123456789);
let mut buf = Vec::new();
for _ in 0..REPEATS {
buf.clear();
while buf.len() < 512 {
buf.extend(rng.rand_u32().to_ne_bytes());
}
let mut u = Unstructured::new(&buf);
let cfg = CfgExpr::arbitrary(&mut u).unwrap();
DnfExpr::new(cfg);
}
}