use pmat::services::mutation::json_parser::{CargoMutantsReport, MutantOutcome};
use std::process;
fn main() {
println!("๐งช cargo-mutants JSON Parser - GREEN Phase Example\n");
let sample_json = r#"{
"mutants": [
{
"outcome": "caught",
"file": "src/lib.rs",
"function": "add",
"line": 10,
"replacement": "0"
},
{
"outcome": "missed",
"file": "src/lib.rs",
"function": "subtract",
"line": 15,
"replacement": "1"
},
{
"outcome": "timeout",
"file": "src/lib.rs",
"function": "multiply",
"line": 20,
"replacement": "panic!()"
},
{
"outcome": "unviable",
"file": "src/lib.rs",
"function": "divide",
"line": 25,
"replacement": "compile_error!()"
}
]
}"#;
println!("๐ Sample cargo-mutants JSON:");
println!("{}\n", sample_json);
match CargoMutantsReport::from_json(sample_json) {
Ok(report) => {
println!("โ
Parsed {} mutants from JSON\n", report.mutants.len());
let pmat_report = report.to_pmat_report();
println!(
"โ
Converted to PMAT format ({} mutants)\n",
pmat_report.len()
);
let total = report.mutants.len();
let caught = report
.mutants
.iter()
.filter(|m| matches!(m.outcome, MutantOutcome::Caught))
.count();
let missed = report
.mutants
.iter()
.filter(|m| matches!(m.outcome, MutantOutcome::Missed))
.count();
let timeout = report
.mutants
.iter()
.filter(|m| matches!(m.outcome, MutantOutcome::Timeout))
.count();
let unviable = report
.mutants
.iter()
.filter(|m| matches!(m.outcome, MutantOutcome::Unviable))
.count();
let mutation_score = if total > 0 {
(caught as f64 / total as f64) * 100.0
} else {
0.0
};
println!("๐ Mutation Testing Results:");
println!(" Total mutants: {}", total);
println!(" Caught: {} ({:.1}%)", caught, mutation_score);
println!(
" Missed: {} ({:.1}%)",
missed,
(missed as f64 / total as f64) * 100.0
);
println!(
" Timeout: {} ({:.1}%)",
timeout,
(timeout as f64 / total as f64) * 100.0
);
println!(
" Unviable: {} ({:.1}%)\n",
unviable,
(unviable as f64 / total as f64) * 100.0
);
println!("๐ Mutation Score: {:.1}%", mutation_score);
if mutation_score >= 90.0 {
println!("โ
Excellent! Test suite quality is very high");
} else if mutation_score >= 75.0 {
println!("โ ๏ธ Good, but room for improvement");
} else {
println!("โ Test suite needs significant improvement");
}
println!("\nโ
GREEN Phase implementation complete!");
}
Err(e) => {
eprintln!("โ Failed to parse JSON: {}", e);
process::exit(1);
}
}
}