aboutsummaryrefslogtreecommitdiff
path: root/string_array_test.go
diff options
context:
space:
mode:
authorMartin Milata <[email protected]>2016-10-11 13:53:10 +0200
committerMartin Milata <[email protected]>2016-10-11 13:53:10 +0200
commitb027180f68d2dd09ce6a5b64a4e03b9413c8421e (patch)
treeebbbc44937b64104bb115b4944b15013ef208a11 /string_array_test.go
parentb83537d79690b75cac5e021b036ae16792bf0f20 (diff)
Fix square bracket handling in string_array
Same issue fixed in 13e924de for string_slice.
Diffstat (limited to 'string_array_test.go')
-rw-r--r--string_array_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/string_array_test.go b/string_array_test.go
index 3e3eb74..1ceac8c 100644
--- a/string_array_test.go
+++ b/string_array_test.go
@@ -192,3 +192,42 @@ func TestSAWithSpecialChar(t *testing.T) {
}
}
}
+
+func TestSAWithSquareBrackets(t *testing.T) {
+ var sa []string
+ f := setUpSAFlagSet(&sa)
+
+ in := []string{"][]-[", "[a-z]", "[a-z]+"}
+ expected := []string{"][]-[", "[a-z]", "[a-z]+"}
+ argfmt := "--sa=%s"
+ arg1 := fmt.Sprintf(argfmt, in[0])
+ arg2 := fmt.Sprintf(argfmt, in[1])
+ arg3 := fmt.Sprintf(argfmt, in[2])
+ err := f.Parse([]string{arg1, arg2, arg3})
+ if err != nil {
+ t.Fatal("expected no error; got", err)
+ }
+
+ if len(expected) != len(sa) {
+ t.Fatalf("expected number of sa to be %d but got: %d", len(expected), len(sa))
+ }
+ for i, v := range sa {
+ if expected[i] != v {
+ t.Fatalf("expected sa[%d] to be %s but got: %s", i, expected[i], v)
+ }
+ }
+
+ values, err := f.GetStringArray("sa")
+ if err != nil {
+ t.Fatal("expected no error; got", err)
+ }
+
+ if len(expected) != len(values) {
+ t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(values))
+ }
+ for i, v := range values {
+ if expected[i] != v {
+ t.Fatalf("expected got sa[%d] to be %s but got: %s", i, expected[i], v)
+ }
+ }
+}