use super::*;
#[test]
fn test_should_skip_line_comment() {
assert!(should_skip_line("# this is a comment"));
assert!(should_skip_line(" # indented comment"));
}
#[test]
fn test_should_skip_line_assignment() {
assert!(should_skip_line("FOO=bar baz")); assert!(!should_skip_line("VAR=value"));
}
#[test]
fn test_should_skip_line_not_assignment() {
assert!(!should_skip_line("echo $VAR"));
assert!(!should_skip_line("ls -la"));
assert!(!should_skip_line("if [ $x = 1 ]; then")); }
#[test]
fn test_should_skip_line_if_bracket() {
assert!(!should_skip_line("if [ $x = 1 ]; then"));
assert!(!should_skip_line("[ $x = 1 ]"));
}
#[test]
fn test_should_skip_line_equals_after_space() {
assert!(!should_skip_line("echo x = y")); }
#[test]
fn test_should_skip_line_no_space() {
assert!(!should_skip_line("VAR=value"));
}
#[test]
fn test_find_dollar_position_simple() {
let line = "echo $VAR";
assert_eq!(find_dollar_position(line, 6), 5); }
#[test]
fn test_find_dollar_position_braced() {
let line = "echo ${VAR}";
assert_eq!(find_dollar_position(line, 7), 5); }
#[test]
fn test_find_dollar_position_multiple() {
let line = "echo $A $B";
assert_eq!(find_dollar_position(line, 9), 8);
}
#[test]
fn test_calculate_end_column_simple() {
let line = "echo $VAR more";
assert_eq!(calculate_end_column(line, 9, false), 10);
}
#[test]
fn test_calculate_end_column_braced() {
let line = "echo ${VAR} more";
assert_eq!(calculate_end_column(line, 10, true), 12);
}
#[test]
fn test_calculate_end_column_braced_no_brace() {
let line = "echo ${VAR";
assert_eq!(calculate_end_column(line, 10, true), 11);
}
#[test]
fn test_is_in_arithmetic_context_command_sub() {
let line = "x=$(( a + b ))";
assert!(is_in_arithmetic_context(line, 6, 7));
}
#[test]
fn test_is_in_arithmetic_context_standalone() {
let line = "(( i++ ))";
assert!(is_in_arithmetic_context(line, 3, 4));
}
#[test]
fn test_is_in_arithmetic_context_for_loop() {
let line = "for (( i=0; i<$n; i++ )); do";
assert!(is_in_arithmetic_context(line, 14, 16));
}
#[test]
fn test_is_in_arithmetic_context_not_arithmetic() {
let line = "echo $VAR";
assert!(!is_in_arithmetic_context(line, 5, 8));
}
#[test]
fn test_get_cstyle_for_loop_vars_single() {
let source = "for (( i=0; i<10; i++ )); do echo $i; done";
let vars = get_cstyle_for_loop_vars(source);
assert!(vars.contains("i"));
assert_eq!(vars.len(), 1);
}
#[test]
fn test_get_cstyle_for_loop_vars_multiple() {
let source = "for ((i=0; i<10; i++)); do\n for ((j=0; j<5; j++)); do\n echo\n done\ndone";
let vars = get_cstyle_for_loop_vars(source);
assert!(vars.contains("i"));
assert!(vars.contains("j"));
assert_eq!(vars.len(), 2);
}
#[test]
fn test_get_cstyle_for_loop_vars_none() {
let source = "for item in *.txt; do echo $item; done";
let vars = get_cstyle_for_loop_vars(source);
assert!(vars.is_empty());
}
#[test]
fn test_is_in_double_bracket_context_true() {
let line = "[[ -n $var ]]";
assert!(is_in_double_bracket_context(line, 6, 10));
}
#[test]
fn test_is_in_double_bracket_context_false_single() {
let line = "[ -n $var ]";
assert!(!is_in_double_bracket_context(line, 5, 9));
}
#[test]
fn test_is_in_double_bracket_context_comparison() {
let line = "[[ $a == $b ]]";
assert!(is_in_double_bracket_context(line, 3, 5));
}
#[test]
fn test_is_already_quoted_simple() {
let line = r#"echo "$VAR""#;
assert!(is_already_quoted(line, 6, 10));
}
#[test]
fn test_is_already_quoted_braced() {
let line = r#"echo "${VAR}""#;
assert!(is_already_quoted(line, 6, 11));
}
#[test]
fn test_is_already_quoted_inside_string() {
let line = r#"echo "prefix${VAR}suffix""#;
assert!(is_already_quoted(line, 13, 18));
}
#[test]
fn test_is_already_quoted_not_quoted() {
let line = "echo $VAR";
assert!(!is_already_quoted(line, 5, 9));
}
#[test]
fn test_is_already_quoted_edge_case() {
let line = r#"echo \"$VAR""#;
assert!(is_already_quoted(line, 7, 11));
}
#[test]
fn test_is_already_quoted_braced_not_immediately() {
let line = r#"cmd ${VAR}end"#;
assert!(!is_already_quoted(line, 4, 8));
#[test]
fn test_is_already_quoted_odd_quote_braced() {
let line = r#"x="prefix${VAR}suffix""#;
assert!(is_already_quoted(line, 10, 14));
}
#[test]
fn test_is_already_quoted_escaped_quote_before() {
let line = r#"echo \"$VAR"#;
assert!(!is_already_quoted(line, 7, 11));
}
#[test]
fn test_format_var_text_simple() {
assert_eq!(format_var_text("VAR", false), "$VAR");
assert_eq!(format_var_text("foo", false), "$foo");
}
#[test]
fn test_format_var_text_braced() {
assert_eq!(format_var_text("VAR", true), "${VAR}");
assert_eq!(format_var_text("foo", true), "${foo}");
}
#[test]
fn test_format_quoted_var_simple() {
assert_eq!(format_quoted_var("VAR", false), "\"$VAR\"");
}
#[test]
fn test_format_quoted_var_braced() {
assert_eq!(format_quoted_var("VAR", true), "\"${VAR}\"");
}
#[test]
fn test_line_has_arithmetic_markers_command_sub() {
assert!(line_has_arithmetic_markers("x=$(( a + b ))"));
}
#[test]
fn test_line_has_arithmetic_markers_standalone() {
assert!(line_has_arithmetic_markers("(( i++ ))"));
}
#[test]
fn test_line_has_arithmetic_markers_none() {
assert!(!line_has_arithmetic_markers("echo $VAR"));
assert!(!line_has_arithmetic_markers("ls -la"));
}
}