diff --git a/src/elements/word.rs b/src/elements/word.rs index c6f17bd6..573b995e 100644 --- a/src/elements/word.rs +++ b/src/elements/word.rs @@ -45,7 +45,15 @@ impl Word { if feeder.len() == 0 { break; - }else if left == "{" && feeder.starts_with(",") { + }else if feeder.starts_with("{"){ + let c = feeder.consume(1); + ans.text += &c; + let sw = UnquotedSubword::new(&c); + ans.subwords.push(Box::new(sw)); + continue; + } + + if left == "{" && feeder.starts_with(",") { break; }else if left == "," && ( feeder.starts_with(",") || feeder.starts_with("}") ) { break; @@ -64,7 +72,7 @@ impl Word { if ans.text.len() == 0 { None }else{ - dbg!("{:?}", &ans); + //dbg!("{:?}", &ans); Some(ans) } } diff --git a/test/test.bash b/test/test.bash index b9ea0c50..b527fd77 100755 --- a/test/test.bash +++ b/test/test.bash @@ -336,6 +336,93 @@ res=$($com <<< 'touch /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo w res=$($com <<< 'rm -f /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo wait ; rm /tmp/rusty_bash ; done') [ "$res" == "" ] || err $LINENO +### ARG TEST ### + +# brace + +res=$($com <<< 'echo {a,b}c') +[ "$res" == "{a,b}c" ] || err $LINENO +#[ "$res" == "ac bc" ] || err $LINENO + +res=$($com <<< 'echo c{a,b}') +[ "$res" == "c{a,b}" ] || err $LINENO +#[ "$res" == "ca cb" ] || err $LINENO + +res=$($com <<< 'echo {{a},b}') +[ "$res" == "{{a},b}" ] || err $LINENO +#[ "$res" == "{a} b" ] || err $LINENO + +res=$($com <<< 'echo {a,{b},c}') +[ "$res" == "{a,{b},c}" ] || err $LINENO +#[ "$res" == "a {b} c" ] || err $LINENO + +res=$($com <<< 'echo {a,b,c{d,e}f,g{h,i{j,k}}}') +[ "$res" == "{a,b,c{d,e}f,g{h,i{j,k}}}" ] || err $LINENO +#[ "$res" == "a b cdf cef gh gij gik" ] || err $LINENO + +res=$($com <<< 'echo {a,b,c{d,e}f,g{h,i{j,k}}') +[ "$res" == "{a,b,c{d,e}f,g{h,i{j,k}}" ] || err $LINENO +#[ "$res" == "{a,b,cdf,gh {a,b,cdf,gij {a,b,cdf,gik {a,b,cef,gh {a,b,cef,gij {a,b,cef,gik" ] || err $LINENO + +res=$($com <<< 'echo c{a,b') +[ "$res" == "c{a,b" ] || err $LINENO + +res=$($com <<< 'echo c{a,b,') +[ "$res" == "c{a,b," ] || err $LINENO + +res=$($com <<< 'echo {{a,b},{c,d},') +[ "$res" == "{{a,b},{c,d}," ] || err $LINENO +#[ "$res" == "{a,c, {a,d, {b,c, {b,d," ] || err $LINENO + +res=$($com <<< 'echo {{a,b},{c,d') +[ "$res" == "{{a,b},{c,d" ] || err $LINENO +#[ "$res" == "{a,{c,d {b,{c,d" ] || err $LINENO + +res=$($com <<< 'echo {{a,b,{c,') +[ "$res" == "{{a,b,{c," ] || err $LINENO + +res=$($com <<< 'echo {a}') +[ "$res" == "{a}" ] || err $LINENO + +res=$($com <<< 'echo {a,}') +[ "$res" == "{a,}" ] || err $LINENO +#[ "$res" == "a" ] || err $LINENO + +res=$($com <<< 'echo {a,b,}') +[ "$res" == "{a,b,}" ] || err $LINENO +#[ "$res" == "a b" ] || err $LINENO + +res=$($com <<< 'echo {a,b,}c') +[ "$res" == "{a,b,}c" ] || err $LINENO +#[ "$res" == "ac bc c" ] || err $LINENO + +res=$($com <<< 'echo {}') +[ "$res" == "{}" ] || err $LINENO + +res=$($com <<< 'echo {,}') +[ "$res" == "{,}" ] || err $LINENO +#[ "$res" == "" ] || err $LINENO + +res=$($com <<< 'echo {,,}') +[ "$res" == "{,,}" ] || err $LINENO +#[ "$res" == "" ] || err $LINENO + +res=$($com <<< 'echo a{,,}b') +[ "$res" == "a{,,}b" ] || err $LINENO +#[ "$res" == "ab ab ab" ] || err $LINENO + +res=$($com <<< 'echo {') +[ "$res" == "{" ] || err $LINENO + +res=$($com <<< 'echo }') +[ "$res" == "}" ] || err $LINENO + +res=$($com <<< 'echo {a,}{b,}') +[ "$res" == "{a,}{b,}" ] || err $LINENO +#[ "$res" == "ab a b" ] || err $LINENO + +### WHILE TEST ### + res=$($com <<< 'touch /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo wait ; rm /tmp/rusty_bash ; done > /tmp/rusty_bash1'; cat /tmp/rusty_bash1 ; cat /tmp/rusty_bash1 ) [ "$res" == "wait wait" ] || err $LINENO