Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 17, 2025
1 parent 5ef658d commit c9c18e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions error
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./test/test_compound.bash
./test/test_compound.bash
20 changes: 17 additions & 3 deletions src/elements/command/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl CaseCommand {
}

let mut ans = Self::new();
// let mut ok = false;
ans.text = feeder.consume(4);
let mut esac = false;

if ! Self::eat_word(feeder, &mut ans, core)?
|| ! feeder.starts_with("in") {
Expand All @@ -138,8 +138,8 @@ impl CaseCommand {
}

if feeder.starts_with("esac") {
// ok = true;
ans.text += &feeder.consume(4);
esac = true;
break;
}

Expand All @@ -164,7 +164,21 @@ impl CaseCommand {
}
}

if /*ok &&*/ ans.patterns_script_end.len() > 0 {
if ! esac {
if feeder.len() == 0 {
feeder.feed_additional_line(core)?;
}
command::eat_blank_with_comment(feeder, core, &mut ans.text);
if feeder.starts_with("\n") {
ans.text += &feeder.consume(1);
}
if feeder.starts_with("esac") {
ans.text += &feeder.consume(4);
esac = true;
}
}

if esac && ans.patterns_script_end.len() > 0 {
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
Ok(Some(ans))
}else{
Expand Down
2 changes: 1 addition & 1 deletion test/ok
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
./test_script.bash
./test_options.bash
./test_redirects.bash
./test_glob.bash
./test_redirects.bash
./test_brace.bash
./test_builtins.bash
./test_others.bash
Expand Down
9 changes: 9 additions & 0 deletions test/test_compound.bash
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ res=$($com <<< 'case aaa in bbb) echo NG ;; aaa) echo OK ;;& aaa) echo OK ;; esa
[ "$res" = "OK
OK" ] || err $LINENO

res=$($com <<< 'case aaa in
bbb) echo NG ;;
aaa) echo OK ;;&
aaa) echo OK ;;
')
[ "$res" = "" ] || err $LINENO


res=$($com <<< 'case aaa in aaa) echo OK1 ;;& bbb) echo OK2 ;& aaa) echo OK3 ;; esac')
[ "$res" = "OK1
OK3" ] || err $LINENO
Expand Down

0 comments on commit c9c18e3

Please sign in to comment.