#![allow(clippy::unwrap_used)] #![allow(clippy::expect_used)]
use bashrs::linter::{lint_shell_with_path, LintResult};
use std::path::PathBuf;
#[test]
fn test_issue_005_zshrc_uses_zsh_rules() {
let zshrc_content = r#"#!/usr/bin/env zsh
# Valid zsh array splitting
filtered_args=("${(@f)"$(echo -e "line1\nline2")"}")
echo "${filtered_args[*]}"
"#;
let path = PathBuf::from(".zshrc");
let result = lint_shell_with_path(&path, zshrc_content);
assert!(
!contains_code(&result, "SC2296"),
"SC2296 (nested parameter expansion) should not be flagged for zsh"
);
}
#[test]
fn test_issue_005_bash_file_uses_bash_rules() {
let bashrc_content = r#"#!/bin/bash
# This would be invalid in bash
x=$RANDOM
echo $x
"#;
let path = PathBuf::from(".bashrc");
let _result = lint_shell_with_path(&path, bashrc_content);
}
#[test]
fn test_issue_005_shebang_overrides_extension() {
let content = r#"#!/bin/bash
# This is bash despite .zsh extension
echo "hello"
"#;
let path = PathBuf::from("script.zsh");
let _result = lint_shell_with_path(&path, content);
}
#[test]
fn test_issue_005_shellcheck_directive_overrides_all() {
let content = r#"#!/bin/bash
# shellcheck shell=zsh
# This forces zsh rules despite bash shebang
echo "hello"
"#;
let path = PathBuf::from("test.sh");
let _result = lint_shell_with_path(&path, content);
}
fn contains_code(result: &LintResult, code: &str) -> bool {
result.diagnostics.iter().any(|d| d.code == code)
}