diff --git a/src/elements/subword/braced_param.rs b/src/elements/subword/braced_param.rs index 17016a67..17a3d04a 100644 --- a/src/elements/subword/braced_param.rs +++ b/src/elements/subword/braced_param.rs @@ -75,27 +75,7 @@ impl Subword for BracedParam { } if self.has_offset { - match self.offset.clone() { - None => { - eprintln!("sush: {}: bad substitution", &self.text); - return false; - }, - Some(mut offset) => { - if offset.text == "" { - eprintln!("sush: {}: bad substitution", &self.text); - return false; - } - match offset.eval(core) { - None => return false, - Some(s) => match s.parse::() { - Ok(n) => { - self.text = self.text.chars().enumerate().filter(|(i, _)| i >= &n).map(|(_, c)| c).collect(); - }, - _ => return false, - } - } - }, - } + return self.offset(core); } match self.alternative_symbol.as_deref() { @@ -138,6 +118,32 @@ impl BracedParam { } } + fn offset(&mut self, core: &mut ShellCore) -> bool { + let mut offset = match self.offset.clone() { + None => { + eprintln!("sush: {}: bad substitution", &self.text); + return false; + }, + Some(ofs) => ofs, + }; + + if offset.text == "" { + eprintln!("sush: {}: bad substitution", &self.text); + return false; + } + + match offset.eval(core) { + None => return false, + Some(s) => match s.parse::() { + Ok(n) => { + self.text = self.text.chars().enumerate().filter(|(i, _)| i >= &n).map(|(_, c)| c).collect(); + }, + _ => return false, + } + } + true + } + fn replace_to_alternative(&mut self, core: &mut ShellCore) -> bool { let symbol = match self.alternative_symbol.as_ref() { Some(s) => s, diff --git a/test/ok b/test/ok index e4888750..bb403ea0 100644 --- a/test/ok +++ b/test/ok @@ -4,4 +4,3 @@ ./test_compound.bash ./test_others.bash ./test_job.bash -../../../test/test_others.bash diff --git a/test/test_others.bash b/test/test_others.bash index bbc63662..b09d86cf 100755 --- a/test/test_others.bash +++ b/test/test_others.bash @@ -130,6 +130,9 @@ res=$($com <<< 'A=あいうえお; echo ${A:}' ) [ "$?" = 1 ] || err $LINENO [ "$res" = "" ] || err $LINENO +res=$($com <<< 'A=あ; echo ${A: }' ) +[ "$res" = "あ" ] || err $LINENO + res=$($com <<< 'A=あいうえお; echo ${A:6}' ) [ "$res" = "" ] || err $LINENO