diff options
| author | shenwei356 <[email protected]> | 2016-10-07 00:41:20 +0800 |
|---|---|---|
| committer | shenwei356 <[email protected]> | 2016-10-07 00:41:20 +0800 |
| commit | 13e924deb5961431f4836dcb0e247254b9cc23d4 (patch) | |
| tree | 2b9a66ea31c8d882d5783cad12f02a5bc061a278 /string_slice_test.go | |
| parent | 4bd69631f4750a9df249ee317f4536e02cbc3c65 (diff) | |
fix bug of string_slice with square brackets
Diffstat (limited to 'string_slice_test.go')
| -rw-r--r-- | string_slice_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/string_slice_test.go b/string_slice_test.go index 26118c7..c41f3bd 100644 --- a/string_slice_test.go +++ b/string_slice_test.go @@ -213,3 +213,41 @@ func TestSSWithComma(t *testing.T) { } } } + +func TestSSWithSquareBrackets(t *testing.T) { + var ss []string + f := setUpSSFlagSet(&ss) + + in := []string{`"[a-z]"`, `"[a-z]+"`} + expected := []string{"[a-z]", "[a-z]+"} + argfmt := "--ss=%s" + arg1 := fmt.Sprintf(argfmt, in[0]) + arg2 := fmt.Sprintf(argfmt, in[1]) + err := f.Parse([]string{arg1, arg2}) + if err != nil { + t.Fatal("expected no error; got", err) + } + + if len(expected) != len(ss) { + t.Fatalf("expected number of ss to be %d but got: %d", len(expected), len(ss)) + } + for i, v := range ss { + if expected[i] != v { + t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v) + } + } + + values, err := f.GetStringSlice("ss") + 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 ss[%d] to be %s but got: %s", i, expected[i], v) + } + } +} |
