Skip to content

Commit

Permalink
Implementing word
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 31, 2024
1 parent 6ee981b commit 5d92bc7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/elements/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,7 +72,7 @@ impl Word {
if ans.text.len() == 0 {
None
}else{
dbg!("{:?}", &ans);
//dbg!("{:?}", &ans);
Some(ans)
}
}
Expand Down
87 changes: 87 additions & 0 deletions test/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d92bc7

Please sign in to comment.