Skip to content

Commit 0411268

Browse files
committed
Implement ${A-hogehoge} and ${A+hogehoge} temporary
1 parent 6b7b0c8 commit 0411268

File tree

7 files changed

+35
-4
lines changed

7 files changed

+35
-4
lines changed

src/core/builtins/unset.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ fn unset_function(core: &mut ShellCore, name: &str) -> i32 {
1919
}
2020

2121
pub fn unset(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
22+
if args.len() < 2 {
23+
return 0;
24+
}
25+
2226
match args[1].as_ref() {
2327
"-f" => {
2428
if args.len() > 2 {

src/elements/subword/braced_param.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl Subword for BracedParam {
5050
return false;
5151
}
5252
if self.unknown.len() > 0
53-
&& ! self.unknown.starts_with("-")
5453
&& ! self.unknown.starts_with(",") {
5554
eprintln!("sush: {}: bad substitution", &self.text);
5655
return false;
@@ -72,7 +71,13 @@ impl Subword for BracedParam {
7271
};
7372
}
7473

75-
match self.default_symbol.as_ref() {
74+
match self.default_symbol.as_deref() {
75+
Some("-") => {
76+
self.default_value = None;
77+
self.default_symbol = None;
78+
return true;
79+
},
80+
Some("+") => return true,
7681
Some(s) => if s == ":+" || self.text == "" {
7782
return self.replace_to_default(core);
7883
},

src/elements/subword/error

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
../../../test/test_others.bash
22
../../../test/test_others.bash
3+
../../../test/test_others.bash
4+
../../../test/test_others.bash

src/feeder/scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl Feeder {
276276
}
277277

278278
pub fn scanner_parameter_default_symbol(&mut self) -> usize {
279-
self.scanner_one_of(&[":-", ":=", ":?", ":+"])
279+
self.scanner_one_of(&[":-", ":=", ":?", ":+", "-", "+"])
280280
}
281281

282282
pub fn scanner_test_check_option(&mut self, core: &mut ShellCore) -> usize {

test/error

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
./test_others.bash
2+
../../../test/test_others.bash
3+
../../../test/test_others.bash
4+
../../../test/test_others.bash
5+
../../../test/test_others.bash
6+
../../../test/test_others.bash
7+
../../../test/test_others.bash
8+
../../../test/test_others.bash

test/ok

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
./test_builtins.bash
33
./test_brace.bash
44
./test_compound.bash
5-
./test_others.bash
65
./test_job.bash
6+
../../../test/test_others.bash
7+
../../../test/test_others.bash
8+
../../../test/test_others.bash
9+
../../../test/test_others.bash
10+
../../../test/test_others.bash
11+
../../../test/test_others.bash
12+
../../../test/test_others.bash

test/test_others.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ ok" ] || err $LINENO
7979
res=$($com <<< 'A=aaa ; echo ${A- - - - -}' )
8080
[ "$res" = "aaa" ] || err $LINENO
8181

82+
res=$($com <<< 'A=aaa ; echo ${A+- - - - bbb}' )
83+
[ "$res" = "- - - - bbb" ] || err $LINENO
84+
85+
res=$($com <<< 'A= ; echo ${A+- - - - bbb}' )
86+
[ "$res" = "- - - - bbb" ] || err $LINENO
87+
8288
res=$($com <<< 'echo ${A:- abc}' )
8389
[ "$res" = "abc" ] || err $LINENO
8490

0 commit comments

Comments
 (0)