aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2018-01-15 11:31:02 +0100
committerKate Ward <kate.ward@forestent.com>2018-01-15 11:31:02 +0100
commita8e81fdb77b054dc28987af82e53ab9a0c107d20 (patch)
tree24cc7ecbe70d62358af67399248ebd7da5b26ad3
parente563d4c1731683908c05782f07bfac48856f3139 (diff)
downloadshflags-a8e81fdb77b054dc28987af82e53ab9a0c107d20.tar.gz
Added unit test for underscoreName(), and fixed potential POSIX compliance issue.
-rw-r--r--shflags2
-rwxr-xr-xshflags_private_test.sh15
2 files changed, 14 insertions, 3 deletions
diff --git a/shflags b/shflags
index 672ac39..c8dd5fe 100644
--- a/shflags
+++ b/shflags
@@ -427,7 +427,7 @@ _flags_define() {
# Output:
# string: underscored name
_flags_underscoreName() {
- echo "$1" |tr '-' '_'
+ echo "$1" |tr z- z_
}
# Return valid getopt options using currently defined list of long options.
diff --git a/shflags_private_test.sh b/shflags_private_test.sh
index 5a2b442..e6b6376 100755
--- a/shflags_private_test.sh
+++ b/shflags_private_test.sh
@@ -3,8 +3,7 @@
#
# shFlags unit tests for the internal functions.
#
-#
-# Copyright 2008-2017 Kate Ward. All Rights Reserved.
+# Copyright 2008-2018 Kate Ward. All Rights Reserved.
# Released under the Apache 2.0 license.
#
# Author: kate.ward@forestent.com (Kate Ward)
@@ -113,6 +112,18 @@ EOF
assertFalse 'empty lists should not match' $?
}
+testUnderscoreName() {
+ while read desc name want; do
+ got=`_flags_underscoreName "${name}"`
+ assertEquals "${desc}: underscoreName(${name})" "${got}" "${want}"
+ done <<EOF
+with_dashes name-with-dashes name_with_dashes
+with_underscores name_with_underscores name_with_underscores
+just_alpha_numeric abc123 abc123
+empty "" ""
+EOF
+}
+
testValidBool() {
# Valid values.
for value in ${TH_BOOL_VALID}; do