use super::*;
use crate::linter::shell_type::ShellType;
#[test]
fn test_sec_rules_are_universal() {
for i in 1..=8 {
let rule_id = format!("SEC{:03}", i);
let compat = get_rule_compatibility(&rule_id);
assert_eq!(compat, Some(ShellCompatibility::Universal));
}
}
#[test]
fn test_det_rules_are_universal() {
for i in 1..=3 {
let rule_id = format!("DET{:03}", i);
let compat = get_rule_compatibility(&rule_id);
assert_eq!(compat, Some(ShellCompatibility::Universal));
}
}
#[test]
fn test_idem_rules_are_universal() {
for i in 1..=3 {
let rule_id = format!("IDEM{:03}", i);
let compat = get_rule_compatibility(&rule_id);
assert_eq!(compat, Some(ShellCompatibility::Universal));
}
}
#[test]
fn test_should_apply_universal_rules_to_all_shells() {
let shells = vec![
ShellType::Bash,
ShellType::Zsh,
ShellType::Sh,
ShellType::Ksh,
ShellType::Auto,
];
for shell in shells {
assert!(should_apply_rule("SEC001", shell));
assert!(should_apply_rule("DET001", shell));
assert!(should_apply_rule("IDEM001", shell));
}
}
#[test]
fn test_unknown_rule_defaults_to_universal() {
assert!(should_apply_rule("UNKNOWN999", ShellType::Bash));
assert!(should_apply_rule("UNKNOWN999", ShellType::Zsh));
assert!(should_apply_rule("UNKNOWN999", ShellType::Sh));
}
#[test]
fn test_registry_has_373_rules() {
assert_eq!(RULE_REGISTRY.len(), 396);
}
#[test]
fn test_bash_specific_rules_not_sh() {
assert_eq!(
get_rule_compatibility("SC2198"),
Some(ShellCompatibility::NotSh)
);
assert_eq!(
get_rule_compatibility("SC2199"),
Some(ShellCompatibility::NotSh)
);
assert_eq!(
get_rule_compatibility("SC2039"),
Some(ShellCompatibility::NotSh)
);
}
#[test]
fn test_should_skip_bash_rules_for_sh() {
assert!(!should_apply_rule("SC2198", ShellType::Sh));
assert!(!should_apply_rule("SC2199", ShellType::Sh));
assert!(should_apply_rule("SC2198", ShellType::Bash));
assert!(should_apply_rule("SC2198", ShellType::Zsh));
}
#[test]
fn test_double_bracket_rules_not_sh() {
let double_bracket_rules = vec!["SC2108", "SC2109", "SC2110"];
for rule in double_bracket_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh",
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_function_keyword_rules_not_sh() {
let function_rules = vec!["SC2111", "SC2112", "SC2113"];
for rule in function_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"{} should be NotSh",
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
);
}
}
#[test]
fn test_arithmetic_rules_universal() {
let arithmetic_rules = vec![
"SC2003", "SC2004", "SC2079", "SC2080", "SC2084", "SC2085", "SC2133", "SC2134", "SC2137",
];
for rule in arithmetic_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::Zsh),
"{} should apply to zsh",
rule
);
assert!(
should_apply_rule(rule, ShellType::Sh),
"{} should apply to sh",
rule
);
assert!(
should_apply_rule(rule, ShellType::Ksh),
"{} should apply to ksh",
rule
);
}
}
#[test]
fn test_quoting_rules_universal() {
let quoting_rules = vec![
"SC2030", "SC2031", "SC2032", "SC2087", "SC2088", "SC2089", "SC2090", "SC2091", "SC2092",
"SC2093",
];
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_batch2_notsh_count() {
let notsh_rules = vec![
"SC2108", "SC2109", "SC2110", "SC2111", "SC2112", "SC2113", ];
for rule in notsh_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh)
);
}
}
#[test]
fn test_batch2_universal_count() {
let universal_rules = vec![
"SC2003", "SC2004", "SC2079", "SC2080", "SC2084", "SC2085", "SC2133", "SC2134",
"SC2137", "SC2030", "SC2031", "SC2032", "SC2087", "SC2088", "SC2089", "SC2090", "SC2091", "SC2092",
"SC2093",
];
assert_eq!(universal_rules.len(), 19);
for rule in universal_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal)
);
}
}
#[test]
fn test_batch3_loop_safety_rules_universal() {
let loop_rules = vec!["SC2038", "SC2040", "SC2041", "SC2042", "SC2043"];
for rule in loop_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_batch3_test_operators_mostly_universal() {
let universal_test_rules = vec![
"SC2045", "SC2046", "SC2047", "SC2048", "SC2049", "SC2050", "SC2051",
];
for rule in universal_test_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"{} should be Universal",
rule
);
}
assert_eq!(
get_rule_compatibility("SC2044"),
Some(ShellCompatibility::NotSh),
"SC2044 should be NotSh (process substitution)"
);
assert_eq!(
get_rule_compatibility("SC2052"),
Some(ShellCompatibility::NotSh),
"SC2052 should be NotSh ([[ ]] syntax)"
);
}
#[test]
fn test_batch3_critical_security_rules_universal() {
let critical_rules = vec![
("SC2059", "Printf format string injection"),
("SC2064", "Trap command timing bug"),
];
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]
include!("rule_registry_tests_tests_batch3_quoti.rs");