use crate::cpp::integration_tests::{create_test_target, mutants_for_slug};
use mewt::LanguageEngine;
use mewt::languages::cpp::engine::CppLanguageEngine;
use mewt::types::Mutant;

fn slug_mutants(source: &str) -> Vec<Mutant> {
    mutants_for_slug(source, "LC")
}

#[test]
fn test_lc_replacement_content() {
    let source = r#"
void f() {
    for (int i = 0; i < 10; i++) {
        if (i == 5) break;
    }
}
"#;
    let lc = slug_mutants(source);
    assert_eq!(
        lc.len(),
        1,
        "LC should produce 1 replacement for break: {lc:?}"
    );
    assert!(
        lc[0].old_text.contains("break"),
        "LC old_text should contain break"
    );
    assert!(
        lc[0].new_text.contains("continue"),
        "LC should replace break with continue"
    );
}

#[test]
fn test_switch_break_not_swapped_to_continue() {
    // break inside a switch (not inside a loop) — LC targets break_statement
    // and continue_statement, but a break inside a switch without a surrounding
    // loop should not produce a valid continue mutation. Document actual behavior.
    let source = r#"
int f(int x) {
    switch (x) {
        case 1:
            return 10;
        case 2:
            return 20;
        default:
            break;
    }
    return 0;
}
"#;
    let (_tmp, target) = create_test_target(source);
    let engine = CppLanguageEngine::new();
    let mutants = engine.mutate(&target);

    let lc: Vec<&Mutant> = mutants.iter().filter(|m| m.mutation_slug == "LC").collect();
    // LC will try to swap break -> continue here. This produces invalid code
    // (continue inside switch without a loop), which will fail to compile and
    // be recorded as TestFail (caught). This is acceptable noise — document it.
    // The important thing is it doesn't crash during mutation generation.
    // If there are LC mutants, they should involve break.
    for m in &lc {
        assert!(
            m.old_text.contains("break") || m.old_text.contains("continue"),
            "LC mutants should involve break or continue: {m:?}"
        );
    }
}
