summaryrefslogtreecommitdiff
path: root/test/unit/_parse_usage.exp
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/_parse_usage.exp')
-rw-r--r--test/unit/_parse_usage.exp59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/unit/_parse_usage.exp b/test/unit/_parse_usage.exp
new file mode 100644
index 00000000..0069848d
--- /dev/null
+++ b/test/unit/_parse_usage.exp
@@ -0,0 +1,59 @@
+proc setup {} {
+ save_env
+}
+
+proc teardown {} {
+ assert_env_unmodified {
+ /declare -f fn/d
+ }
+}
+
+setup
+
+
+set cmd {fn() { printf '%s\n' ""; }; _parse_usage fn}
+assert_bash_list "" $cmd "empty"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "no dashes here"; }; _parse_usage fn}
+assert_bash_list "" $cmd "no dashes"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "foo [-f]"; }; _parse_usage fn}
+assert_bash_list "-f" $cmd "simple"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "bar [-aBcD] [-e X]"; }; _parse_usage fn}
+assert_bash_list "-a -B -c -D -e" $cmd "bundled + separate 1 short"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[-[XyZ]] [--long=arg]"; }; _parse_usage fn}
+assert_bash_list "-X -y -Z --long=" $cmd "bundled in brackets + separate long"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[-s|--long]"; }; _parse_usage fn}
+assert_bash_list "--long" $cmd "short or long"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[-s, --long=arg]"; }; _parse_usage fn}
+assert_bash_list "--long=" $cmd "short or long with arg, comma"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[--long/-s] [-S/--longer]"; }; _parse_usage fn}
+assert_bash_list "--long\n--longer" $cmd "long or short, slash"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[ -a ] [ -b foo ]"; }; _parse_usage fn}
+assert_bash_list "-a\n-b" $cmd "whitespace in brackets"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "[ -a | --aa ]"; }; _parse_usage fn}
+assert_bash_list "--aa" $cmd "whitespace in brackets 2"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "----\n---foo\n----- bar"; }; _parse_usage fn}
+assert_bash_list "" $cmd "many dashes"
+sync_after_int
+
+
+teardown