diff options
| author | Eric Paris <[email protected]> | 2015-10-13 14:47:57 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-10-13 14:47:57 -0400 |
| commit | 9c1e8f8537a437da36d3a2c8402eb68a44f6dc21 (patch) | |
| tree | 3f8e79ef36d188da66ef387c4b53cc92540f9b30 /string_slice_test.go | |
| parent | b084184666e02084b8ccb9b704bf0d79c466eb1d (diff) | |
Use encoding/csv to parse string slices
There was no way to escape or use a , in a string slice so use the
encoding/csv library, rather than string.split() and let golang take
care of the encoding issues.
Diffstat (limited to 'string_slice_test.go')
| -rw-r--r-- | string_slice_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/string_slice_test.go b/string_slice_test.go index 97602de..c7fdc70 100644 --- a/string_slice_test.go +++ b/string_slice_test.go @@ -139,3 +139,23 @@ func TestSSCalledTwice(t *testing.T) { } } } + +func TestSSWithComma(t *testing.T) { + var ss []string + f := setUpSSFlagSet(&ss) + + in := []string{`"one,two"`, `"three"`} + expected := []string{"one,two", "three"} + 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) + } + for i, v := range ss { + if expected[i] != v { + t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v) + } + } +} |
