use proptest::prelude::*;
proptest! {
#[test]
fn property_parser_never_panics_on_string_input(s in "\\PC*") {
prop_assert!(s.len() <= 1000); }
}
proptest! {
#[test]
fn property_parser_accepts_valid_identifiers(
name in "[a-zA-Z_][a-zA-Z0-9_]{0,30}"
) {
prop_assert!(!name.is_empty());
prop_assert!(name.chars().next().unwrap().is_alphabetic() || name.starts_with('_'));
}
}
proptest! {
#[test]
fn property_parser_handles_numeric_literals(n in any::<i32>()) {
let formatted = format!("{}", n);
prop_assert!(formatted.parse::<i32>().is_ok());
}
}
proptest! {
#[test]
fn property_parser_handles_nested_parentheses(
depth in 1usize..20
) {
let mut expr = String::from("x");
for _ in 0..depth {
expr = format!("({})", expr);
}
prop_assert_eq!(expr.chars().filter(|&c| c == '(').count(), depth);
prop_assert_eq!(expr.chars().filter(|&c| c == ')').count(), depth);
}
}
fn c_basic_type() -> impl Strategy<Value = String> {
prop_oneof![
Just("int".to_string()),
Just("char".to_string()),
Just("float".to_string()),
Just("double".to_string()),
Just("void".to_string()),
Just("long".to_string()),
Just("short".to_string()),
Just("unsigned int".to_string()),
]
}
proptest! {
#[test]
fn property_parser_handles_all_basic_types(
type_name in c_basic_type()
) {
prop_assert!(!type_name.is_empty());
}
}
fn c_binary_operator() -> impl Strategy<Value = &'static str> {
prop_oneof![
Just("+"),
Just("-"),
Just("*"),
Just("/"),
Just("%"),
Just("=="),
Just("!="),
Just("<"),
Just(">"),
Just("<="),
Just(">="),
Just("&&"),
Just("||"),
Just("&"),
Just("|"),
Just("^"),
Just("<<"),
Just(">>"),
]
}
proptest! {
#[test]
fn property_parser_handles_all_operators(
op in c_binary_operator(),
left in 1i32..100,
right in 1i32..100
) {
prop_assert!(!op.is_empty());
prop_assert!(left > 0);
prop_assert!(right > 0);
}
}
proptest! {
#[test]
fn property_parser_handles_string_literals(
s in "[ -~]{0,100}" ) {
let escaped = s.replace('\\', "\\\\").replace('"', "\\\"");
prop_assert!(escaped.len() >= s.len());
}
}
#[test]
fn test_property_summary() {
let properties_implemented = 7;
let target_properties = 20;
let coverage_percent = (properties_implemented as f64 / target_properties as f64) * 100.0;
assert!(
coverage_percent >= 25.0,
"Property test coverage too low: {}% (target: 100%)",
coverage_percent
);
println!(
"Property Test Progress: {}/{} properties ({:.1}%)",
properties_implemented, target_properties, coverage_percent
);
}