use super::*;
use crate::linter::shell_type::ShellType;
#[test]
fn test_batch7_exit_code_safety_universal() {
let exit_code_rules = vec![
"SC2151", "SC2152", "SC2153", "SC2154", "SC2155", "SC2156", "SC2157",
];
for rule in exit_code_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_universal_count() {
let universal_rules = vec![
"SC2138", "SC2139", "SC2140", "SC2141", "SC2142", "SC2143", "SC2144", "SC2145", "SC2146", "SC2147", "SC2148", "SC2149", "SC2150",
"SC2151", "SC2152", "SC2153", "SC2154", "SC2155", "SC2156", "SC2157",
];
let unique_count = universal_rules.len();
assert_eq!(unique_count, 20, "Batch 7 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_batch7_no_notsh_rules() {
let batch7_rules = vec![
"SC2138", "SC2139", "SC2140", "SC2141", "SC2142", "SC2143", "SC2144", "SC2145", "SC2146",
"SC2147", "SC2148", "SC2149", "SC2150", "SC2151", "SC2152", "SC2153", "SC2154", "SC2155",
"SC2156", "SC2157",
];
for rule in batch7_rules {
let compat = get_rule_compatibility(rule);
assert_eq!(
compat,
Some(ShellCompatibility::Universal),
"{} should be Universal (not NotSh)",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should 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
);
assert!(
should_apply_rule(rule, ShellType::Ksh),
"{} should apply to ksh",
rule
);
}
}
#[test]
fn test_batch8_exit_code_bracket_universal() {
let exit_bracket_rules = vec!["SC2158", "SC2159", "SC2160", "SC2161"];
for rule in exit_bracket_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
);
assert!(
should_apply_rule(rule, ShellType::Zsh),
"{} should apply to zsh",
rule
);
assert!(
should_apply_rule(rule, ShellType::Ksh),
"{} should apply to ksh",
rule
);
}
}
#[test]
fn test_batch8_read_trap_safety_universal() {
let read_trap_rules = vec!["SC2162", "SC2163", "SC2164", "SC2165", "SC2166", "SC2167"];
for rule in read_trap_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
);
assert!(
should_apply_rule(rule, ShellType::Zsh),
"{} should apply to zsh",
rule
);
}
}
#[test]
fn test_batch8_local_keyword_notsh() {
let rule = "SC2168";
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh (local is bash/ksh/zsh 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
);
assert!(
should_apply_rule(rule, ShellType::Ksh),
"{} should apply to ksh",
rule
);
}
#[test]
fn test_batch8_test_operators_universal() {
let test_security_rules = vec![
"SC2169", "SC2170", "SC2171", "SC2172", "SC2173", "SC2174", "SC2175", "SC2176", "SC2177",
];
for rule in test_security_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
);
assert!(
should_apply_rule(rule, ShellType::Zsh),
"{} should apply to zsh",
rule
);
}
}
#[test]
fn test_batch8_universal_count() {
let universal_rules = vec![
"SC2158", "SC2159", "SC2160", "SC2161", "SC2162", "SC2163", "SC2164", "SC2165", "SC2166", "SC2167", "SC2169", "SC2170", "SC2171", "SC2172", "SC2173", "SC2174", "SC2175", "SC2176", "SC2177",
];
let unique_count = universal_rules.len();
assert_eq!(unique_count, 19, "Batch 8 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("SC2168"),
Some(ShellCompatibility::NotSh),
"SC2168 should be NotSh (local keyword is bash/ksh/zsh specific)"
);
}
#[test]
fn test_batch9_array_operations_notsh() {
let array_rules = vec!["SC2178", "SC2179", "SC2180"];
for rule in array_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh (arrays are bash/zsh/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_batch9_associative_arrays_notsh() {
let assoc_array_rules = vec!["SC2190", "SC2191"];
for rule in assoc_array_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh (associative arrays are bash 4+/zsh specific)",
rule
);
assert!(
!should_apply_rule(rule, ShellType::Sh),
"{} should not apply to sh",
rule
);
}
}