aboutsummaryrefslogtreecommitdiff
path: root/opts_test.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-11-29 22:09:17 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-11-29 22:09:17 +0100
commitf5fbe4aecdc04815cb48f047578e193a6289c3c5 (patch)
tree7a9de1f5475803c16a5edfeec4fb04e909df7a1d /opts_test.go
parenta6c83a3f1b14512a4138fb1744bafdf3f59caaa0 (diff)
Support optional-args for short options
Diffstat (limited to 'opts_test.go')
-rw-r--r--opts_test.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/opts_test.go b/opts_test.go
index 2ea9334..1f71057 100644
--- a/opts_test.go
+++ b/opts_test.go
@@ -10,7 +10,7 @@ func die(t *testing.T, name string, want, got any) {
}
func assertGet(t *testing.T, args []string, fw, ow int, ew error) []Flag {
- flags, optind, err := Get(args, "abλc:dß")
+ flags, optind, err := Get(args, "abλc:dßĦ::")
if err != ew {
die(t, "err", ew, err)
}
@@ -217,3 +217,42 @@ func TestXAfterDash(t *testing.T) {
args := []string{"foo", "-", "-x"}
assertGet(t, args, 0, 1, nil)
}
+
+func TestĦWithSpaceAndArg(t *testing.T) {
+ args := []string{"foo", "-Ħ", "bar"}
+ flags := assertGet(t, args, 1, 2, nil)
+ if flags[0].Key != 'Ħ' {
+ die(t, "flags[0].Key", 'Ħ', flags[0].Key)
+ }
+ if flags[0].Value != "" {
+ die(t, "flags[0].Value", "", flags[0].Value)
+ }
+}
+
+func TestĦWithArg(t *testing.T) {
+ args := []string{"foo", "-Ħbar"}
+ flags := assertGet(t, args, 1, 2, nil)
+ if flags[0].Key != 'Ħ' {
+ die(t, "flags[0].Key", 'Ħ', flags[0].Key)
+ }
+ if flags[0].Value != "bar" {
+ die(t, "flags[0].Value", "bar", flags[0].Value)
+ }
+}
+
+func TestΛĦWithArg(t *testing.T) {
+ args := []string{"foo", "-λĦbar"}
+ flags := assertGet(t, args, 2, 2, nil)
+ if flags[0].Key != 'λ' {
+ die(t, "flags[0].Key", 'λ', flags[0].Key)
+ }
+ if flags[0].Value != "" {
+ die(t, "flags[0].Value", "", flags[0].Value)
+ }
+ if flags[1].Key != 'Ħ' {
+ die(t, "flags[1].Key", 'Ħ', flags[1].Key)
+ }
+ if flags[1].Value != "bar" {
+ die(t, "flags[1].Value", "bar", flags[1].Value)
+ }
+}