use super::*;
use crate::linter::shell_type::ShellType;
#[test]
fn test_batch4_quoting_safety_universal() {
let quoting_rules = vec![
"SC2075", "SC2076", "SC2077", "SC2078", "SC2081", "SC2082", "SC2083",
];
for rule in quoting_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch4_command_safety_universal() {
let command_rules = vec!["SC2094", "SC2095", "SC2096", "SC2097", "SC2098", "SC2103"];
for rule in command_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch4_critical_dangerous_rm_universal() {
let critical_rules = vec![
("SC2114", "Dangerous rm -rf without validation"),
("SC2115", "Use ${var:?} to ensure var is set before rm -rf"),
];
for (rule, description) in critical_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} ({}) should be Universal - applies to all shells",
rule,
description
);
for shell in [
ShellType::Bash,
ShellType::Zsh,
ShellType::Sh,
ShellType::Ksh,
] {
assert!(
should_apply_rule(rule, shell),
"{} should apply to {:?}",
rule,
shell
);
}
}
}
#[test]
fn test_batch4_notsh_count() {
let notsh_rules = vec![
"SC2128", ];
for rule in notsh_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh)
);
assert!(!should_apply_rule(rule, ShellType::Sh));
assert!(should_apply_rule(rule, ShellType::Bash));
assert!(should_apply_rule(rule, ShellType::Zsh));
}
}
#[test]
fn test_batch4_universal_count() {
let universal_rules = vec![
"SC2067", "SC2068", "SC2069", "SC2070", "SC2071", "SC2072", "SC2073", "SC2074",
"SC2075", "SC2076", "SC2077", "SC2078", "SC2081", "SC2082", "SC2083",
"SC2094", "SC2095", "SC2096", "SC2097", "SC2098", "SC2103",
"SC2104", "SC2105", "SC2107", "SC2114", "SC2115", "SC2116",
];
let unique_count = universal_rules.len();
assert_eq!(unique_count, 27, "Batch 4 should have 27 Universal rules");
for rule in universal_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
}
}
#[test]
fn test_batch5_command_optimization_universal() {
let command_rules = vec!["SC2001", "SC2005", "SC2006", "SC2007"];
for rule in command_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch5_logic_and_tr_universal() {
let logic_and_tr_rules = vec![
"SC2015", "SC2016", "SC2017", "SC2018", "SC2019", "SC2020", "SC2021",
];
for rule in logic_and_tr_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch5_ssh_and_quoting_universal() {
let ssh_and_quoting_rules = vec![
"SC2022", "SC2023", "SC2024", "SC2025", "SC2026", "SC2027", "SC2028", "SC2029",
];
for rule in ssh_and_quoting_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch5_critical_word_splitting_universal() {
let critical_rule = "SC2086";
assert_eq!(
get_rule_compatibility(critical_rule),
Some(ShellCompatibility::Universal),
"SC2086 (CRITICAL word splitting) should be Universal"
);
for shell in [
ShellType::Bash,
ShellType::Zsh,
ShellType::Sh,
ShellType::Ksh,
] {
assert!(
should_apply_rule(critical_rule, shell),
"SC2086 should apply to {:?}",
shell
);
}
}
#[test]
fn test_batch5_universal_count() {
let universal_rules = vec![
"SC2001", "SC2005", "SC2006", "SC2007", "SC2015", "SC2016", "SC2017", "SC2018", "SC2019", "SC2020", "SC2021", "SC2022", "SC2023", "SC2024", "SC2025", "SC2026", "SC2027", "SC2028", "SC2029", "SC2086",
];
let unique_count = universal_rules.len();
assert_eq!(unique_count, 20, "Batch 5 should have 20 Universal rules");
for rule in universal_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
}
}
#[test]
fn test_batch6_variable_function_safety_universal() {
let variable_rules = vec!["SC2033", "SC2034", "SC2035"];
for rule in variable_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch6_command_best_practices_universal() {
let command_rules = vec!["SC2099", "SC2100", "SC2101", "SC2102", "SC2106", "SC2117"];
for rule in command_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch6_ksh_specific_notsh() {
let rule = "SC2118";
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh (ksh-specific)",
rule
);
assert!(
!should_apply_rule(rule, ShellType::Sh),
"{} should not apply to sh",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Zsh),
"{} should apply to zsh",
rule
);
}
#[test]
fn test_batch6_quality_efficiency_universal() {
let quality_rules = vec![
"SC2121", "SC2122", "SC2126", "SC2127", "SC2129", "SC2130", "SC2131", "SC2132", "SC2135",
"SC2136",
];
for rule in quality_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch6_universal_count() {
let universal_rules = vec![
"SC2033", "SC2034", "SC2035", "SC2099", "SC2100", "SC2101", "SC2102", "SC2106", "SC2117",
"SC2121", "SC2122", "SC2126", "SC2127", "SC2129", "SC2130", "SC2131", "SC2132", "SC2135",
"SC2136",
];
let unique_count = universal_rules.len();
assert_eq!(unique_count, 19, "Batch 6 should have 19 Universal rules");
for rule in universal_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
}
assert_eq!(
get_rule_compatibility("SC2118"),
Some(ShellCompatibility::NotSh),
"SC2118 should be NotSh"
);
}
#[test]
fn test_batch7_alias_function_context_universal() {
let alias_function_rules = vec!["SC2138", "SC2139", "SC2140", "SC2141", "SC2142"];
for rule in alias_function_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}
#[test]
fn test_batch7_find_glob_efficiency_universal() {
let find_glob_rules = vec![
"SC2143", "SC2144", "SC2145", "SC2146", "SC2147", "SC2148", "SC2149", "SC2150",
];
for rule in find_glob_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
assert!(
should_apply_rule(rule, ShellType::Bash),
"{} should apply to bash",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
}
}