#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
#[cfg(test)]
#[test]
fn test_explain_changes_fallback_message() {
let result = explain_purification_changes("echo $RANDOM");
assert!(result.is_ok());
}
#[test]
fn test_format_transformation_report_with_line_number() {
let explanation = TransformationExplanation::new(
TransformationCategory::Determinism,
"Remove $RANDOM",
"echo $RANDOM",
"echo 42",
"Removed RANDOM",
"Determinism",
)
.with_line_number(7);
let report = format_transformation_report(&[explanation]);
assert!(report.contains("DETERMINISM"));
assert!(report.contains("Line: 7"));
assert!(report.contains("Remove $RANDOM"));
}
#[test]
fn test_format_transformation_report_multiple_entries() {
let explanations = vec![
TransformationExplanation::new(
TransformationCategory::Idempotency,
"mkdir → mkdir -p",
"mkdir /tmp",
"mkdir -p /tmp",
"Added -p",
"Idempotent",
),
TransformationExplanation::new(
TransformationCategory::Safety,
"Quote variables",
"echo $v",
"echo \"$v\"",
"Added quotes",
"Safety",
),
];
let report = format_transformation_report(&explanations);
assert!(report.contains("IDEMPOTENCY"));
assert!(report.contains("SAFETY"));
}
#[test]
fn test_purify_and_lint_mkdir_result() {
let result = purify_and_lint("mkdir /tmp/test_dir");
assert!(result.is_ok());
let plr = result.unwrap();
assert!(plr.purified_code.contains("mkdir"));
}
#[test]
fn test_explain_detailed_no_changes() {
let result = explain_purification_changes_detailed("echo hello");
assert!(result.is_ok());
let explanations = result.unwrap();
assert!(explanations.is_empty());
}
#[test]
fn test_explain_detailed_mkdir_idempotency() {
let result = explain_purification_changes_detailed("mkdir /tmp/test");
assert!(result.is_ok());
let explanations = result.unwrap();
let has_mkdir = explanations.iter().any(|e| {
matches!(e.category, TransformationCategory::Idempotency) && e.title.contains("mkdir")
});
assert!(has_mkdir, "Should detect mkdir → mkdir -p transformation");
}
#[test]
fn test_explain_detailed_rm_idempotency() {
let result = explain_purification_changes_detailed("rm /tmp/testfile");
assert!(result.is_ok());
let explanations = result.unwrap();
let has_rm = explanations.iter().any(|e| {
matches!(e.category, TransformationCategory::Idempotency) && e.title.contains("rm")
});
assert!(has_rm, "Should detect rm → rm -f transformation");
}
#[test]
fn test_explain_detailed_variable_quoting_safety_category() {
let result = explain_purification_changes_detailed("echo $HOME");
assert!(result.is_ok());
let explanations = result.unwrap();
let has_quoting = explanations
.iter()
.any(|e| matches!(e.category, TransformationCategory::Safety));
assert!(has_quoting, "Should detect variable quoting transformation");
}
#[test]
fn test_explain_detailed_random_determinism() {
let result = explain_purification_changes_detailed("echo $RANDOM");
assert!(result.is_ok());
let explanations = result.unwrap();
let has_random = explanations
.iter()
.any(|e| matches!(e.category, TransformationCategory::Determinism));
assert!(
has_random,
"Should detect $RANDOM removal as determinism transformation"
);
}
#[test]
fn test_explain_detailed_ln_idempotency() {
let result = explain_purification_changes_detailed("ln -s /src /dest");
assert!(result.is_ok());
let explanations = result.unwrap();
for e in &explanations {
assert!(!e.title.is_empty());
assert!(!e.what_changed.is_empty());
}
}