use crate::ui::constants::{color_dim, color_success, ICON_PASS};
pub fn render_passed_checks(passed_checks: &[String]) -> String {
if passed_checks.is_empty() {
return String::new();
}
let mut output = String::new();
output.push('\n');
output.push_str(&format!(
"{} ({})\n\n",
"Passed Checks",
passed_checks.len()
));
let max_width = passed_checks.iter().map(|c| c.len()).max().unwrap_or(20) + 6;
let num_cols = 3;
for (idx, check) in passed_checks.iter().enumerate() {
let formatted = format!("{} {}", color_success(ICON_PASS), color_dim(check));
if (idx + 1) % num_cols == 0 {
output.push_str(&format!("{}\n", formatted));
} else {
let padding = max_width.saturating_sub(check.len() + 3);
output.push_str(&formatted);
output.push_str(&" ".repeat(padding));
}
}
if !passed_checks.is_empty() && !passed_checks.len().is_multiple_of(num_cols) {
output.push('\n');
}
output
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_passed_checks_empty() {
let checks: Vec<String> = vec![];
let output = render_passed_checks(&checks);
assert_eq!(output, "");
}
#[test]
fn test_passed_checks_single() {
let checks = vec!["balance_conservation".to_string()];
let output = render_passed_checks(&checks);
assert!(output.contains("Passed Checks"));
assert!(output.contains("balance_conservation"));
}
#[test]
fn test_passed_checks_multiple() {
let checks = vec![
"balance_conservation".to_string(),
"no_negative_balance".to_string(),
"access_control".to_string(),
];
let output = render_passed_checks(&checks);
assert!(output.contains("Passed Checks"));
assert_eq!(output.matches("✓").count(), 3);
}
}