use super::*;
use crate::linter::shell_type::ShellType;
#[test]
fn test_batch17_bash_specific_notsh() {
let bash_specific_rules = vec![
(
"SC2292",
"Prefer ${var:0:1} over expr substr - bash substring expansion",
),
("SC2293", "Use += to append to arrays - bash array operator"),
(
"SC2301",
"Use [[ -v array[0] ]] to check if array element exists - arrays + [[ -v ]]",
),
(
"SC2302",
"Prefer ${var// /} over tr - bash ${var//} expansion",
),
];
for (rule, description) in bash_specific_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"Batch 17 bash-specific rule {} ({}) should be NotSh",
rule,
description
);
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_batch17_split_universal_vs_notsh() {
let universal_rules = vec![
"SC2036", "SC2037", "SC2119", "SC2123", "SC2125",
"SC2294", "SC2295", "SC2296", "SC2297", "SC2298", "SC2299", "SC2300", "SC2303", "SC2304",
"SC2305", "SC2319",
];
let notsh_rules = vec![
"SC2124", "SC2292", "SC2293", "SC2301", "SC2302", ];
for rule in &universal_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::Universal),
"Batch 17 rule {} should be Universal",
rule
);
}
for rule in ¬sh_rules {
assert_eq!(
get_rule_compatibility(rule),
Some(ShellCompatibility::NotSh),
"Batch 17 rule {} should be NotSh",
rule
);
}
assert_eq!(
universal_rules.len(),
16,
"Batch 17 should have 16 Universal rules"
);
assert_eq!(notsh_rules.len(), 5, "Batch 17 should have 5 NotSh rules");
}