#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod cb050_falsification {
use super::*;
#[test]
fn tp_001_basic_todo_macro() {
let code = "fn foo() { todo!() }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect basic todo!()"
);
assert!(
violations.iter().any(|(_, id, _)| *id == "CB-050-A"),
"FALSIFIED: Wrong pattern ID for todo!()"
);
}
#[test]
fn tp_002_todo_with_message() {
let code = r#"fn foo() { todo!("implement later") }"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect todo!() with message"
);
}
#[test]
fn tp_003_unimplemented_macro() {
let code = "fn bar() { unimplemented!() }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect unimplemented!()"
);
assert!(violations.iter().any(|(_, id, _)| *id == "CB-050-B"));
}
#[test]
fn tp_004_panic_not_implemented() {
let code = r#"fn baz() { panic!("not implemented") }"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect panic not implemented"
);
assert!(violations.iter().any(|(_, id, _)| *id == "CB-050-C"));
}
#[test]
fn tp_005_empty_function_body() {
let code = "fn empty() {}";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect empty function body"
);
assert!(violations.iter().any(|(_, id, _)| *id == "CB-050-D"));
}
#[test]
fn tp_006_empty_function_with_whitespace() {
let code = "fn empty() { }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect empty body with whitespace"
);
}
#[test]
fn tp_007_empty_function_multiline() {
let code = "fn empty() {\n\n}";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect multiline empty body"
);
}
#[test]
fn tp_008_python_not_implemented_error() {
let code = "def foo():\n raise NotImplementedError()";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect Python NotImplementedError"
);
assert!(violations.iter().any(|(_, id, _)| *id == "CB-050-E"));
}
#[test]
fn tp_009_python_not_implemented_with_message() {
let code = r#"def foo():
raise NotImplementedError("not done yet")"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect NotImplementedError with message"
);
}
#[test]
fn tp_010_python_pass_stub_comment() {
let code = "def foo():\n pass # stub";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect Python pass stub"
);
assert!(violations.iter().any(|(_, id, _)| *id == "CB-050-F"));
}
#[test]
fn tp_011_todo_in_match_arm() {
let code = "match x { Some(_) => todo!(), None => 0 }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect todo!() in match arm"
);
}
#[test]
fn tp_012_todo_in_closure() {
let code = "let f = || todo!();";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect todo!() in closure"
);
}
#[test]
fn tp_013_unimplemented_with_formatting() {
let code = r#"fn x() { unimplemented!("{} not done: {}", "feature", 42) }"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect unimplemented!() with format"
);
}
#[test]
fn tp_014_todo_weird_spacing() {
let code = "fn f() { todo ! () }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Failed to detect todo with weird spacing"
);
}
#[test]
fn tp_015_multiple_stubs_one_file() {
let code = "fn a() { todo!() }\nfn b() { unimplemented!() }\nfn c() {}";
let violations = detect_cb050_code_stubs_in_str(code);
assert_eq!(
violations.len(),
3,
"FALSIFIED: Should detect all 3 stubs, found {}",
violations.len()
);
}
#[test]
fn tn_016_todo_in_string_literal() {
let code = r#"let s = "todo!() is a macro";"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Detected todo! in string literal"
);
}
#[test]
fn tn_017_todo_in_comment() {
let code = "// TODO: implement this\nfn foo() { return 42; }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Detected TODO comment as code stub"
);
}
#[test]
fn tn_018_function_with_body() {
let code = "fn not_empty() { println!(\"hello\"); }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Function with body flagged as stub"
);
}
#[test]
fn tn_019_trait_default_impl() {
let code = "trait Foo { fn default_impl() {} }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Trait default impl flagged as stub"
);
}
#[test]
fn tn_020_test_function_with_todo() {
let code = "#[test]\nfn test_future_feature() { todo!() }";
let violations = detect_cb050_code_stubs_in_str_with_path(code, "src/tests/mod.rs");
assert!(
violations.is_empty(),
"FALSIFIED (FP): Test stub flagged as violation"
);
}
#[test]
fn tn_021_doc_comment_with_todo() {
let code = "/// TODO: document this\nfn foo() { 42 }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Doc comment flagged as stub"
);
}
#[test]
fn tn_022_raw_string_with_todo() {
let code = r##"let s = r#"todo!() in raw string"#;"##;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Raw string flagged as stub"
);
}
#[test]
fn tn_023_macro_definition_with_todo_pattern() {
let code = r#"macro_rules! my_macro { (todo) => { /* ... */ }; }"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Macro definition flagged"
);
}
#[test]
fn tn_024_variable_named_todo() {
let code = "let todo = 42;";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Variable named 'todo' flagged"
);
}
#[test]
fn tn_025_function_named_todo() {
let code = "fn todo() -> i32 { 42 }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Function named 'todo' flagged"
);
}
#[test]
fn edge_026_nested_braces_empty_inner() {
let code = "fn outer() { { } let x = 1; }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Nested empty braces in function with content"
);
}
#[test]
fn edge_027_async_fn_with_todo() {
let code = "async fn foo() { todo!() }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(!violations.is_empty(), "FALSIFIED: Missed todo in async fn");
}
#[test]
fn edge_028_const_fn_empty() {
let code = "const fn marker() {}";
let _violations = detect_cb050_code_stubs_in_str(code);
}
#[test]
fn edge_029_unicode_in_todo_message() {
let code = r#"fn f() { todo!("实现这个功能 🚧") }"#;
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
!violations.is_empty(),
"FALSIFIED: Missed todo with unicode"
);
}
#[test]
fn edge_030_todo_in_doc_test() {
let code = "/// ```\n/// fn example() { todo!() }\n/// ```\nfn real_fn() { 42 }";
let violations = detect_cb050_code_stubs_in_str(code);
assert!(
violations.is_empty(),
"FALSIFIED (FP): Doc test stub flagged"
);
}
}