scmb_expand_args: return an array to fix quoting issues

This commit is contained in:
Tom "Ravi" Hale
2018-08-25 20:30:42 +07:00
parent fb7d227c30
commit 73ed8cb53e
2 changed files with 28 additions and 26 deletions

View File

@@ -49,16 +49,22 @@ setupTestRepo() {
#-----------------------------------------------------------------------------
test_scmb_expand_args() {
local e1="one"; local e2="two"; local e3="three"; local e4="four"; local e5="five"; local e6="six"; local e7="seven"
local e1="one" e2="two" e3="three" e4="four" e5="five" e6="six" e7='$dollar' e8='two words'
local error="Args not expanded correctly"
assertEquals "$error" "$(printf 'one\tthree\tseven')" "$(scmb_expand_args 1 3 7)"
assertEquals "$error" "$(printf 'one\ttwo\tthree\tsix')" "$(scmb_expand_args 1-3 6)"
assertEquals "$error" "$(printf 'seven\ttwo\tthree\tfour\tfive\tone')" "$(scmb_expand_args seven 2-5 1)"
assertEquals "$error" "'one' 'three' 'six'" \
"$(eval a=$(scmb_expand_args 1 3 6); token_quote "${a[@]}")"
assertEquals "$error" "'one' 'two' 'three' 'five'" \
"$(eval a=$(scmb_expand_args 1-3 5); token_quote "${a[@]}")"
assertEquals "$error" "'\$dollar' 'two' 'three' 'four' 'one'" \
"$(eval a=$(scmb_expand_args 7 2-4 1); token_quote "${a[@]}")"
# Test that any args with spaces remain quoted
assertEquals "$error" "$(printf -- '-m\tTest Commit Message\tone')" "$(scmb_expand_args -m "Test Commit Message" 1)"
assertEquals "$error" "$(printf -- '-ma\tTest Commit Message\tUnquoted')"\
"$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"
assertEquals "$error" "'-m' 'Test Commit Message' 'one'" \
"$(eval a=$(scmb_expand_args -m "Test Commit Message" 1); token_quote "${a[@]}")"
assertEquals "$error" "'-ma' 'Test Commit Message' 'Unquoted'"\
"$(eval a=$(scmb_expand_args -ma "Test Commit Message" "Unquoted"); token_quote "${a[@]}")"
assertEquals "$error" "'\$dollar' 'one' 'two words'" \
"$(eval a=$(scmb_expand_args 7 1-1 8); token_quote "${a[@]}")"
}
test_command_wrapping_escapes_special_characters() {